简体   繁体   English

Android边缘检测opencv

[英]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. 对于Canny边缘检测,对于阈值参数,我已经尝试使用阈值和otsu的方法来获得更高和更低的阈值,但它似乎没有给出适当的结果。 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. 您可以通过应用边缘链接算法来改善sobel,canny或不同算法提取的图像。 Many edge linking algorithms are avaliable to use such as hough transform, ant colony algorithm etc. 许多边缘链接算法可用于诸如霍夫变换,蚁群算法等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM