1

I am using OpenCV on Android for doing number plate recognition. As part of the process I am using Canny edge detection to find the edges within the image. The problem I am having is that the horizontal edges within the image are not being detected as solid lines. The problems is that because the lines are not solid I cannot detect it as one contour

This is the image that I am running the edge detection on

enter image description here

This is the result of the edge detection. As you can see the vertical edges of the number plate have been detected as solid lines but the horizontals are dotted.

enter image description here

Here is my code

        org.opencv.imgproc.Imgproc.Canny(snapshot.getImage(), dst,
            Configurator.PlateDetectCannyThreshold1,
            Configurator.PlateDetectCannyThreshold2,
            Configurator.PlateDetectCannyApperture);
    List<Mat> contours = new Vector<Mat>();
    org.opencv.imgproc.Imgproc.findContours(dst, contours, new Mat(),
            org.opencv.imgproc.Imgproc.CV_RETR_LIST,
            org.opencv.imgproc.Imgproc.CV_CHAIN_APPROX_SIMPLE,
            new org.opencv.core.Point(0, 0));
Mike Norgate
  • 2,173
  • 3
  • 19
  • 40
  • You have bad thresholds in Canny. Lower them a bit. – Sam Mar 21 '12 at 14:18
  • I have tried that. I should have mentioned that my upper threshold is at 300 and the lower is at 0 for the image above but I have lowered the upper image incrementally down to 0 and it's made no difference – Mike Norgate Mar 21 '12 at 14:36
  • The upper threshold should be set somewhere around 40120, and the lower threshold as 0.4*upper, or upper/3. I think it's always good to read a bit. `wiki canny` on google, and read how canny works. It's important – Sam Mar 21 '12 at 14:42
  • I have tried adjusting the thresholds and I have a good understanding of how the algorithm works, but I'm still seeing the same problem with horizontal lines – Mike Norgate Mar 21 '12 at 15:20
  • From my understanding of the problem is probably going to be caused because of the angle of the line and it not being completely level. I might be able to fix it using OpenCV erode, does anyone know how to get erode to work in Android as my tests just give me a black image – Mike Norgate Mar 21 '12 at 15:39
  • Same result can be achieved by this: http://android-coding.blogspot.com/2012/05/android-image-processing-edge-detect.html – TharakaNirmana Oct 18 '13 at 08:49

2 Answers2

2

I ran into similar problem when i implement document edge detection and used Morphology to dilate the edge for better detection:

 Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3,3), new Point(1,1));
 Imgproc.dilate(mIntermediateMat, mIntermediateMat, kernel);
Shailesh
  • 131
  • 1
  • 7
  • can you share steps you performed? – RBK Oct 12 '16 at 08:47
  • @RBK please refer to [Square Detetection](http://stackoverflow.com/questions/8667818/opencv-c-obj-c-detecting-a-sheet-of-paper-square-detection?rq=1) it describes the steps very well. – Shailesh Oct 13 '16 at 16:47
1

A quick and dirty solution would be using morphological closing operation as described here.

Morphological closing operation helps filling small gaps.

Hakan Serce
  • 10,888
  • 3
  • 26
  • 43