kos*_*bou 3 java android opencv
我正在使用以下代码来查找图像的垫轮廓.我发现轮廓正确.但是当我尝试在轮廓处裁剪图像时,应用程序崩溃了.我哪里错了?
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(imageA, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
for(int i=0; i< contours.size();i++){
if (Imgproc.contourArea(contours.get(i)) > 50 ){
Rect rect = Imgproc.boundingRect(contours.get(i));
if (rect.height > 28){
Core.rectangle(image, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(0,0,255));
Mat ROI = image.submat(rect.x, rect.x + rect.heigth, rect.x, rect.x + rect.width);
Highgui.imwrite("/mnt/sdcard/images/test4.png",ROI);
}
}
}
Run Code Online (Sandbox Code Playgroud)
你的submat看起来很破碎:
Mat ROI = image.submat(rect.x, rect.x + rect.heigth, rect.x, rect.x + rect.width);
Run Code Online (Sandbox Code Playgroud)
它应该是这样的(我们在这里的行/ col世界):
Mat ROI = image.submat(rect.y, rect.y + rect.heigth, rect.x, rect.x + rect.width);
Run Code Online (Sandbox Code Playgroud)
http://docs.opencv.org/java/org/opencv/core/Mat.html#submat(int,%20int,%20int,%20int)
| 归档时间: |
|
| 查看次数: |
7465 次 |
| 最近记录: |