當前位置: 首頁>>代碼示例>>Java>>正文


Java Imgproc.arcLength方法代碼示例

本文整理匯總了Java中org.opencv.imgproc.Imgproc.arcLength方法的典型用法代碼示例。如果您正苦於以下問題:Java Imgproc.arcLength方法的具體用法?Java Imgproc.arcLength怎麽用?Java Imgproc.arcLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.arcLength方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: gridDetection

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
public static void gridDetection(Mat img){
       List<MatOfPoint> contours = new ArrayList<>();
       Imgproc.findContours(img,contours,new Mat(),Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);

       double maxArea = 0;
       MatOfPoint max_contour = new MatOfPoint();

       Iterator<MatOfPoint> iterator = contours.iterator();
       while (iterator.hasNext()){
           MatOfPoint contour = iterator.next();
           double area = Imgproc.contourArea(contour);
           if(area > maxArea){
               maxArea = area;
               max_contour = contour;
           }
       }

       double epsilon = 0.1*Imgproc.arcLength(new MatOfPoint2f(max_contour.toArray()),true);
       MatOfPoint2f approx = new MatOfPoint2f();
       Imgproc.approxPolyDP(new MatOfPoint2f(max_contour.toArray()),approx,epsilon,true);
	
	RotatedRect rect = Imgproc.minAreaRect(new MatOfPoint2f(max_contour.toArray()));
	
	Mat grid = Thresholding.orderPoints(approx);
	
	Thresholding.approx = approx;
	Thresholding.grid = grid;
	Thresholding.rect = rect;
}
 
開發者ID:Sanahm,項目名稱:SudoCAM-Ku,代碼行數:30,代碼來源:Thresholding.java

示例2: filterContours

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
/**
 * Filters out contours that do not meet certain criteria.
 * 
 * @param inputContours
 *            is the input list of contours
 * @param output
 *            is the the output list of contours
 * @param minArea
 *            is the minimum area of a contour that will be kept
 * @param minPerimeter
 *            is the minimum perimeter of a contour that will be kept
 * @param minWidth
 *            minimum width of a contour
 * @param maxWidth
 *            maximum width
 * @param minHeight
 *            minimum height
 * @param maxHeight
 *            maximimum height
 * @param Solidity
 *            the minimum and maximum solidity of a contour
 * @param minVertexCount
 *            minimum vertex Count of the contours
 * @param maxVertexCount
 *            maximum vertex Count
 * @param minRatio
 *            minimum ratio of width to height
 * @param maxRatio
 *            maximum ratio of width to height
 */
private void filterContours(List<MatOfPoint> inputContours, double minArea, double minPerimeter, double minWidth,
		double maxWidth, double minHeight, double maxHeight, double[] solidity, double maxVertexCount,
		double minVertexCount, double minRatio, double maxRatio, List<MatOfPoint> output) {
	final MatOfInt hull = new MatOfInt();
	output.clear();
	// operation
	for (int i = 0; i < inputContours.size(); i++) {
		final MatOfPoint contour = inputContours.get(i);
		final Rect bb = Imgproc.boundingRect(contour);
		if (bb.width < minWidth || bb.width > maxWidth)
			continue;
		if (bb.height < minHeight || bb.height > maxHeight)
			continue;
		final double area = Imgproc.contourArea(contour);
		if (area < minArea)
			continue;
		if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter)
			continue;
		Imgproc.convexHull(contour, hull);
		MatOfPoint mopHull = new MatOfPoint();
		mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
		for (int j = 0; j < hull.size().height; j++) {
			int index = (int) hull.get(j, 0)[0];
			double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1] };
			mopHull.put(j, 0, point);
		}
		final double solid = 100 * area / Imgproc.contourArea(mopHull);
		if (solid < solidity[0] || solid > solidity[1])
			continue;
		if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount)
			continue;
		final double ratio = bb.width / (double) bb.height;
		if (ratio < minRatio || ratio > maxRatio)
			continue;
		output.add(contour);
	}
}
 
開發者ID:chopshop-166,項目名稱:frc-2017,代碼行數:68,代碼來源:Vision.java

示例3: findRectangle

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
public void findRectangle() {
        Imgproc.cvtColor(originalImage, image, Imgproc.COLOR_BGR2GRAY);
        setFilter();
        this.rects.clear();

        //Find Contours
        Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));

        //For conversion later on
        MatOfPoint2f approxCurve = new MatOfPoint2f();

        //For each contour found
        for (int i = 0; i < contours.size(); i++) {

            //Convert contours from MatOfPoint to MatOfPoint2f
            MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(i).toArray());
            //Processing on mMOP2f1 which is in type MatOfPoint2f
            double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;

            if (approxDistance > 1) {
                //Find Polygons
                Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

                //Convert back to MatOfPoint
                MatOfPoint points = new MatOfPoint(approxCurve.toArray());

                //Rectangle Checks - Points, area, convexity
                if (points.total() == 4 && Math.abs(Imgproc.contourArea(points)) > 1000 && Imgproc.isContourConvex(points)) {
                    double cos = 0;
                    double mcos = 0;
                    for (int sc = 2; sc < 5; sc++) {
                        // TO-DO Figure a way to check angle
                        if (cos > mcos) {
                            mcos = cos;
                        }
                    }
                    if (mcos < 0.3) {
                        // Get bounding rect of contour
                        Rect rect = Imgproc.boundingRect(points);

//                        if (Math.abs(rect.height - rect.width) < 1000) {
                            System.out.println(i + "| x: " + rect.x + " + width("+rect.width+"), y: " + rect.y + "+ width("+rect.height+")");
                            rects.add(rect);
                            Core.rectangle(originalImage, rect.tl(), rect.br(), new Scalar(20, 20, 20), -1, 4, 0);
                            Imgproc.drawContours(originalImage, contours, i, new Scalar(0, 255, 0, .8), 2);
                            
                            // Highgui.imwrite("detected_layers"+i+".png", originalImage);
//                        }
                    }
                }
            }
        }
        // Pass raw parameters
        ImageDetection id = new ImageDetection();
        HyperTextBuilder.rects = this.rects;
        HyperTextBuilder.rect_height = this.HEIGHT;
        HyperTextBuilder.rect_width = this.WIDTH;
        id.setData(Utility.matToBufferedImage(originalImage));
    }
 
開發者ID:lupino22,項目名稱:kronometer,代碼行數:60,代碼來源:SketchRecognition.java

示例4: filterContours

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
/**
 * Filters out contours that do not meet certain criteria.
 * @param inputContours is the input list of contours
 * @param output is the the output list of contours
 * @param minArea is the minimum area of a contour that will be kept
 * @param minPerimeter is the minimum perimeter of a contour that will be kept
 * @param minWidth minimum width of a contour
 * @param maxWidth maximum width
 * @param minHeight minimum height
 * @param maxHeight maximimum height
 * @param Solidity the minimum and maximum solidity of a contour
 * @param minVertexCount minimum vertex Count of the contours
 * @param maxVertexCount maximum vertex Count
 * @param minRatio minimum ratio of width to height
 * @param maxRatio maximum ratio of width to height
 */
private void filterContours(List<MatOfPoint> inputContours, double minArea,
	double minPerimeter, double minWidth, double maxWidth, double minHeight, double
	maxHeight, double[] solidity, double maxVertexCount, double minVertexCount, double
	minRatio, double maxRatio, List<MatOfPoint> output) {
	final MatOfInt hull = new MatOfInt();
	output.clear();
	//operation
	for (int i = 0; i < inputContours.size(); i++) {
		final MatOfPoint contour = inputContours.get(i);
		final Rect bb = Imgproc.boundingRect(contour);
		if (bb.width < minWidth || bb.width > maxWidth) continue;
		if (bb.height < minHeight || bb.height > maxHeight) continue;
		final double area = Imgproc.contourArea(contour);
		if (area < minArea) continue;
		if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter) continue;
		Imgproc.convexHull(contour, hull);
		MatOfPoint mopHull = new MatOfPoint();
		mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
		for (int j = 0; j < hull.size().height; j++) {
			int index = (int)hull.get(j, 0)[0];
			double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1]};
			mopHull.put(j, 0, point);
		}
		final double solid = 100 * area / Imgproc.contourArea(mopHull);
		if (solid < solidity[0] || solid > solidity[1]) continue;
		if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount)	continue;
		final double ratio = bb.width / (double)bb.height;
		if (ratio < minRatio || ratio > maxRatio) continue;
		output.add(contour);
	}
}
 
開發者ID:mustafamertunali,項目名稱:FRC-6416-frc2017,代碼行數:48,代碼來源:GripPipeline.java

示例5: filterContours

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
@Override
public List<MatOfPoint> filterContours(List<MatOfPoint> contours) {
    List<MatOfPoint> output = new ArrayList<>();
    // Generated and tested by GRIP, variables slightly renamed
    final MatOfInt hull = new MatOfInt();
    for (int i = 0; i < contours.size(); i++) {
        final MatOfPoint contour = contours.get(i);
        final Rect bb = Imgproc.boundingRect(contour);
        if (bb.width < width.start || bb.width > width.end)
            continue;
        if (bb.height < height.start || bb.height > height.end)
            continue;
        final double area = Imgproc.contourArea(contour);
        if (area < minArea)
            continue;
        if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter)
            continue;
        Imgproc.convexHull(contour, hull);
        MatOfPoint mopHull = new MatOfPoint();
        mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
        for (int j = 0; j < hull.size().height; j++) {
            int index = (int) hull.get(j, 0)[0];
            double[] point = new double[]{contour.get(index, 0)[0], contour.get(index, 0)[1]};
            mopHull.put(j, 0, point);
        }
        final double solid = 100 * area / Imgproc.contourArea(mopHull);
        if (solid < solidity.start || solid > solidity.end)
            continue;
        if (contour.rows() < vertexCount.start || contour.rows() > vertexCount.end)
            continue;
        final double ratio = bb.width / (double) bb.height;
        if (ratio < widthToHeightRatio.start || ratio > widthToHeightRatio.end)
            continue;
        output.add(contour);
    }
    return output;
}
 
開發者ID:kylecorry31,項目名稱:Robot-Vision-API,代碼行數:38,代碼來源:ConvexHullContourFilter.java

示例6: filterContours

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
/**
 * Filters out contours that do not meet certain criteria.
 * 
 * @param inputContours
 *            is the input list of contours
 * @param output
 *            is the the output list of contours
 * @param minArea
 *            is the minimum area of a contour that will be kept
 * @param minPerimeter
 *            is the minimum perimeter of a contour that will be kept
 * @param minWidth
 *            minimum width of a contour
 * @param maxWidth
 *            maximum width
 * @param minHeight
 *            minimum height
 * @param maxHeight
 *            maximimum height
 * @param Solidity
 *            the minimum and maximum solidity of a contour
 * @param minVertexCount
 *            minimum vertex Count of the contours
 * @param maxVertexCount
 *            maximum vertex Count
 * @param minRatio
 *            minimum ratio of width to height
 * @param maxRatio
 *            maximum ratio of width to height
 */
private void filterContours (List<MatOfPoint> inputContours,
        double minArea,
        double minPerimeter, double minWidth, double maxWidth,
        double minHeight, double maxHeight, double[] solidity,
        double maxVertexCount, double minVertexCount, double minRatio,
        double maxRatio, List<MatOfPoint> output)
{
    final MatOfInt hull = new MatOfInt();
    output.clear();
    // operation
    for (int i = 0; i < inputContours.size(); i++)
        {
        final MatOfPoint contour = inputContours.get(i);
        final Rect bb = Imgproc.boundingRect(contour);
        if (bb.width < minWidth || bb.width > maxWidth)
            continue;
        if (bb.height < minHeight || bb.height > maxHeight)
            continue;
        final double area = Imgproc.contourArea(contour);
        if (area < minArea)
            continue;
        if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()),
                true) < minPerimeter)
            continue;
        Imgproc.convexHull(contour, hull);
        MatOfPoint mopHull = new MatOfPoint();
        mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
        for (int j = 0; j < hull.size().height; j++)
            {
            int index = (int) hull.get(j, 0)[0];
            double[] point = new double[]
                {contour.get(index, 0)[0], contour.get(index, 0)[1]};
            mopHull.put(j, 0, point);
            }
        final double solid = 100 * area / Imgproc.contourArea(mopHull);
        if (solid < solidity[0] || solid > solidity[1])
            continue;
        if (contour.rows() < minVertexCount
                || contour.rows() > maxVertexCount)
            continue;
        final double ratio = bb.width / (double) bb.height;
        if (ratio < minRatio || ratio > maxRatio)
            continue;
        output.add(contour);
        }
}
 
開發者ID:FIRST-Team-339,項目名稱:2017,代碼行數:77,代碼來源:GripPipeline.java

示例7: filterContours

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
/**
 * Filters out contours that do not meet certain criteria.
 *
 * @param inputContours
 *          is the input list of contours
 * @param output
 *          is the the output list of contours
 * @param minArea
 *          is the minimum area of a contour that will be kept
 * @param minPerimeter
 *          is the minimum perimeter of a contour that will be kept
 * @param minWidth
 *          minimum width of a contour
 * @param maxWidth
 *          maximum width
 * @param minHeight
 *          minimum height
 * @param maxHeight
 *          maximimum height
 * @param Solidity
 *          the minimum and maximum solidity of a contour
 * @param minVertexCount
 *          minimum vertex Count of the contours
 * @param maxVertexCount
 *          maximum vertex Count
 * @param minRatio
 *          minimum ratio of width to height
 * @param maxRatio
 *          maximum ratio of width to height
 */
private void filterContours(List<MatOfPoint> inputContours, double minArea, double minPerimeter, double minWidth,
    double maxWidth, double minHeight, double maxHeight, double[] solidity, double maxVertexCount,
    double minVertexCount, double minRatio, double maxRatio, List<MatOfPoint> output) {
  final MatOfInt hull = new MatOfInt();
  output.clear();
  // operation
  for (int i = 0; i < inputContours.size(); i++) {
    final MatOfPoint contour = inputContours.get(i);
    final Rect bb = Imgproc.boundingRect(contour);
    if (bb.width < minWidth || bb.width > maxWidth) {
      continue;
    }
    if (bb.height < minHeight || bb.height > maxHeight) {
      continue;
    }
    final double area = Imgproc.contourArea(contour);
    if (area < minArea) {
      continue;
    }
    if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter) {
      continue;
    }
    Imgproc.convexHull(contour, hull);
    MatOfPoint mopHull = new MatOfPoint();
    mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
    for (int j = 0; j < hull.size().height; j++) {
      int index = (int) hull.get(j, 0)[0];
      double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1] };
      mopHull.put(j, 0, point);
    }
    final double solid = 100 * area / Imgproc.contourArea(mopHull);
    if (solid < solidity[0] || solid > solidity[1]) {
      continue;
    }
    if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount) {
      continue;
    }
    final double ratio = bb.width / (double) bb.height;
    if (ratio < minRatio || ratio > maxRatio) {
      continue;
    }
    output.add(contour);
  }
}
 
開發者ID:cyborgs3335,項目名稱:STEAMworks,代碼行數:75,代碼來源:GripPipelineWithBlur.java

示例8: arcLength

import org.opencv.imgproc.Imgproc; //導入方法依賴的package包/類
/**
 * Get the arc length of the contour
 *
 * @param closed True if the contour should be calculated as closed
 * @return Arc length
 */
public double arcLength(boolean closed) {
    return Imgproc.arcLength(getDoubleData(), closed);
}
 
開發者ID:ykarim,項目名稱:FTC2016,代碼行數:10,代碼來源:Contour.java


注:本文中的org.opencv.imgproc.Imgproc.arcLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。