Closed. This question needs to be more
focused。它当前不接受答案。
想改善这个问题吗?更新问题,使其仅关注
editing this post一个问题。
6年前关闭。
Improve this question
我想知道哪种算法用于检测药丸和胶囊?那就是使用opencv和android检测表上胶囊的数量。
我使用过的过程:首先捕获图像,然后应用灰度,然后在应用阈值后应用阈值,然后应用侵 eclipse ,然后在使用houghcircles之后尝试检测胶囊,但无法检测到任何胶囊。
请给解决方案.....
我到目前为止已经尝试过:这是我在android opencv中检测药丸的代码。
Bitmap i = getBitmap(imgPath + "orignal.jpg");
//Log.i("after Bitmap i",""+imgPath);
Bitmap bmpImg = i.copy(Bitmap.Config.ARGB_8888, false);
bmpImg =SetBrightness(bmpImg,-60);
//Log.i("after Bitmap bmpImg",""+imgPath);
Mat srcMat = new Mat ( bmpImg.getHeight(), bmpImg.getWidth(), CvType.CV_8UC3);
Bitmap myBitmap32 = bmpImg.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmpImg, srcMat);
//convert to gray scale and save image
Mat gray = new Mat(srcMat.size(), CvType.CV_8UC1);
//Imgproc.cvtColor(srcMat, gray, Imgproc.COLOR_RGB2GRAY,4);
Imgproc.cvtColor(srcMat, gray, Imgproc.COLOR_BGRA2GRAY);
//write bitmap
Boolean grayBool = Highgui.imwrite(imgPath + "gray.jpg", gray);
Imgproc.medianBlur(gray, gray,51);
Utils.matToBitmap(gray, bmpImg);
//thresholding
Mat threshed = new Mat(bmpImg.getWidth(),bmpImg.getHeight(), CvType.CV_8UC1);
Imgproc.adaptiveThreshold(gray, threshed, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 75, 5);//15, 8 were original tests. Casey was 75,10//(smoothed, threshed, 250, 250, 0);
Core.bitwise_not(threshed, threshed);
Boolean threshedBool = Highgui.imwrite(imgPath + "threshed.jpg", threshed);
Utils.matToBitmap(threshed, bmpImg);
Imgproc.GaussianBlur(threshed, threshed, new org.opencv.core.Size(9, 9), 2, 2);
Utils.matToBitmap(threshed, bmpImg);
//erosion
Mat eroded = new Mat(bmpImg.getWidth(),bmpImg.getHeight(), CvType.CV_8UC1);
Imgproc.erode(threshed, eroded, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new org.opencv.core.Size(15, 15)));
Utils.matToBitmap(eroded, bmpImg);
//write bitmap
Boolean boolEroded = Highgui.imwrite(imgPath + "eroded.jpg", eroded);
//smoothing
//Imgproc.GaussianBlur(threshed, threshed, new org.opencv.core.Size(3,3), 50);
Imgproc.GaussianBlur(edge, threshed, new org.opencv.core.Size(9, 9), 2, 2);
Utils.matToBitmap(threshed, bmpImg);
//hough circles
Mat circles = new Mat();
Imgproc.HoughCircles( eroded, circles, Imgproc.CV_HOUGH_GRADIENT,1, eroded.rows()/8, 200,100, eroded.cols()/25, eroded.cols()/6 );
//Imgproc.HoughCircles( threshed, circles, Imgproc.CV_HOUGH_GRADIENT,1, threshed.rows()/8,100, 80, 10, 100);
请协助。谢谢。