OpenCV Android:在新Mat中定义并保存ROI(OpenCV Android: Define and save ROI in new Mat)
我正在尝试将我的图像的一部分切割(裁剪)到另一个,因此它可以单独处理。 我找到了轮廓,现在试图在新Mat中保存每个轮廓,但它给出了错误
Mat crop;
Imgproc.findContours(m, contours, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
for(int i=0; i
{
Rect rect = Imgproc.boundingRect(contours.get(i));
crop = m.submat(rect);
}
Utils.matToBitmap(crop, bm);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(bm);
这里是我保存图像的Mat
错误:
I am trying to slice (crop) part of my image to another so it can be worked on separately. I have found contours and now trying to save every contour in new Mat but it is giving error
Mat crop;
Imgproc.findContours(m, contours, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
for(int i=0; i
{
Rect rect = Imgproc.boundingRect(contours.get(i));
crop = m.submat(rect);
}
Utils.matToBitmap(crop, bm);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(bm);
Here m is my Mat where image is saved
Error:
原文:https://stackoverflow.com/questions/29365064
2019-11-23 22:11
满意答案
在这种情况下我总是做的是使用带有rect的构造函数创建一个新的mat:
Mat cropped = new Mat(mOriginal, boudingRect);
编辑:
您的位图也应该具有相同的大小:
bm = Bitm