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


Java Imgproc.drawContours方法代码示例

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


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

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

示例2: irregularQuadrangle_Simplified

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat irregularQuadrangle_Simplified(Mat irrInput, Point p1, Point p2, Point p3, Point p4,
		double shift_x, double shift_y, boolean noULandLRcorner, double ulCornerRatio, double lrCornerRatio) {
	final Mat maskCopyTo = Mat.zeros(irrInput.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��

	// �����ĵ���Ϊ��ʼ����
	final double centerX = (p1.x + p2.x + p3.x + p4.x) / 4;
	final double centerY = (p1.y + p2.y + p3.y + p4.y) / 4;
	final Point cc = new Point(centerX, centerY);

	final List<MatOfPoint> counter = new ArrayList<>();
	final Point aP1 = new Point(p1.x + shift_x, p1.y + shift_y);
	final Point aP2 = new Point(p2.x - shift_x, p2.y + shift_y);
	final Point aP3 = new Point(p3.x + shift_x, p3.y - shift_y);
	final Point aP4 = new Point(p4.x - shift_x, p4.y - shift_y);

	if (noULandLRcorner) {
		final Point aP1L = new Point(aP1.x, aP1.y + (aP3.y - aP1.y) * ulCornerRatio);
		final Point aP1R = new Point(aP1.x + (aP2.x - aP1.x) * ulCornerRatio, aP1.y);
		final Point aP4L = new Point(aP4.x - (aP4.x - aP3.x) * lrCornerRatio, aP4.y);
		final Point aP4R = new Point(aP4.x, aP4.y - (aP4.y - aP2.y) * lrCornerRatio);

		counter.add(new MatOfPoint(aP1L, aP1R, aP2, aP4R, aP4L, aP3)); // ����һ��������Ķ���Σ�û�����ϽǺ����½�
	} else
		counter.add(new MatOfPoint(aP1, aP2, aP4, aP3)); // ����һ��������Ķ����

	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	Imgproc.drawContours(maskCopyTo, counter, -1, Scalar.all(255)); // ��������
	// MatView.imshow(maskCopyTo, "Irregular shape edge");
	final Mat maskFloodFill = new Mat(irrInput.rows() + 2, irrInput.cols() + 2, CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	Imgproc.floodFill(maskCopyTo, maskFloodFill, new Point(centerX, centerY), Scalar.all(255), null, Scalar.all(20),
			Scalar.all(20), 4); // ��ˮ��䷨����ڲ�
	// MatView.imshow(maskFloodFill, "Irregular shape��Mask of floodFill"); //
	// ����copyTo������mask
	// MatView.imshow(maskCopyTo, "Irregular shape��Mask of copyTo"); //
	// ����floodFill������mask
	final Mat imgIrregularROI = new Mat();
	irrInput.copyTo(imgIrregularROI, maskCopyTo); // ��ȡ��������״��ROI
	// MatView.imshow(imgIrregularROI, "Irregular shape ROI");
	return imgIrregularROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:41,代码来源:ROI_Irregular.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: fillContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat fillContours(Size size, List<MatOfPoint> contours, Point[] seeds) {
    Mat im = Mat.zeros(size, CvType.CV_8U);
    Mat mask = Mat.zeros(new Size(size.width + 2, size.height + 2), CvType.CV_8U);

    for (int ind = 0; ind < contours.size(); ++ind) {
        Imgproc.drawContours(mask, contours, ind, Util.SCALAR_WHITE);
    }

    for (Point p : seeds) {
        Imgproc.floodFill(im, mask, p, Util.SCALAR_WHITE);
    }

    return im;
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:15,代码来源:Util.java

示例5: drawContour

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static void drawContour(Mat img, Contour contour, Color color, int thickness) {
    List<MatOfPoint> contoursOut = new ArrayList<>();
    contoursOut.add(contour.getData());
    Imgproc.drawContours(img, contoursOut, -1, color.getScalarRGBA(), thickness);
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:6,代码来源:Drawing.java

示例6: drawContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void drawContours(Mat img, List<Contour> contours, Color color, int thickness) {
    List<MatOfPoint> contoursOut = new ArrayList<>();
    for (Contour contour : contours)
        contoursOut.add(contour.getData());
    Imgproc.drawContours(img, contoursOut, -1, color.getScalarRGBA(), thickness);
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:7,代码来源:Drawing.java

示例7: irregularQuadrangle

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat irregularQuadrangle(Mat irrInput, Point p1, Point p2, Point p3, Point p4, double shift,
		boolean noULandLRcorner, double ulCornerRatio, double lrCornerRatio) {
	final Mat maskCopyTo = Mat.zeros(irrInput.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��

	final double angle = MathBox.slopeAngle(p1, p2);
	// System.out.println(angle);
	final double sin = Math.sin(angle);
	final double cos = Math.cos(angle);

	// �����ĵ���Ϊ��ʼ����
	final double centerX = (p1.x + p2.x + p3.x + p4.x) / 4;
	final double centerY = (p1.y + p2.y + p3.y + p4.y) / 4;
	final Point cc = new Point(centerX, centerY);

	final List<MatOfPoint> counter = new ArrayList<>();
	final Point aP1raw = new Point(p1.x + shift, p1.y + shift);
	final Point aP2raw = new Point(p2.x - shift, p2.y + shift);
	final Point aP3raw = new Point(p3.x + shift, p3.y - shift);
	final Point aP4raw = new Point(p4.x - shift, p4.y - shift);

	final Point aP1 = MathBox.rotateAroundAPoint(cc, aP1raw, angle);
	final Point aP2 = MathBox.rotateAroundAPoint(cc, aP2raw, angle);
	final Point aP3 = MathBox.rotateAroundAPoint(cc, aP3raw, angle);
	final Point aP4 = MathBox.rotateAroundAPoint(cc, aP4raw, angle);

	if (noULandLRcorner) {
		final Point aP1Lraw = new Point(aP1.x, aP1.y + (aP3.y - aP1.y) * ulCornerRatio);
		final Point aP1Rraw = new Point(aP1.x + (aP2.x - aP1.x) * ulCornerRatio, aP1.y);
		final Point aP4Lraw = new Point(aP4.x - (aP4.x - aP3.x) * lrCornerRatio, aP4.y);
		final Point aP4Rraw = new Point(aP4.x, aP4.y - (aP4.y - aP2.y) * lrCornerRatio);

		final Point aP1L = MathBox.rotateAroundAPoint(cc, aP1Lraw, angle);
		final Point aP1R = MathBox.rotateAroundAPoint(cc, aP1Rraw, angle);
		final Point aP4L = MathBox.rotateAroundAPoint(cc, aP4Lraw, angle);
		final Point aP4R = MathBox.rotateAroundAPoint(cc, aP4Rraw, angle);

		counter.add(new MatOfPoint(aP1L, aP1R, aP2, aP4R, aP4L, aP3)); // ����һ��������Ķ���Σ�û�����ϽǺ����½�
	} else
		counter.add(new MatOfPoint(aP1, aP2, aP4, aP3)); // ����һ��������Ķ����

	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	Imgproc.drawContours(maskCopyTo, counter, -1, Scalar.all(255)); // ��������
	MatView.imshow(maskCopyTo, "Irregular shape edge");
	final Mat maskFloodFill = new Mat(irrInput.rows() + 2, irrInput.cols() + 2, CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	Imgproc.floodFill(maskCopyTo, maskFloodFill, new Point(centerX, centerY), Scalar.all(255), null, Scalar.all(20),
			Scalar.all(20), 4); // ��ˮ��䷨����ڲ�
	// MatView.imshow(maskFloodFill, "Irregular shape��Mask of floodFill"); //
	// ����copyTo������mask
	// MatView.imshow(maskCopyTo, "Irregular shape��Mask of copyTo"); //
	// ����floodFill������mask
	final Mat imgIrregularROI = new Mat();
	irrInput.copyTo(imgIrregularROI, maskCopyTo); // ��ȡ��������״��ROI
	// MatView.imshow(imgIrregularROI, "Irregular shape ROI");
	return imgIrregularROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:56,代码来源:ROI_Irregular.java

示例8: drawContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void drawContours(Mat im, List<MatOfPoint> contours, Scalar color) {
    for (int ind = 0; ind < contours.size(); ++ind) {
        Imgproc.drawContours(im, contours, ind, color, 2);
    }
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:6,代码来源:Util.java

示例9: drawContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Draws a list of contours unto a mat.
 * 
 * @param feed the mat to draw on
 * @param contours list of contours to draw
 * @param color color to draw with
 * @see Imgproc#drawContours(Mat, List, int, Scalar)
 */
public static void drawContours(Mat feed, List<MatOfPoint> contours, Scalar color) {
	for(int i = 0; i < contours.size(); i++)
		Imgproc.drawContours(feed, contours, i, color);
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:13,代码来源:CvProcessing.java


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