1
我試圖使用android-opencv 2.3.1來識別圖像中的圓圈(硬幣)。 但是通過執行方法Imgproc.cvtColor發生錯誤(org.opencv.cvException)。Android OpenCv HoughCircles
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);
我做了更改,但仍然給出相同的錯誤。 –
你能更新你的問題嗎?也許只需添加新的修訂代碼,以便我們看到現在的樣子。 – fireant
當然。我會在下面發佈我的代碼。 –