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


Java Imgproc.boundingRect方法代码示例

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


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

示例1: createParticleReports

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Takes the base OpenCV list of contours and changes the output to be easier to
 * work with.
 * 
 * @param contours
 *            The input from the base OpenCV contours output
 */
private void createParticleReports (List<MatOfPoint> contours)
{
    ParticleReport[] reports = new ParticleReport[contours.size()];

    for (int i = 0; i < reports.length; i++)
        {
        reports[i] = new ParticleReport();
        Rect r = Imgproc.boundingRect(contours.get(i));
        reports[i].area = r.area();
        reports[i].center = new Point(r.x + (r.width / 2),
                r.y + (r.height / 2));
        reports[i].boundingRect = r;
        }

    this.particleReports = reports;
}
 
开发者ID:FIRST-Team-339,项目名称:2017,代码行数:24,代码来源:VisionProcessor.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: 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

示例4: setUpCamera

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void setUpCamera(){
    CameraServer.getInstance().startAutomaticCapture();
    camera = CameraServer.getInstance().startAutomaticCapture();
    //camera.setResolution(RobotMap.IMG_WIDTH, RobotMap.IMG_HEIGHT);
    //camera.setExposureManual(RobotMap.exposure);
    visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> {
        if (!pipeline.filterContoursOutput().isEmpty()) {
            Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
            synchronized (imgLock) {
                centerX = r.x + (r.width / 2);
            }
        }
    });
}
 
开发者ID:mr-glt,项目名称:FRC-2017-Command,代码行数:15,代码来源:Vision.java

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

示例6: startThread

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

        if (thread == null) {
            // Create a new thread that will constantly evaluate new camera frames
            thread = new Thread(() -> {

                Mat image = new Mat(CAMERA_HEIGHT, CAMERA_WIDTH, 6);

                while (!Thread.interrupted()) {

                    // Check whether it's time to evaluate a new rame
                    currentFrameTime = sink.grabFrameNoTimeout(image);
                    if (currentFrameTime == 0 || currentFrameTime == prevFrameTime) {
                        continue;
                    }
                    prevFrameTime = currentFrameTime;

                    // Process image using generated pipeline
                    pipeline.process(image);

                    // Get pipeline objects
                    ArrayList<MatOfPoint> mops = pipeline.filterContoursOutput();

                    // Evaluate objects
                    for (MatOfPoint mop : mops) {
                        Rect bRect = Imgproc.boundingRect(mop);
                        Imgproc.rectangle(image, bRect.tl(), bRect.br(), new Scalar(255, 0, 255));
                        // TODO: Evaluate objects
                    }

                    // Send the evaluated image to the output stream
                    output.putFrame(image);

                }
            });
            
            thread.start();
        }
    }
 
开发者ID:vyrotek,项目名称:frc-robot,代码行数:40,代码来源:Vision.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:mustafamertunali,项目名称:FRC-6416-frc2017,代码行数:48,代码来源:GripPipeline.java

示例8: getRawTargets

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Utilizes the processed contours and wraps them
 * into bounding rectangles
 * @return the unprocessed targets as bounding rectangles
 * @see TargetSource#getContoursReport()
 * @see Rect
 */
default Rect[] getRawTargets() {
	List<MatOfPoint> contours = this.getContoursReport();
	Rect[] rawTargets = new Rect[contours.size()];
	
	for(int i = 0; i < rawTargets.length; i++) {
		rawTargets[i] = Imgproc.boundingRect(contours.get(i));
	}
	
	return rawTargets;
}
 
开发者ID:KHS-Robotics,项目名称:DemonVision,代码行数:18,代码来源:TargetSource.java

示例9: filterContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public List<MatOfPoint> filterContours(List<MatOfPoint> contours) {
    List<MatOfPoint> output = new ArrayList<>();
    for (MatOfPoint contour : contours) {
        final Rect boundingRect = Imgproc.boundingRect(contour);

        final double rectArea = boundingRect.area();

        final double targetAreaPercent = rectArea / imageArea * 100;

        if (!area.inRangeInclusive(targetAreaPercent)) {
            continue;
        }

        final double targetAspect = boundingRect.width / boundingRect.height;

        if (!aspectRatio.inRangeInclusive(targetAspect)) {
            continue;
        }

        final double targetArea = Imgproc.contourArea(contour);

        final double targetFullness = targetArea / rectArea * 100;

        if (!fullness.inRangeInclusive(targetFullness)) {
            continue;
        }

        output.add(contour);
    }
    return output;
}
 
开发者ID:kylecorry31,项目名称:Robot-Vision-API,代码行数:33,代码来源:StandardContourFilter.java

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

示例11: computeBoundingRectangle

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private Rect computeBoundingRectangle(MatOfPoint mop1, MatOfPoint mop2) {
	Rect rec1 = Imgproc.boundingRect(mop1);
	Rect rec2 = Imgproc.boundingRect(mop2);
	int x = Math.min(rec1.x, rec2.x);
	int y = Math.min(rec1.y, rec2.y);
	int width = Math.max(rec1.x + rec1.width, rec2.x + rec2.width)-x;
	int height = Math.max(rec1.y + rec1.height, rec2.y + rec2.height)-y;
	Rect recCombine = new Rect(x, y, width, height);
	return recCombine;
}
 
开发者ID:cyborgs3335,项目名称:STEAMworks,代码行数:11,代码来源:VisionTest.java

示例12: scoreContour

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Score contour based on a variety of factors
 * @param mop contour to score
 * @return contour score (range from 0 to infinity?)
 */
private double scoreContour(MatOfPoint mop) {
	// Score on solidity -- ideally find 100% solid rectangle
	final MatOfInt hull = new MatOfInt(); // is this expensive?
	final double area = Imgproc.contourArea(mop);
	Imgproc.convexHull(mop, 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[] { mop.get(index, 0)[0], mop.get(index, 0)[1]};
		mopHull.put(j, 0, point);
	}
	final double solid = 100 * area / Imgproc.contourArea(mopHull);
	double scoreSolidity = solid;

	// Score aspect ratio -- exact ratio is 0.4
	final Rect bb = Imgproc.boundingRect(mop);
	final double ratio = bb.width / (double)bb.height;
	final double targetRatio = 0.4;
	final double minRatio = 0.0;
	final double maxRatio = 1.0;
	double scoreAspectRatio = 0;
	if (ratio < minRatio || ratio > maxRatio) {
		scoreAspectRatio = 0;
	} else {
		if (ratio > targetRatio) {
			scoreAspectRatio = 1 - (ratio - targetRatio) / (maxRatio - targetRatio);
		} else {
			scoreAspectRatio = 1 - (targetRatio - ratio) / (targetRatio - minRatio);
		}
		scoreAspectRatio *= 100;
	}

	// Compute final score
	double score = scoreSolidity + scoreAspectRatio;
	return score;
}
 
开发者ID:cyborgs3335,项目名称:STEAMworks,代码行数:43,代码来源:VisionTest.java

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

示例14: getRectFromArray

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static Rect getRectFromArray(Rect[] rects, MatOfPoint contour, int i){
	Rect r = rects[i] != null ? rects[i] : Imgproc.boundingRect(contour);
	if(rects[i] == null) 
		rects[i] = r;
	return r;
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:7,代码来源:CvProcessing.java

示例15: wrapCvContour

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Saves data from an opencv {@link MatOfPoint} into a {@link Contour} object
 * to simplify data for user.
 * 
 * @param contour opencv contour
 * @return a contour wrapper
 */
public static Contour wrapCvContour(MatOfPoint contour){
	Rect rect = Imgproc.boundingRect(contour);
	Point center = contourCenter2(rect);
	return new Contour((int)center.x, (int)center.y, rect.width, rect.height);
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:13,代码来源:CvProcessing.java


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