Here's how I suggest you should do this task. Read my detailed answer here.
- Convert to Grayscale.
- Gaussian Blur with 3x3 or 5x5 filter.
Apply Sobel Filter to find vertical edges.
Sobel(gray, dst, -1, 1, 0)
- Threshold the resultant image to get a binary image.
- Apply a morphological close operation using suitable structuring element.
- Find contours of the resulting image.
- Find
minAreaRect
of each contour. Select rectangles based on aspect ratio and minimum and maximum area.
- For each selected contour, find edge density. Set a threshold for edge density and choose the rectangles breaching that threshold as possible plate regions.
- Few rectangles will remain after this. You can filter them based on orientation or any criteria you deem suitable.
- Clip these detected rectangular portions from an image after
adaptiveThreshold
of the original (grayscale) image and apply OCR.