开发者

Haar create sample parse error

I am creating samples in opencv 2.1 by "opencv_createsamples.exe", but I've got parse error on line 1.

File positives.txt contains:

c:\haar\Positives\PosImg_0.jpg 1 175,120,275,240
c:\haar\Positives\PosImg_1.jpg 1 175,120,275,240
c:\haar\Positives\PosImg_10.jpg 1 175,120,275,240
...(--and so on )

and what I did in cmd is:

c:\Haar>C:\OpenCV2.1\bin\opencv_createsamples.exe  -info positives.txt -vec Posi
tivesMany.vec -num 15 -w 24 -h 24 PAUSE
Info file name: positives.txt
Img file name: (NULL)
Vec file name: PositivesMany.vec
BG  file name: (NULL)
Num: 15
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: 24
Height: 24
Create training samples from images开发者_如何学Python collection...
positives.txt(1) : parse errorDone. Created 0 samples

All of the info files paths are correct.


I had the same problem, and in my case i solved it by passing to opencv_createsamples the -num parameter with exactly the total number of image samples described in the description file. I guess a minor number passed would work too.

Note that omitting the -num parameter gives parse error too, even though it's clearly a redundant parameter when you want to process exactly all the samples described.


You need to remove the comma in your positives.txt file.

Like this:

c:\haar\Positives\PosImg_0.jpg 1 175 120 275 240
c:\haar\Positives\PosImg_1.jpg 1 175 120 275 240
c:\haar\Positives\PosImg_10.jpg 1 175 120 275 240
...(--and so on )

Also, it seems strange that all of your picture have the object at the exact same place...


I had the same problem and I found the solution on this training page


I had the same error message, but in my case it was caused by wrong number of object instances in it.


I have a problem with annotation file content. opencv_createsamles has broken without pointing a line number where it happened in the annotation file. It has been tediously and boring to search the needed line.

I had this error message:

Create training samples from images collection... OpenCV Error: Assertion failed (rect.width >= 0 && rect.height >= 0 && rect.x < image->width && rect.y < image->height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0)) in cvSetImageROI, file /home/kostya/work/opencv/opencv-2.4.13.6/modules/core/src/array.cpp, line 3006
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/kostya/work/opencv/opencv-2.4.13.6/modules/core/src/array.cpp:3006: error: (-215) rect.width >= 0 && rect.height >= 0 && rect.x < image->width && rect.y < image->height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0) in function cvSetImageROI

I have created simple perl-script for pointing to a bad line in the file. When the bad line was found then I have decided to check the image file content and coordinates. So happened, it was found that some points coordinates were outside the image size. How it happened, I don't know. I have used opencv_annotation for creating this annotation file. The code of my script is below:

#!/usr/bin/perl
use strict;
use warnings;

my $TARGET_FILE = 'annotations.txt';
my $MIN_W = 70;
my $MIN_H = 14;

main();

sub main
{
    open F, $TARGET_FILE;

    my $cur_line = 1;
    while (my $inp_str = <F>)
    {
        print "line: $cur_line\n";

        if ($inp_str =~ m/0 0 0 0/)
        {
            print "Bad coordinates! Line: $cur_line\n";
            close F;
            die;
        }

        open W, '>temp_annotations.txt';
        print W $inp_str;
        close W;

        my $res = `opencv_createsamples -info temp_annotations.txt -bg negatives_cam.txt -vec temp.vec -w $MIN_W -h $MIN_H -num 1 2>&1`;

        if ($res =~ m/Error/)
        {
            print "Broken line: $cur_line\n";
            print "Original error message: \n\n $res\n\n";
            close F;
            die;
        }
        $cur_line++;
    }
    close F;
    print "File is correct\n";
}


Hariseldon78's workaround worked for me.

To be perfectly clear (as I misunderstood first), the number to provide (in the --num parameter) is not the number of line, but the total number of samples.

In my case the error message is even displaying the required number.

> opencv_createsamples.exe -vec result.vec -info info.txt  
Info file name: info.txt
Img file name: (NULL)
Vec file name: result.vec
...
Create training samples from images collection...
info.txt(335) : parse errorDone. Created 460 samples

in the last line, the 460 is the number of samples (and 335 is the number of lines in my file). So giving 460 to the application as number of samples to treat is enough to avoid the error message.

> opencv_createsamples.exe -vec result.vec -info info.txt -num 460
Info file name: info.txt
Img file name: (NULL)
Vec file name: result.vec
...
Create training samples from images collection...
info.txt(335) : parse error
Done. Created 460 samples

Additionally : I'm not sure if the error message is significant or not, what I can say is that the .vec files produced by the 2 previous commands differs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜