仅在帧的一部分上检测轮廓

时间:2015-01-21 03:05:25

标签: java android opencv

是否可以检测部分传入帧的轮廓?

    Imgproc.findContours(threshold_output, contourList, mHierarchy,
            Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    Rect rect = new Rect(new Point(0,0), new Point(x,y));
    Mat subMat = incomingFrame.submat(rect);
    // MAKE ONLY CONTOUR OUTSIDE RECT DETECTABLE
    subMat.copyTo(incomingFrame.submat(rect));

1 个答案:

答案 0 :(得分:0)

假设您已经知道如何在图像中找到轮廓或如何准备Mat来查找轮廓。您只需在Mat中指定投资回报率(感兴趣的区域)。

Mat frame = Highgui.imread("image/test.jpg");
// this is not a copy of frame, drawings on frameROI will also appear on frame
// rect describes ROI, starting at x,y = 50 and width, height = 100 
Mat frameROI = new Mat(frame, new Rect(50, 50, 100, 100));

// find contours in (processed to improve contour finding) frameROI
Imgproc.findContours(frameROIprepared, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

// go through all the contours in my contour list and draw them
for (int i = 0; i < contours.size(); i++)
    Imgproc.drawContours(frameROI, contours, i, new Scalar(0, 255, 0));

申请后我得到了这个:

<强>输入

enter image description here

<强>输出

enter image description here

正如您所看到的,它无法识别整个矩形,只是它在ROI内部的部分。