Ask Your Question
1

traincascade: object detection size.

asked 2015-03-26 08:17:21 -0600

tomnjerry gravatar image

updated 2015-03-26 08:17:49 -0600

I have trained a cascade using LBP to detect certain object. I have trained the cascade using 400 positive images of objects having same size (100 X 40).

To train cascade, I used following command : opencv_traincascade -data data -vec object.vec -bg bg.txt -numPos 400 -numNeg 500 -numStages 14 -w 50 -h 20 -featureType LBP -maxFalseAlarmRate 0.4 -minHitRate 0.99 -precalcValBufSize 2048 -precalcIdxBufSize 2048

Now when I use this cascade on test images, will it detect objects only if they are of the size for which they are trained for or they can detect bigger objects too ? I tried using images (500 X 500) with object being more than (100 X 40) and it cannot detect objects in them.

edit retag flag offensive close merge delete

Comments

verify that the xml file is loaded; verify that the test images really have the object; verify the positive images you trained on are containing just the object, and not too much background (I mean that the object you want to detect is not small in some corner, but is the main object in the image); but 400 positives in LPB are going to create a lot of false positives. Your cascade is returning just object of size you trained on and larger.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-03-26 10:03:50 -0600 )edit

With parameters -w 50 -h 20 you will be able to detect objects as small as those dimensions, finding larger object should work perfectly if you do not limit the scale ranges. Can you place your exact detection command? Smaller objects than 50x20 should not be detected however!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-03-27 04:58:07 -0600 )edit
2

That is your training command, I want to know with what parameters you are calling your detection function in detectMultiScale inside the C++ code. Your model is trained with the window size you specify, BUT at detection time a image pyramid is generated with a sliding window so that other sizes are detected also. To understand that, read the Viola and Jones paper!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-03-27 05:29:44 -0600 )edit

Detection command: object_detect.detectMultiScale(grayImage, object, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(5000 , 5000));

Also can cascade take care of differently oriented objects. For eg: Say I have 500 images of car of which some face towards right and other face towards left. If I train the cascade for this positive image dataset, will it be able to recognize car with either orientation ?

tomnjerry gravatar imagetomnjerry ( 2015-04-01 01:28:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
6

answered 2015-04-01 03:52:12 -0600

updated 2015-04-01 03:58:33 -0600

Okay here comes the bunch of problems

  1. You are using HAAR training specific flags, but you train with the traincascade app and with the LBP features. So start by removing the CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING it is simply redundant with your model. For explanation look at the docs, which clearly state it is not used anymore.
  2. You are mixing old C - API code with the C++ interface. Start by changing cvSize to Size functions.
  3. You are defining a scale range from 0,0 to 5000,5000 which is probably your image size. That is however not what the size factors are doing. They are there to define the borders of your image pyramid. Also your minimum size can never be smaller than the model size you trained on, the 0,0 dimensions are quite meaningless.
  4. A cascade classifier is NOT rotation invariant, so you train it with samples that are oriented all to a same normalized position. If you apply different rotations, than the descriptive power of your model will be reduced yielding more false positive detections and less true positive detections.

So I suggest changing your command to

object_detect.detectMultiScale(grayImage, object, 1.1, 10);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-26 08:17:21 -0600

Seen: 1,012 times

Last updated: Apr 01 '15