Java 仅在帧的一部分上检测轮廓
是否有可能在传入帧的一部分上检测轮廓Java 仅在帧的一部分上检测轮廓,java,android,opencv,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(r
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中指定感兴趣的ROI区域 应用此方法后,我得到以下结果: 输入 输出 正如您所见,它无法识别整个矩形,而只能识别ROI内的部分矩形。垫子的ROI也是垫子。你可以取出rect描述的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));