Ask Your Question
0

haar createsamples error

asked 2017-08-30 07:27:40 -0600

jgc gravatar image

Hello.

I'm trying to create positive samples with the opencv_createsamples tool but i'm having some problems:

I want to detect this images image description

As I found, I can create positive samples using the createsamples tool with other background images.

_Folder structure:_

 Parent folder    (wehere I'm running the instruction)
│
 ───  haar
│   └─── neg
│       │   bg.txt   (with path of the bg images)
│   └─── train
│   └─── pos
│        └─── images
│
└─── images     (images to detect)
    │   image1.jpg

Instruction i'm running:

opencv_createsamples -img images/image1.jpg -bg haar/neg/bg.txt -info haar/pos/info.dat -bgthresh 0 -maxxangle 0.3 -maxyangle 0.3 -maxzangle 0.3 -num 50 -w 150 -h 15

The problems are:

1 - Sometimes i get an error during the execution:

OpenCV Error: Incorrect size of input array () in cvGetSubRect, file /home/jorge/dev/fingerP/opencv-3.2.0/modules/core/src/array.cpp, line 1275
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/jorge/dev/fingerP/opencv-3.2.0/modules/core/src/array.cpp:1275: error: (-201)  in function cvGetSubRect

2 - in other ocasions the execution finishes but neither images nor data into the _info.dat_ file has been created

3- When images are created (in the case 1 of these problems) the image looks like this:

image description

with the positive image on it but cropped.

Can anyone help me?

Thanks!

edit retag flag offensive close merge delete

Comments

are there different numbers in the images, you want to detect later ?

it somehow seems, your whole approach won't work at all.

chances of detecting a string of numbers/letters with a haar cascade like this are utterly low, worse even, if you use a single image for training.

berak gravatar imageberak ( 2017-08-30 19:54:19 -0600 )edit

Yes, there are different numbers but the idea is not to catch the numbers (at least at this step) but detect the box which contains this numbers.

I know that if I train the haar cascade with only this image it will try to detect only this box with this string. The idea is to use so many cases (many boxes with other strings) to try to detect boxes with numbers (if the positives has many different numbers, when the haar algorithm extract characteristics this will be generic for the numbers)

This single image is because with only one image i can show you the problems with the procedure to create samples (error during the process and image crop in the created positive images)

Do you think other approach to detect the box? Do you have any idea why this errors?

jgc gravatar imagejgc ( 2017-08-31 01:35:31 -0600 )edit

no idea, why it's crashing, but again, synthesizing many positives from a single image won't get you anywhere here, you either need ~1000 REAL positive images, or change the plan, and look for an alternative technique (swt,mser,there's a text-detection module in opencv-contrib)

berak gravatar imageberak ( 2017-08-31 01:43:45 -0600 )edit

Thanks, I'll try another approach but I don't know how to solve the crashes neither the image crop. No ideas?

jgc gravatar imagejgc ( 2017-08-31 03:32:30 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2017-11-23 09:26:48 -0600

Hugo_F gravatar image

Hello,

I had the same issue and found a solution.

The problem occurs when the image you're trying to create positive samples for is not a square.

Wrap your image into a black square and make the black color transparent when using opencv_createsamples (put parameter -bgcolor to 0). Also if you specify width and height parameters make sure they are the same to fit your squared image.

Fixed it for me, I guess the rotations applied by opencv_createsamples turns a square containing your object into a square containing your object but doesn't turn a rectangle containing your object into another rectangle containing your object.

Hope this helps :-)

Hugo

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-08-30 07:27:40 -0600

Seen: 777 times

Last updated: Aug 30 '17