One problem is possibly here:
Mat image = new Mat(bitmap.getWidth(), bitmap.getHeight(), CvType.CV_8UC1);
When you create a Mat
, the arguments are rows
, cols
, so you should be doing this:
Mat image = new Mat(bitmap.getHeight(), bitmap.getWidth(), CvType.CV_8UC1);
However, the error implies that the source and destination images are different sizes. So, noting that the roi.copyTo(image)
call will resize image
to match the size of the region of interest, it may not match your original bitmap.
So, either you have to create a bitmap of the same size as the ROI, and then copy to that, or you have to resize the ROI to match your recieving bitmap.
You can do this to make sure that you know what size bitmap to use:
Mat image = new Mat(roi.size(), CvType.CV_8UC1);
// unsure of syntax for your platform here... but something like ...
Bitmap newBitmap = Bitmap.createBitmap(image.cols(), image.rows(),
Bitmap.Config.ARGB_8888);
// now copy the image
Utils.matToBitmap(image, newBitmap);