I'm working with OpenCV (cv2) in Python3.7 to attempt to create a license plate reader employing the pytesseract module. Using cv2.Canny() to detect the contour edges of the license plate in
the image works fairly well, but when use cv2.approxPolyDP() to reduce the contour to a four-point polygon, the resulting polygon is slightly rotated (represented by the green lines in the image). This negatively affects the ability to interpret the text on the license plate because the text is somewhat rotated after performing a four-point transform to de-warp the polygon into a rectangle. Unfortunately, tesseract 4.0 does not seem to have the capability to detect text rotation for such a small number of characters -- it generates an exception in text_to_osd() for anything less than 133 characters.
I believe the problem may be that license plates have rounded corners, and since cv2.approxPolyDP() is limited to points on the contour, there may be no way to avoid the rotation. In this particular case though, it looks as if there may actually be a better choice for points on the contour that better approximate the plate edges with four points. Unless there is some way to avoid this, I would need some clever way to detect and correct the text rotation, since tesseract appears to be unable to do this for a small number of characters.
So what I'm looking for is a) a method for finding the 4-point contour of a license plate that accurately matches the image or b) an alternate means of detecting text rotation in an image when there are as few as six characters in the image.
Related
I am trying to find symmetry lines or points in my image
My main aim is to find the center of this contour. But I can't use thresholding, so can't use OpenCV contours.
So my next guess it to find symmetric point in my image and hopefully that will correspond to the center of this contour. Any other idea to find center of this contour is also appreciated, something which doesn't involve thresholding as I can't give parameters to user.
I tried finding centroid using cv moments but that didn't give me good results.
I tried using hough circle detection, but it couldn't detect this as circle.
I am using python and OpenCV.
The question is rather vague, lacking adequate sample images and there is little feedback to comments, so it is a stab in the dark as whether you are having difficulty separating the objects, or finding their lines of symmetry, but I wanted to point out that ImageMagick does a pretty good job of separating the objects using the algorithm described here.
Here it is from command line with dithering suppressed:
magick IuOWe.jpg +dither -colors 3 result.jpg
And here with initial blurring:
magick IuOWe.jpg -blur 0x5 +dither -colors 3 result.jpg
Of course you can use similar techniques with OpenCV, or scikit-image as you have tagged Python - it is just quicker to demonstrate my avenue of thought using ImageMagick.
My goal is to draw a rectangle border around the face by removing the neck area connected to the whole face area. All positive values here represent skin color pixels. Here I have so far filtered out the binary image using OpenCV and python. Code so far skinid.py
Below is the test image.
Noise removals have also been applied to this binary image
Up to this point, I followed this paper Face segmentation using skin-color map in videophone applications. And for the most of it, I used custom functions rather than using built-in OpenCV functions because I kind of wanted to do it from scratch. (although some erosion, opening, closing were used to tune it up)
I want to know a way to split the neck from the whole face area and remove it like this,
as I am quite new to the whole image processing area.
Perform a distance transform (built into opencv or you could write by hand its a pretty fun and easy one to write using the erode function iteratively, and adding the result into another matrix each round, lol slow but conceptually easy). On the binary image you presented above, the highest value in a distance transform (and tbh I think pretty generalized across any mug shots) will be the center of the face. So that pixel is the center of your box, but also that value (value of that pixel after the distance transform) will give you a pretty solid approx face size (since it is going to be the pixel distance from the center of the face to the horizontal edges of the face). Depending on what you are after, you may just be able to multiply that distance by say 1.5 or so (figure out standard face width to height ratio and such to choose your best multiplier), set that as your circle radius (or half side width for a box) and call it a day. Comment if you need anything clarified as I am pretty confident in this answer and would be happy to write up some quick code (in c++ opencv) if you need/ it would help.
(alt idea). You could tweak your color filter a bit to reject darker areas (this will at least in the image presented) create a nice separation between your face and neck due to the shadowing of the chin. (you may have to dial back your dilate/ closing op tho)
I am working on an application where I need feature like Cam Scanner where document is to be detected in an image. For that I am using Canny Edge detection followed by Hough Transform.
The results look promising but the text in the document is creating issues as explained via images below:
Original Image
After canny edge detection
After hough transform
My issue lies in the third image, the text in original mage near the bottom has forced hough transform to detect the horizontal line(2nd cluster from bottom).
I know I can take the largest quadrilateral and that would work fine in most cases, but still I want to know any other ways where in this processing I can ignore the effect of text on the edges.
Any help would be appreciated.
I solved the issue of text with the help of median filter of size 15(square) in an image of 500x700.
Median filter doesn't affect the boundaries of the paper, but can help eliminate the text completely.
Using that I was able to get much more effective boundaries.
Another approach you could try is to use thresholding to find the paper boundaries. This would create a binary image. You can then examine the blobs of white pixels and see if any are large enough to be the paper and have the right dimensions. If it fits the criteria, you can find the min/max points of this blob to represent the paper.
There are several ways to do the thresholding, including iterative, otsu, and adaptive.
Also, for best results you may have to dilate the binary image to close the black lines in the table as shown in your example.
To detect a car trailer its very hard. There're a lot of car trailers that has the same license plate as the car itself. To detect if its a trailer I need to search in a area around the license plate. I already making a detector for the license plate with Viola and Jones. Only to detect where the triangle is you don't see it very clearly on the image. The images coming from section control so a lot of different thresholds in the day time.
For the privacy I have to delete the license plate details
So my question are there special ways of image processing that would be help full. I thought about:
- canny
- adapting threshold
- image Gradients
But big difficulty is that the application needs to be real-time.
The way I see it, you will need edge-detection (canny) and image correlation (finding similar shapes; recognition of object in the image).
Your two basic shapes (patterns to seek) would consist of the line-image of license plate, the base line of the bumper, edges of the lights, and respectively the triangles for one and no triangles in the other. The presence and absence of the triangles should be the only difference between the two images to be sought.
First, you process the image through Canny or Sobel or some other edge-detect to get the edges. Then you correlate it with the two patterns. The correlation function should produce "quality of match" value - how well the shape found in the image matches the pattern. If the one with triangles matches better, it's the trailer.
Don't try to detect just the triangles. They are too dim to produce a decent match, and too common a shape, possibly producing countless false positives. Seek bumper with lights and license plate, and then once that is found, compare it to example bumper with triangles, and example bumper without triangles. That way no matter how poor the triangle detection, the match against the image with triangles will always be better if they are there.
Using python, which may be the best algorithm or the best strategy to detect the presence of colored bands as in image?
The image is scanned and cropped, the problem is that the crop not to be precise and I can not make use of a control that makes use of Cartesian coordinates to determine if the lines are present.
The strips may be present or not.
You have a number of options at your disposal:
If the strips are going to be the same size, and their orientation is known, then you can use cross-correlation (with working Python source). Your template image could be a single stripe, or a multiple strip pattern if you know the number of strips and their spacing.
More generally, you could go with morphological image processing and look for rectangles. You'd first have to threshold your image (using Ohtsu's method or some empirically determined threshold) and then perform contour detection. Here's an example that does something similar, but for ellipses -- it's trivial to modify it to look for rectangles. This time the source in in C, but it uses OpenCV like the first example, so it should be trivial to port
There are other approaches such as edge detection and Fourier analysis, but I really think that the first two are going to be more than enough for you.