我正在开发一款Android应用,它将从Bitmap
获得ImageView
。将此Bitmap
转换为JavaCV IplImage
,然后转换为灰度,如下所示:
IplImage image = IplImage.create(width, height, IPL_DEPTH_8U, 4);
bitmap.copyPixelsToBuffer(image.getByteBuffer());
IplImage _3image = IplImage.create(width, height, IPL_DEPTH_8U, 3);
IplImage _1image = IplImage.create(width, height, IPL_DEPTH_8U, 1);
cvCvtColor(image, _3image, CV_BGRA2BGR);
cvCvtColor(_3image, _1image, CV_RGB2GRAY);
但是当我这样做时,我得到RuntimeException: Buffer not large enough for pixels
Bitmap x = Bitmap.createBitmap(width, height, Config.ARGB_8888);
x.copyPixelsFromBuffer(_1image.getByteBuffer());
任何帮助将不胜感激。谢谢。