当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.findContours方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.findContours方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.findContours方法的具体用法?Java Imgproc.findContours怎么用?Java Imgproc.findContours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.findContours方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: findContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Sets the values of pixels in a binary image to their distance to the nearest
 * black pixel.
 * 
 * @param input
 *            The image on which to perform the Distance Transform.
 * @param type
 *            The Transform.
 * @param maskSize
 *            the size of the mask.
 * @param output
 *            The image in which to store the output.
 */
private void findContours (Mat input, boolean externalOnly,
        List<MatOfPoint> contours)
{
    Mat hierarchy = new Mat();
    contours.clear();
    int mode;
    if (externalOnly)
        {
        mode = Imgproc.RETR_EXTERNAL;
        }
    else
        {
        mode = Imgproc.RETR_LIST;
        }
    int method = Imgproc.CHAIN_APPROX_SIMPLE;
    Imgproc.findContours(input, contours, hierarchy, mode, method);
}
 
开发者ID:FIRST-Team-339,项目名称:2017,代码行数:31,代码来源:GripPipeline.java

示例3: findContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Sets the values of pixels in a binary image to their distance to the nearest black pixel.
 * 
 * @param input
 *            The image on which to perform the Distance Transform.
 * @param type
 *            The Transform.
 * @param maskSize
 *            the size of the mask.
 * @param output
 *            The image in which to store the output.
 */
private void findContours(Mat input, boolean externalOnly, List<MatOfPoint> contours) {
	Mat hierarchy = new Mat();
	contours.clear();
	int mode;
	if (externalOnly) {
		mode = Imgproc.RETR_EXTERNAL;
	} else {
		mode = Imgproc.RETR_LIST;
	}
	int method = Imgproc.CHAIN_APPROX_SIMPLE;
	Imgproc.findContours(input, contours, hierarchy, mode, method);
}
 
开发者ID:chopshop-166,项目名称:frc-2017,代码行数:25,代码来源:Vision.java

示例4: largeContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static List<MatOfPoint> largeContours(Mat im, int area) {
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    Imgproc.findContours(im, contours, hierarchy, 1, Imgproc.RETR_LIST);

    // FIXME: stream requires Android sdk >= 24
    // return contours.stream()
    //         .filter(cnt -> Imgproc.contourArea(cnt) > area)
    //         .collect(Collectors.toList());

    List<MatOfPoint> ret = new ArrayList<>();
    for (MatOfPoint cnt : contours) {
        if (Imgproc.contourArea(cnt) > area) {
            ret.add(cnt);
        }
    }
    return ret;
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:19,代码来源:Util.java

示例5: getContourArea

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static ArrayList<Rect> getContourArea(Mat mat) {
	Mat hierarchy = new Mat();
	Mat image = mat.clone();
	List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
	Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
	Rect rect = null;
	double maxArea = 300;
	ArrayList<Rect> arr = new ArrayList<Rect>();
	for (int i = 0; i < contours.size(); i++) {
		Mat contour = contours.get(i);
		double contourArea = Imgproc.contourArea(contour);
		if (contourArea > maxArea) {
			rect = Imgproc.boundingRect(contours.get(i));
			arr.add(rect);
		}
	}
	return arr;
}
 
开发者ID:baghelamit,项目名称:video-stream-analytics,代码行数:19,代码来源:VideoMotionDetector.java

示例6: Contours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void Contours() {
    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat hierarchy = new Mat();

    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>(); //A list to store all the contours

    //Converting the image to grayscale
    Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

    Imgproc.Canny(originalMat, cannyEdges, 10, 100);

    //finding contours
    Imgproc.findContours(cannyEdges, contourList, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    //Drawing contours on a new image
    Mat contours = new Mat();
    contours.create(cannyEdges.rows(), cannyEdges.cols(), CvType.CV_8UC3);
    Random r = new Random();
    for (int i = 0; i < contourList.size(); i++) {
        Imgproc.drawContours(contours, contourList, i, new Scalar(r.nextInt(255), r.nextInt(255), r.nextInt(255)), -1);
    }
    //Converting Mat back to Bitmap
    Utils.matToBitmap(contours, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:27,代码来源:MainActivity.java

示例7: trackLaser

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private void trackLaser()
{

    Imgproc.cvtColor(frame,hsv , Imgproc.COLOR_BGR2HSV);
    //shiny RED Color
    Scalar lowerScale = new Scalar(0, 0, 255);
    Scalar upperScale = new Scalar(255, 255, 255);

    Core.inRange(hsv, lowerScale, upperScale, mask);
    matOfPoints.clear();
    Imgproc.findContours(mask, matOfPoints, heir , Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    if (matOfPoints.size() > 0) {

        float[] radius = new float[1];

        Point[] matOfPoint = matOfPoints.get(maxPoint(matOfPoints)).toArray();
        Imgproc.minEnclosingCircle(new MatOfPoint2f(matOfPoint), laserCenter,radius);
        //Trigger Listener up here
        Imgproc.circle(frame, laserCenter, 7, new Scalar(255, 0, 0), 2);
        Imgproc.circle(mask, laserCenter, 7, new Scalar(255, 0, 0), 2);
        triggerLaserDetectionFrame(laserCenter);

    }
    triggerProcessingListeners(onFrameProcessedListeners, frame);
    triggerProcessingListeners(onMaskProcessedListeners, mask);

}
 
开发者ID:kareem2048,项目名称:Asteroids-Laser-Controller,代码行数:28,代码来源:LaserDetector.java

示例8: process

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Process an rgba image. The results can be drawn on retrieved later.
 * This method does not modify the image.
 *
 * @param rgbaImage An RGBA image matrix
 */
public void process(Mat rgbaImage) {
    Imgproc.pyrDown(rgbaImage, mPyrDownMat);
    Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);

    Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);

    //Test whether we need two inRange operations (only if the hue crosses over 255)
    if (upperBound.getScalar().val[0] <= 255) {
        Core.inRange(mHsvMat, lowerBound.getScalar(), upperBound.getScalar(), mMask);
    } else {
        //We need two operations - we're going to OR the masks together
        Scalar lower = lowerBound.getScalar().clone();
        Scalar upper = upperBound.getScalar().clone();
        while (upper.val[0] > 255)
            upper.val[0] -= 255;
        double tmp = lower.val[0];
        lower.val[0] = 0;
        //Mask 1 - from 0 to n
        Core.inRange(mHsvMat, lower, upper, mMaskOne);
        //Mask 2 - from 255-n to 255
        lower.val[0] = tmp;
        upper.val[0] = 255;

        Core.inRange(mHsvMat, lower, upper, mMask);
        //OR the two masks
        Core.bitwise_or(mMaskOne, mMask, mMask);
    }

    //Dilate (blur) the mask to decrease processing power
    Imgproc.dilate(mMask, mDilatedMask, new Mat());

    List<MatOfPoint> contourListTemp = new ArrayList<>();

    Imgproc.findContours(mDilatedMask, contourListTemp, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    // Filter contours by area and resize to fit the original image size
    contours.clear();
    for (MatOfPoint c : contourListTemp) {
        Core.multiply(c, new Scalar(4, 4), c);
        contours.add(new Contour(c));
    }
}
 
开发者ID:TheBigBombman,项目名称:RobotIGS,代码行数:49,代码来源:ColorBlobDetector.java

示例9: 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

示例10: findContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Sets the values of pixels in a binary image to their distance to the nearest black pixel.
 * @param input The image on which to perform the Distance Transform.
 * @param type The Transform.
 * @param maskSize the size of the mask.
 * @param output The image in which to store the output.
 */
private void findContours(Mat input, boolean externalOnly,
	List<MatOfPoint> contours) {
	Mat hierarchy = new Mat();
	contours.clear();
	int mode;
	if (externalOnly) {
		mode = Imgproc.RETR_EXTERNAL;
	}
	else {
		mode = Imgproc.RETR_LIST;
	}
	int method = Imgproc.CHAIN_APPROX_SIMPLE;
	Imgproc.findContours(input, contours, hierarchy, mode, method);
}
 
开发者ID:mustafamertunali,项目名称:FRC-6416-frc2017,代码行数:22,代码来源:GripPipeline.java

示例11: findContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public List<MatOfPoint> findContours(Mat image) {
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    int mode = Imgproc.RETR_EXTERNAL;
    int method = Imgproc.CHAIN_APPROX_SIMPLE;
    Imgproc.findContours(image, contours, hierarchy, mode, method);
    return contours;
}
 
开发者ID:kylecorry31,项目名称:Robot-Vision-API,代码行数:10,代码来源:StandardContourFinder.java

示例12: process_image

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void process_image(Mat input_mat,Size size) {
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    Mat output = input_mat;
    Imgproc.resize(output,output,size);
    Mat processed = preprocess(input_mat,size);
    Mat filtered = apply_filters(processed);
    processed.release();
    Imgproc.findContours(filtered.clone(),contours,hierarchy,Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
    hierarchy.release();
    filtered.release();

    //magic_sort(contours)//sort by x coord
}
 
开发者ID:SCHS-Robotics,项目名称:Team9261-2017-2018,代码行数:15,代码来源:GlyphDetector.java

示例13: findContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Sets the values of pixels in a binary image to their distance to the
 * nearest black pixel.
 *
 * @param input
 *          The image on which to perform the Distance Transform.
 * @param type
 *          The Transform.
 * @param maskSize
 *          the size of the mask.
 * @param output
 *          The image in which to store the output.
 */
private void findContours(Mat input, boolean externalOnly, List<MatOfPoint> contours) {
  Mat hierarchy = new Mat();
  contours.clear();
  int mode;
  if (externalOnly) {
    mode = Imgproc.RETR_EXTERNAL;
  } else {
    mode = Imgproc.RETR_LIST;
  }
  int method = Imgproc.CHAIN_APPROX_SIMPLE;
  Imgproc.findContours(input, contours, hierarchy, mode, method);
}
 
开发者ID:cyborgs3335,项目名称:STEAMworks,代码行数:26,代码来源:GripPipelineWithBlur.java

示例14: detectContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Detects contours within a binary image.
 * 
 * @param threshold the binary image
 * @param contours list of contours to fill
 * @param hierarchy hierarchy of contours
 * @return the contours param
 * @see Imgproc#findContours(Mat, List, Mat, int, int)
 */
public static List<MatOfPoint> detectContours(Mat threshold, List<MatOfPoint> contours, Mat hierarchy) {
	Imgproc.findContours(threshold, contours, hierarchy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE);
	return contours;
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:14,代码来源:CvProcessing.java


注:本文中的org.opencv.imgproc.Imgproc.findContours方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。