我正在尝试使用 android-opencv 2.3.1 来识别图像中的圆圈(硬币)。但是,通过执行 Imgproc.cvtColor 方法会发生错误(org.opencv.cvException)。
File imgFile = new File(Environment.getExternalStorageDirectory() + "/test.jpg");
imageBmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Mat mImg = new Mat();
mImg = Utils.bitmapToMat(imageBmp);
Mat mGray = new Mat(mImg.rows(), mImg.cols(), CvType.CV_8UC1, new Scalar(0));
Imgproc.cvtColor(mImg , mGray, Imgproc.COLOR_BGRA2GRAY, 4);
Imgproc.GaussianBlur( mGray , mGray , new Size(9, 9), 2, 2);
Mat circles = new Mat();
Imgproc.HoughCircles(mGray , circles, Imgproc.CV_HOUGH_GRADIENT, 1d, (double)
mGray.height() / 70, 200d, 100d);
我究竟做错了什么?手机:三星 Galaxy S i9000
只是用新代码更新我的问题。“Imgproc.cvtColor”方法仍然给出同样的错误。
File imgFile = new File(Environment.getExternalStorageDirectory() + "/test.jpg");
imageBmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Mat mImg = new Mat();
mImg = Utils.bitmapToMat(imageBmp);
Mat mGray = new Mat(mImg.rows(), mImg.cols(), CvType.CV_8UC1);
Imgproc.cvtColor(mImg, mGray, Imgproc.COLOR_BGRA2GRAY);
Imgproc.GaussianBlur(mGray, mGray, new Size(9, 9), 2, 2);
Mat circleImage = new Mat(mGray.rows(), mGray.cols(), CvType.CV_8UC1);
Imgproc.HoughCircles(mGray, circleImage, Imgproc.CV_HOUGH_GRADIENT, 1d,
(double) mGray.height() / 70, 200d, 100d);