我正在尝试将我的图像的一部分切割(裁剪)到另一个,以便可以单独处理。我找到了轮廓,现在试图在新Mat中保存每个轮廓但是它给出了错误
Mat crop;
Imgproc.findContours(m, contours, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
for(int i=0; i <contours.size();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);
这里是我保存图像的垫子
错误:
答案 0 :(得分:4)
在这种情况下,我总是使用带有rect的构造函数创建一个新的mat:
Mat cropped = new Mat(mOriginal, boudingRect);
编辑:
您的位图也应该具有相同的尺寸:
bm = Bitmap.createBitmap(crop.size().width,crop.size().height, Bitmap.Config.ARGB_8888);