仅在部分帧上检测轮廓
Detect contours only on a part of frame
是否可以检测部分传入帧的轮廓?
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));
假设您已经知道如何在图像中查找轮廓或如何准备 Mat
来查找轮廓。您只需在 Mat
.
中指定一个 ROI(感兴趣区域)
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));
应用后我得到这个:
输入
输出
如您所见,它只识别了 ROI 内的部分矩形。
是否可以检测部分传入帧的轮廓?
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));
假设您已经知道如何在图像中查找轮廓或如何准备 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));
应用后我得到这个:
输入
输出
如您所见,它只识别了 ROI 内的部分矩形。