1) OpenCV Mat constructor expects <rows, cols>
pair instead of <width, height>
as its arguments. So you have to change your second line to
Mat tmp = new Mat (height, width, CvType.CV_8U, new Scalar(4));
2) Imgproc.cvtColor
can change the dimensions of the tmp
object. So it is safe to create a bitmap after the color conversion:
Bitmap bmp = null;
Mat tmp = new Mat (height, width, CvType.CV_8U, new Scalar(4));
try {
//Imgproc.cvtColor(seedsImage, tmp, Imgproc.COLOR_RGB2BGRA);
Imgproc.cvtColor(seedsImage, tmp, Imgproc.COLOR_GRAY2RGBA, 4);
bmp = Bitmap.createBitmap(tmp.cols(), tmp.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(tmp, bmp);
}
catch (CvException e){Log.d("Exception",e.getMessage());}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…