Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Haar创建示例分析错误_C++_Xml_Opencv_Classification - Fatal编程技术网

C++ Haar创建示例分析错误

C++ Haar创建示例分析错误,c++,xml,opencv,classification,C++,Xml,Opencv,Classification,我正在opencv_createsamples.exe的opencv 2.1中创建示例,但第1行出现了解析错误 文件positives.txt包含: 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 ) 我在cmd中所做

我正在opencv_createsamples.exe的opencv 2.1中创建示例,但第1行出现了解析错误

文件positives.txt包含:

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 )
我在cmd中所做的是:

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 collection...
positives.txt(1) : parse errorDone. Created 0 samples

所有信息文件路径都正确。

我遇到了相同的问题,我在

上找到了解决方案。您需要删除positives.txt文件中的逗号

像这样:

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 )

另外,看起来很奇怪,所有图片的对象都位于完全相同的位置…

我也遇到了同样的问题,在我的例子中,我通过将-num参数传递给opencv_createsamples解决了这个问题,该参数与描述文件中描述的图像样本总数完全相同。我想通过一个小数字也行


请注意,省略-num参数也会导致解析错误,即使当您想要精确处理所描述的所有示例时,它显然是一个冗余参数

我收到了相同的错误消息,但在我的例子中,它是由其中的对象实例数量错误引起的。

我对注释文件内容有问题。 opencv_createsamles已断开,但未指向批注文件中发生的行号。 搜索所需的线路既单调又乏味

我收到了以下错误消息:

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
我创建了简单的perl脚本,用于指向文件中的错误行。 当坏线被发现,然后我决定检查图像文件的内容和坐标。 结果发现,有些点的坐标超出了图像的大小。我不知道这是怎么发生的。 我已经使用opencv_注释创建了这个注释文件。 我的脚本代码如下:

#!/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的变通方法对我很有效

正如我首先误解的那样,非常清楚,-num参数中提供的数字不是行数,而是样本总数

在我的例子中,错误消息甚至显示了所需的号码

> 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
在最后一行中,460是样本数,335是我文件中的行数。 因此,向应用程序提供460作为要处理的样本数就足以避免错误消息

> 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
另外:我不确定错误消息是否重要,我能说的是,前面两个命令生成的.vec文件不同