本文整理了Java中org.opencv.imgproc.Imgproc.contourArea()
方法的一些代码示例,展示了Imgproc.contourArea()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Imgproc.contourArea()
方法的具体详情如下:
包路径:org.opencv.imgproc.Imgproc
类名称:Imgproc
方法名:contourArea
[英]Calculates a contour area.
The function computes a contour area. Similarly to "moments", the area is computed using the Green formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using "drawContours" or "fillPoly", can be different. Also, the function will most certainly give a wrong results for contours with self-intersections. Example: ``
// C++ code:
vector contour;
contour.push_back(Point2f(0, 0));
contour.push_back(Point2f(10, 0));
contour.push_back(Point2f(10, 10));
contour.push_back(Point2f(5, 4));
double area0 = contourArea(contour);
vector approx;
approxPolyDP(contour, approx, 5, true);
double area1 = contourArea(approx);
cout << "area0 =" << area0 << endl <<
"area1 =" << area1 << endl <<
"approx poly vertices" << approx.size() << endl;
[中]计算轮廓面积。
该函数用于计算轮廓区域。与“力矩”类似,面积使用格林公式计算。因此,如果使用“drawContours”或“fillPoly”绘制轮廓,则返回的区域和非零像素数可能不同。此外,对于具有自相交的等高线,该函数肯定会给出错误的结果。示例:``
//C++代码:
矢量轮廓;
外形向后推(点2f(0,0));
外形向后推(点2f(10,0));
外形向后推(点2F(10,10));
外形向后推(点2F(5,4));
双面积0=轮廓面积(轮廓);
向量近似;
近似聚合度(等高线,近似值,5,真实值);
双面积1=轮廓面积(近似值);
cout<<“area0=“<<area0<<endl<<
“area1=“<<area1<<endl<<
“近似多边形顶点”<<近似大小()<<endl;
代码示例来源:origin: openpnp/openpnp
public FluentCv filterContoursByArea(List<MatOfPoint> contours, double areaMin,
double areaMax) {
for (Iterator<MatOfPoint> i = contours.iterator(); i.hasNext();) {
MatOfPoint contour = i.next();
double area = Imgproc.contourArea(contour);
if (area < areaMin || area > areaMax) {
i.remove();
}
}
return this;
}
代码示例来源:origin: openpnp/openpnp
@Override
public Result process(CvPipeline pipeline) throws Exception {
if (contoursStageName == null) {
return null;
}
Result result = pipeline.getResult(contoursStageName);
if (result == null || result.model == null) {
return null;
}
List<MatOfPoint> contours = (List<MatOfPoint>) result.model;
List<MatOfPoint> results = new ArrayList<MatOfPoint>();
for (MatOfPoint contour : contours) {
double area = Imgproc.contourArea(contour);
if (area >= (minArea == -1 ? Double.MIN_VALUE : minArea) && area <= (maxArea == -1 ? Double.MAX_VALUE : maxArea)) {
results.add(contour);
}
}
return new Result(null, results);
}
}
代码示例来源:origin: JavaOpenCVBook/code
for(int i=0;i<contours.size();i++){
MatOfPoint currentContour = contours.get(i);
double currentArea = Imgproc.contourArea(currentContour);
内容来源于网络,如有侵权,请联系作者删除!