Code Monkey home page Code Monkey logo

train-detector's Introduction

train-detector

This repository contains scripts that will help train a license plate detector for a particular region. Your trained region detector can then be used in OpenALPR.

The license plate region detector uses the Local Binary Pattern (LBP) algorithm. In order to train the detector, you will need many positive and negative images. This repository already contains a collection of negative images. You will need to add your own positive images.

To get started, you will first need many cropped plate images containing positive license plate matches. Please see the "eu" positive image folder in this repository to understand the types of plate images required.

The Plate Tagger Utility is helpful to tag the plate locations. After tagging the plates you can run the "crop_plates.py" function to extract the crops from the input images at your target aspect ratio.

After you've collected many (hundreds to thousands) of positive plate images, the next step is to train the detector. First you must configure the training script to use the correct dimensions.

Edit the prep.py script and change the WIDTH, HEIGHT, and COUNTRY variables to match the country that you are training. The width and height should be proportional to the plate size (slightly larger is OK). A total pixel area of around 650 seems to work best. Also, adjust the path to your OpenCV libraries, if that needs to be changed.

Once you are ready to start training, enter the following commands:

  • rm ./out/* (clear the out folder in case it has data from previous runs)
  • ./prep.py neg
  • ./prep.py pos
  • ./prep.py train
  • Copy the output from the above command onto the command line. You should adjust the numStages to a smaller value (usually 12 stages works well, but it will depend on your input images). You may also need to adjust the numPos value to a smaller number in order to complete the training.

Copy the out/cascade.xml file to your OpenALPR runtime directory (runtime_data/region/[countrycode].xml). You should now be able to use the region for plate detection.

train-detector's People

Contributors

chriswiggins avatar jovargas avatar matthill avatar silex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

train-detector's Issues

Problem in stage-2

Hello,

I have been messing around with openalpr project for somedays now and been reading about it as much as i could however theres a problem which remains unanswered.

Im trying to train openalpr plate detector for certain angles, i gathered around 1000 plates as positive image changed the prep script regarding to my needs and executed the script, for some reason i ran into the problem which is written below :

TRAIN
Traceback (most recent call last):
  File "./prep.py", line 184, in <module>
    execStr = '%s/opencv_traincascade %s %s %s %s -numPos %d -numNeg %d -maxFalseAlarmRate 0.45 -featureType LBP -numStages 13' % (OPENCV_DIR, data_arg, vector_arg, bg_arg, width_height_arg, num_pos_samples, num_neg_samples )
NameError: name 'num_neg_samples' is not defined

somehow after executing /prep.py train command variable "num_neg_samples" can not be located in python, after a quick look i added
num_neg_samples = file_len(NEGATIVE_INFO_FILE)
below " num_pos_samples = file_len(POSITIVE_INFO_FILE)" to the line 173 this took care of my variable problem but after executing train command process stops in stage 2

===== TRAINING 2-stage =====
<BEGIN
POS count : consumed   1 : 1
Train dataset for temp stage can not be filled. Branch training terminated.

thanks in advance :)

crop_plates.py

hello, can you please send me an example on the arguments used on crop_plates.py for full function

thank you

.

.

Prep.py Issue at Training Stage 0

img_20190131_104446

Someone help me to fix this issue? I have a 4000 neg pictures and 1000 positives pictures. When I run that it gives me that error.

I don't know where I should fix this. Help me. TIA

out/cascade.xml file not generated

Hello,
I'm working on training Australian License plates.

I have used 180 Australian license plate positive image and made numStages to 12.
After finishing all the tutorial steps, I didn't find the .xml file "not generated"!!
Please, Can you help me?

Best Regards,
Karem Elzftawy

Dimensions of width and height for India

In the prep.py file for training for country, the dimensions of width and height are in which units, while using this command
python crop_plates.py --input_dir= --out_dir= --plate_width=190 --plate_height=46(mentioned in mm)

python script error

Hi,
I've several error running the the python prep.py script on windows 7 using python 2.7.9.
error 1, "from PIL import Image" => the module name incorrect.
changed it from "from pil import Image" to "import image", but still the module Image is unknown.

error 2 is related to directory paths.
original path in script was: "/home/mhill/projects/alpr/samples/training/"
I changed it to: "C:\trainer" and I get error when the script concatenates it in the following instruction:
INPUT_NEGATIVE_DIR = BASE_DIR + 'raw-neg/'
by giving this wrong result: "C:\trainerraw-neg/."
I changed it to: "C:\trainer" and the error is: syntax error: EOL while scanning string literal

seems like the script is written for unix-based system.
can anyone please help?

What should be inside raw-negative?

I found the images in raw-negative have nothing to do with the vehicle license plate. Should I just use it or have to create raw-negative images by myself? Thanks.

cascade.xml not working

i successfully generated the cascade.xml file , rename it to eu2 and placed it in proper folder but using python i am unable to load the eu2.xml file , while .xml files where are present by default are loaded successfully and are working correctly..
i am using windows and opencv3. while openALPR versions is 3.3.1

error: (-5:Bad argument) in function 'get'

I reduced the number of pos and neg images but still get this error.
Does anyone know the solution? I google it and most solutions suggest reduce neg and pos, but it didn't work.
1

Training steps

Here is the command line I used for training:

/usr/local/Cellar/opencv/3.4.1_5/bin/opencv_traincascade -data /Users/xxx/Desktop/new-ocr/out// -vec /Users/xxx/Desktop/new-ocr/positive/vecfile.vec -bg /Users/xxx/Desktop/new-ocr/negative/negative.txt -w 70 -h 39 -numPos 640 -numNeg 4705 -maxFalseAlarmRate 0.45 -featureType LBP -numStages 11

But the train stopped at Stage 7:

===== TRAINING 7-stage =====
<BEGIN
POS count : consumed   640 : 650
NEG count : acceptanceRatio    0 : 0
Required leaf false alarm rate achieved. Branch training terminated.

What could be the reason? Thanks.

prep.py python 3.X supports

Hello,

I'm facing a probem when using this training method :

exp of error : SyntaxError: Missing parentheses in call to 'print'. Did you mean print(execStr)?

My question is : the script isn't updated to work with Python 3.X ?

Thanks.

Best Regards,

train-detector (prep.py)

For adding new region(ua), i do:

  1. Collecting files with license plate and crop it (with image clipper).
  2. Place cropping files into /usr/local/src/train-detector/ua
  3. Doing positives:
    root@ubuntu:/usr/local/src/train-detector# ./prep.py pos
    Pos
    /usr/bin/opencv_createsamples -vec /usr/local/src/train-detector/positive/vecfile.vec -w 52 -h 13 -info /usr/local/src/train-detector/positive/positive.txt -num 20
    Info file name: /usr/local/src/train-detector/positive/positive.txt
    Img file name: (NULL)
    Vec file name: /usr/local/src/train-detector/positive/vecfile.vec
    BG file name: (NULL)
    Num: 20
    BG color: 0
    BG threshold: 80
    Invert: FALSE
    Max intensity deviation: 40
    Max x angle: 1.1
    Max y angle: 1.1
    Max z angle: 0.5
    Show samples: FALSE
    Width: 52
    Height: 13
    Create training samples from images collection...
    Done. Created 20 samples
  4. Doing negatives:
    output only -
    root@ubuntu:/usr/local/src/train-detector# ./prep.py neg
    Neg
  5. In this case the train fold down with error
    root@ubuntu:/usr/local/src/train-detector# ./prep.py train
    TRAIN
    Traceback (most recent call last):
    File "./prep.py", line 170, in
    num_neg_samples = file_len(NEGATIVE_INFO_FILE)
    File "./prep.py", line 54, in file_len
    return i + 1

Why negatives does not create.

Type plate

Hey folks,

please delete my message if this is the wrong place to ask a question. I am working or VELUX, a company that build roof windows. Since many decades our windows have a type plate (see attached picture). I would like to create an application that is able to read the data from the type plates. Is OpenALPR the right way to approach taht?

Cheers,
Klaus
velux_fenstertypen_2013

TRAINING 0-stage not moving forward

Hi, I'm using OSX 10.10.2 (brew)

The stages seems that are not moving forward
What is missing? Not error messages and the files already are in the respective folders

Here is what I did using the folder "eu" as input..

/usr/local/Cellar/opencv/2.4.11_1/bin/opencv_traincascade -data /train-detector/out/ -vec /train-detector/positive/vecfile.vec -bg /train-detector/negative/negative.txt -w 52 -h 13 -numPos 1347 -numNeg 3248 -featureType LBP -numStages 20
PARAMETERS:
cascadeDirName: /train-detector/out/
vecFileName: /train-detector/positive/vecfile.vec
bgFileName: /train-detector/negative/negative.txt
numPos: 1347
numNeg: 3248
numStages: 20
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 52
sampleHeight: 13
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 1347 : 1347
NEG count : acceptanceRatio 3248 : 1

Here is where not continues..

Value of Width and Height in Prep.py

In crop_plates.py I saw that the parameter for that was a pixels, how about the prep.py?

What was the exact value that asking for height and width in prep.py?
is that the char height and width of a plate number?

or the size of the full plate number?

Please anyone help me in this issue.

Confused

So i wanted to ask , after tagging the plates in the tagger tool , i got simple yaml file , like this :
image_file: 1.jpeg image_width: 640 image_height: 480 plate_corners_gt: 453 322 547 315 547 338 453 347 region_code_gt: mk plate_number_gt: SK2235AR plate_inverted_gt: false
Now how can i use this ? also when i try to run the crop plates script , it says 0 images found in the output folder , even if i add some images it still says 0 , what am i doing wrong ? can someone please walk me through ? or at least little more explanation
Thank you

Negative samples

what kind of images should be inside negative sample folder to rich higher accuracy?
should I put any image(whiteout license plate ) with any size inside that or it's better to resize them as same as my positive samples are?
what about the color? should I use grayscale images or RGB images give me higher accuracy?

Openalpr train

Traceback (most recent call last):
File "prep.py", line 77, in
for neg_file in os.listdir(INPUT_NEGATIVE_DIR):
OSError: [Errno 2] No such file or directory: '/home/mhill/projects/alpr/samples/training/raw-neg/'

POSKillednt samples: 18957 - And all stops

I have tried to train the detector with lots of images (jpeg). But I allways get:

===== TRAINING 0-stage =====
<BEGIN
POSKillednt samples: 18957

or

===== TRAINING 0-stage =====
<BEGIN
POS cKilled samples: 18919

Have I make something wrong? What can I do to get the .xml?

How does the train-detector work?

I run the following command, but nothing happened.

./prep.py neg

It only shows: Neg. Then nothing happened. May I know what should I include in raw-neg folder?

But when I run:

./prep.py pos

Pos
/usr/local/Cellar/opencv/3.4.1_5/bin/opencv_createsamples -vec /Users/xxx/Projects/ocr/train-detector/positive/vecfile.vec -w 70 -h 50 -info /Users/xxx/Projects/ocr/train-detector/positive/positive.txt -num 1
Info file name: /Users/xxx/Projects/ocr/train-detector/positive/positive.txt
Img file name: (NULL)
Vec file name: /Users/xxx/Projects/ocr/train-detector/positive/vecfile.vec
BG  file name: (NULL)
Num: 1
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 70
Height: 50
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
Done. Created 1 samples

Only 1 samples created. Is this correct?

Indian number plates are not recognized

when using OpenALPR Ionic with Cordoava plugin for some Indian Number Plates data unable to getting .how to achive this one .i am getting EU, US data geting but Indian Number plate unable getting .

opencv_traincascade "Can not get new positive sample" -> figure num samples automagically

Hello,

Based on a discussion on the forum, opencv_traincascade often fails because you have to guess the number of samples and pass numPos about 90% of the sample for it to work.

The error is pretty cryptic like "Can not get new positive sample. The most possible
reason is insufficient count of samples in given vec-file."

Here are links about how to tackle this:

http://stackoverflow.com/questions/10863560/haar-training-opencv-assertion-failed
http://code.opencv.org/issues/1834

Just creating this issue for others and maybe a PR will eventually come.

OpenAlpr Training indian number plates

Hi,
OS: windows 10
I am trying to train for Indian number plates, and I have some image in positive directory.
indian license plate standard is 500 * 120 mm, so I created a 500 * 120 mm image and in pixels it converts to 1417*340 px.

I run the 'prep.py neg' and it counts all files as it creates a negative.txt in negative directory and there are all negative files are listed.

I tried running 'prep.py pos' and there was 40 images in my folder 'in'(country code) and positive directory was empty before running the command and after executing the 'prep.py pos' command all files got copied from 'in' folder to 'positive' folder and output of the command is below.

C:\Users\LaserTrac\Downloads\alpr\train-detector-master>python prep.py pos
Pos
Exception reading image file: positive.txt
C:/Users/LaserTrac/Downloads/opencv1/opencv/build/x64/vc14/bin/opencv_createsamples -vec C:/Users/LaserTrac/Downloads/alpr/train-detector-master/positive/vecfile.vec -w 1417 -h 340 -info C:/Users/LaserTrac/Downloads/alpr/train-detector-master/positive/positive.txt -num 0
Info file name: C:/Users/LaserTrac/Downloads/alpr/train-detector-master/positive/positive.txt
Img file name: (NULL)
Vec file name: C:/Users/LaserTrac/Downloads/alpr/train-detector-master/positive/vecfile.vec
BG  file name: (NULL)
Num: 0
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 1417
Height: 340
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
Done. Created 0 samples

and positive.txt file was empty.
please help.

crop_plates.py problem

File "crop_plates.py", line 34
print "input_dir (%s) doesn't exist"
^
SyntaxError: invalid syntax

what to do if this happens?

WIDTH and HEIGHT in mm or px?

hi
I have a question.

WIDTH and HEIGHT is mm or px ?

for example :

WIDTH=52

HEIGHT=13

COUNTRY='eu'

but Real HEIGHT size is 11 mm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.