我想隐蔽垫为位图使用下面的code:
I'm trying to covert a MAt to a Bitmap use following code :
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Mat tmp = new Mat (width,height,CvType.CV_8UC1,new Scalar(4));
try {
//Imgproc.cvtColor(seedsImage, tmp, Imgproc.COLOR_RGB2BGRA);
Imgproc.cvtColor(seedsImage, tmp, Imgproc.COLOR_GRAY2RGBA, 4);
Utils.matToBitmap(tmp, bmp);}
catch (CvException e){Log.d("Exception",e.getMessage());}
我seedsImage是垫目标。
而例外,得到的是 10-09 22:15:09.418:D /异常(2461):.. \ .. \模块\ java的\生成的\ src \ CPP \ utils.cpp:105:错误:(-215)src.dims == 2&安培;&安培; info.height ==(uint32_t的)src.rows和放大器;&安培; info.width ==(uint32_t的)函数src.cols无效Java_org_opencv_android_Utils_nMatToBitmap2(的JNIEnv *,_jclass *,jlong,_jobject *,jboolean)
尝试搜索直通,但没有解决我的作品。
可以anynone帮助?
my seedsImage is a Mat object.
And the Exception and got is 10-09 22:15:09.418: D/Exception(2461): ..\..\modules\java\generator\src\cpp\utils.cpp:105: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, _jclass*, jlong, _jobject*, jboolean)
Try to search thru but no solution works for me.
Can anynone help?
1)OpenCV的垫构造函数需要<行,COLS>
对代替<宽度,高度和GT;
作为参数。所以,你必须将你的第二行改为
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
可以修改 TMP
对象的尺寸。所以它是安全的创建位图的色彩转换后:
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());}