I'm using a project using OpenCV for detecting a card that will be place on a atable. I have successfully detect it using Canny Edge. However, for different image the parameter must be tuned manually. I wish for my project to be worked with every image without manually tune the parameter. What Should I do?
Asked
Active
Viewed 1.0k times
6
-
what's the difference between the images? maybe some kind of normalization (white balance, brightness, contrast) of the input image and fixed canny parameters will give you the desired behaviour. – Micka Jul 10 '14 at 09:29
2 Answers
8
If your image consist of Distinct Background & Foreground, You can get the threshold for that automatically as follows explained in this paper http://www.academypublisher.com/proc/isip09/papers/isip09p109.pdf.
- Compute Otsu's threshold + Binary threshold for your image.
- Use the Otsu's threshold value as higher threshold for Canny's algorithm.
CODE:
Mat mCanny_Gray,mThres_Gray;
Mat mSrc_Gray=imread("Test.bmp",0);
double CannyAccThresh = threshold(mSrc_Gray,mThres_Gray,0,255,CV_THRESH_BINARY|CV_THRESH_OTSU);
double CannyThresh = 0.1 * CannyAccThresh;
Canny(mSrc_Gray,mCanny_Gray,CannyThresh,CannyAccThresh);
imshow("mCanny_Gray",mCanny_Gray);
You can also refer this thread.
-
What preprocessing technique do I need for the image before I apply your answer? Is converting to Grayscale is sufficient or I need to apply some thresholding as well? – IllSc Jul 13 '14 at 15:49
-
For all edge detection techniques you need to apply smoothing e.g Gaussian smoothing before applying edge detection. It is good to convert your image into a Gray Scale Image. – Balaji R Jul 14 '14 at 06:32
-
Two parameters having a 10 fold difference seems too much to me. Could you comment on this? – M. Azyoksul Apr 22 '19 at 08:01