1

我在我的OPENCV_ROOT文件夹中并在 Win-x64 中运行以下命令:

opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 
maxzangle 0.5 -maxidev 40 -w 80 -h 40 
-img ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg 
-bg ABSOLUTE_PATH_TO_PROJECT\negatives.txt
-vec ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec 
-num 125

我的negatives.txt样子是这样的:

negative_images\city01_02.jpg
negative_images\city01_04.jpg
negative_images\city01_05.jpg
negative_images\city01_06.jpg
negative_images\city01_07.jpg

这是我的输出:

Info file name: (NULL)
Img file name: ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg
Vec file name: ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec
BG  file name: ABSOLUTE_PATH_TO_PROJECT\negatives.txt
Num: 125
BG color: 0
BG threshold: 0
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: 80
Height: 40
Create training samples from single image applying distortions...
Invalid background description file.

我的底片收集文件 ( negatives.txt) 有什么无效的?我尝试使用绝对路径和相对路径列出其中的文件。我正在关注教程。

4

5 回答 5

5

如果您在 Windows 上创建文件,并在 Linux(例如 Ubuntu)上运行它,则必须更改“行尾顺序”。

在 CR LF 上点击编辑器底部,将其更改为LF再试一次!

记事本++:

记事本++图像:

视觉工作室代码:

Visual Studio 代码图像:

Geany:文档>设置行尾>转换并设置为LF(Unix)

吉尼形象

于 2018-08-28T08:55:07.217 回答
2

问题解决了!问题只是我在 Notepad++ 中编写了集合文件名,一切看起来都很好。但是当我碰巧在记事本中打开同一个文件时,我注意到每个图像文件名后面都没有换行符!当我添加换行符并运行命令时,创建的样本没有错误!

于 2014-04-05T14:25:58.340 回答
1

我有同样的问题。只需跳过图像地址之间的。例如:在我的negatives.dat文件之前是:

./Negative_Images/197.
./Negative_Images/69.
./Negative_Images/510.
./Negative_Images/513.
./Negative_Images/169.png

现在是:

./Negative_Images/197.png



./Negative_Images/69.png



./Negative_Images/510.png



./Negative_Images/513.png



./Negative_Images/169.png

问题解决了。

于 2014-10-09T18:22:22.710 回答
0

就我而言,我正在使用脚本创建此bg.txt文件。基本上,它在做:

for (int i = 0; i < numberOfImages; i++)
    {
                myDescFile << imagesFolder + std::to_string(i) + ".jpg\n";
    }

我只是添加了另一个\n,问题就消失了!

myDescFile << imagesFolder + std::to_string(i) + ".jpg\n\n";

编辑:

您还必须确保您的路径具有/\\作为分隔符。否则,您将能够运行opencv_createsamples.execmd,不会出现错误,但永远不会看到最后Done

前任:L:/imgTraining/plant/bnw/0.jpg

这是notepad++中一个好的bg文件的图片(View>Show Symbol>Show End of Line激活并Edit>EOL Conversion>Windows (CR LF)选中):

在此处输入图像描述

于 2018-08-07T14:43:44.403 回答
0

dos2unix在 Linux 上安装sudo apt-get install dos2unix. 现在你只需要使用dos2unix YourFileName.txt.

于 2020-11-30T23:05:30.543 回答