Android edge detection opencv

I am creating a project, where I have to remove the background from the image and detect the object.

I am using canny edge detection for detecting edges and than finding contours and than draw contours on a masked image, but after canny edge detection, I am getting broken edges ,how to fix that.

For Canny edge detection, for Threshold parameter, I have tried using thresholding with otsu's method for higher and lower threshold, but it doesn't seem to give appropriate result. Further, I have tried finding the mean of pixel values, and finding

double high_threshold = 1.33 * d;
double low_threshold = 0.66 * d;

it is also not giving accurate result. what else I can do

Mat rgba = new Mat();
Utils.bitmapToMat(bitmap, rgba);
Mat edges = new Mat(rgba.size(), CvType.CV_8UC1);Imgproc.cvtColor(rgba, edges, Imgproc.COLOR_RGB2GRAY, 4);
Imgproc.GaussianBlur(edges, edges, new Size(3,3), 2); Mat thresh=new Mat();
double upper_threshold = Imgproc.threshold(edges,thresh,0,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C| Imgproc.THRESH_OTSU);
double lower_threshold = 0.1*upper_threshold;Imgproc.Canny(edges,edges,upper_threshold,lower_threshold,3,false);Mat mDilatedMat = new Mat();

Mat Meroded = new Mat();
double erosion_size=5;
double dilation_size=4;
Mat e=  Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new  Size(2*erosion_size + 1, 2*erosion_size+1));
Mat f=  Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new  Size(2*dilation_size + 1, 2*dilation_size+1));
Imgproc.dilate(edges, mDilatedMat,e);
Imgproc.erode(mDilatedMat, Meroded,f);

You can improve your image extracted by sobel , canny or a different algorithm by applying edge linking algorithm. Many edge linking algorithms are avaliable to use such as hough transform, ant colony algorithm etc.

链接地址: http://www.djcxy.com/p/79666.html

上一篇: 如何提高检测性检测的准确性

下一篇: Android边缘检测opencv