72

I have a web site that allows users to upload images of cars and I would like to put a privacy filter in place to detect registration plates on the vehicle and blur them.

The blurring is not a problem but is there a library or component (open source preferred) that will help with finding a licence within a photo?

Caveats;

  1. I know nothing is perfect and image recognition of this type will provide false positive and negatives.
  2. I appreciate that we could ask the user to select the area to blur and we will do this as well, but the question is specifically about finding that data programmatically; so answers such as 'get a person to check every image' is not helpful.
  3. This software method is called 'Automatic Number Plate Recognition' in the UK but I cannot see any implementations of it as libraries.
  4. Any language is great although .Net is preferred.
Ambo100
  • 1,185
  • 3
  • 15
  • 28
Ryan O'Neill
  • 5,410
  • 4
  • 46
  • 69
  • Any web service that does this? Sending pictures is of course data-intensive but they could be resized and set to greyscale before sending. – Somatik Mar 30 '12 at 16:15
  • you might also give a try at SimpleLPR http://www.warelogic.com –  Apr 17 '10 at 20:32

11 Answers11

36

EDIT: I wrote a Python script for this.

As your objective is blurring (for privacy protection), you basically need a high recall detector as a first step. Here's how to go about doing this. The included code hints use OpenCV with Python.

  1. Convert to Grayscale.
  2. Apply Gaussian Blur.

    img = cv2.imread('input.jpg',1)
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img_gray = cv2.GaussianBlur(img_gray, (5,5), 0)  
    

Let the input image be the following.

enter image description here

  1. Apply Sobel Filter to detect vertical edges.
  2. Threshold the resultant image using strict threshold or OTSU's binarization.

    cv2.Sobel(image, -1, 1, 0)
    cv2.threshold() 
    
  3. Apply a Morphological Closing operation using suitable structuring element. (I used 16x4 as structuring element)

    se = cv2.getStructuringElement(cv2.MORPH_RECT,(16,4))
    cv2.morphologyEx(image, cv2.MORPH_CLOSE, se)  
    

Resultant Image after Step 5.

enter image description here

  1. Find external contours of this image.

    cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 
    
  2. For each contour, find the minAreaRect() bounding it.

  3. Select rectangles based on aspect ratio, minimum and maximum area, and angle with the horizontal. (I used 2.2 <= Aspect Ratio <= 8, 500 <= Area <=15000, and angle <= 45 degrees)

All minAreaRect()s are shown in orange and the one which satisfies our criteria is in green.

enter image description here

  1. There may be false positives after this step, to filter it, use edge density. Edge Density is defined as the number of white pixels/total number of pixels in a rectangle. Set a threshold for edge density. (I used 0.5)

enter image description here

  1. Blur the detected regions.

enter image description here

You can apply other filters you deem suitable to increase recall and precision. The detection can also be trained using HOG+SVM to increase precision.

Abdul Fatir
  • 6,159
  • 5
  • 31
  • 58
  • This is great work, and the pyANPD.py library works well to detect the regions, but could you give a pointer for us non-Pythonites as to how they can then be blurred? – fooquency Jul 12 '19 at 10:26
  • Can you use this for the web? A user uploads a photo of a car and you would extract the number plate. – Xerri Mar 14 '23 at 05:22
34

I coded a C# version based on JAVA ANPR, but I changed the awt library functions with OpenCV. You can check it at http://anprmx.codeplex.com

Jivan Miranda
  • 356
  • 3
  • 2
14

There is a new, open source library on GitHub that does ANPR for US and European plates. It looks pretty accurate and it should do exactly what you need (recognize the plate regions). Here is the GitHub project: https://github.com/openalpr/openalpr

Derrick Johnson
  • 377
  • 5
  • 9
10

I came across this one that is written in java javaANPR, I am looking for a c# library as well.

I would like a system where I can point a video camera at some sailing boats, all of which have large, identifiable numbers on them, and have it identify the boats and send a tweet when they sail past a video camera.

Bruce McLeod
  • 1,362
  • 15
  • 21
8

I have done some googling about this a couple of months ago. There are quite a few papers about this topic, but I never found any concrete open-source implementation. There are a lot of commercial implementations though, but none of them with a price quote, so they're probably pretty expensive.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
5

try this Simple Automatic Number Plate Recognition System

http://opos.codeplex.com/

Open source and written with C#

Birol Kuyumcu
  • 1,195
  • 7
  • 17
3

Have a look at Java ANPR. Free license plate recognition...

2

Yes I use gocr at http://jocr.sourceforge.net/ its a commandline application which you could execute from your application. I use it in a couple of my applications.

keyoke
  • 1,209
  • 12
  • 26
2

High performance ANPR Library - http://www.dtksoft.com/dtkanpr.php. This is commercial, but they provide trial key.

codeguru
  • 21
  • 1
  • I tested this library in comparison with OpenALPR. Nowhere near it! From the 15 images that I had in my library to test, OpenALPR detected 6, this one detected 0. I suppose this library is very dependent on the camera placement and light conditions. – XMight Jan 08 '16 at 13:30
2

http://licenseplate.sourceforge.net Python (I have not tested it)

Somatik
  • 4,723
  • 3
  • 37
  • 49
-1

It maybe work looking at Character recoqnition software as there are many libraries out there that perform the same thing. I reading an image and storing it. Micrsoft office is able to read tiff files and return alphanumerics