【问题标题】:opencv createsamples has no error, but no samples foundopencv createsamples 没有错误,但是没有找到样本
【发布时间】:2014-04-25 14:28:44
【问题描述】:

我正在使用this 教程,并且我正处于从我的正面图像创建大量样本的阶段。我正在使用 Windows。

这是命令:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500\  "C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -maxxangle 1.1\   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

这就是我得到的每个正面图像的输出:

C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -max
xangle 1.1\   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img 60inclin
ation_315azimuth.jpg -bg tmp -vec samples0inclination_315azimuth.jpg.vec -num 62

Info file name: (NULL)
Img file name: 60inclination_315azimuth.jpg
Vec file name: samples0inclination_315azimuth.jpg.vec
BG  file name: tmp
Num: 62
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...
Done

消息似乎成功了,所以我进入示例文件夹,希望看到 1500 个示例,但那里什么也没有!我注意到信息文件是<NULL>,这和这个有什么关系吗?好像没有错误,到底哪里出错了?

编辑

我已更改命令以包含所有内容的绝对路径,例如

perl bin/createsamples.pl C:\my_work\code\opencv-haar-classifier-training-master\positive_images\ C:\my_work\code\opencv-haar-classifier-training-master\positive_images\ samples 1500\  "C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -maxxangle 1.1\   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

但还是没有运气!

【问题讨论】:

    标签: opencv image-processing computer-vision training-data sample-data


    【解决方案1】:

    我有一个类似的问题我会尝试解释我做了什么,希望它能解决你的问题。

    首先-info后面的NULL是正常的。正如 opencv_createcamples 的 OpenCV 官方文档中所说,您需要输入图像 (-img) 或图像集合 (-info) 我会让您阅读文档以进一步理解,但对于这个示例,您不需要需要它。

    其次,您不需要在此命令中放置绝对路径;这是我的命令:

    perl bin/createsamples.pl  positives.txt negatives.txt samples 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 -maxzangle 0.5 -maxidev 40 -w 42 -h 40"
    

    要做到这一点,请确保位于您下载的 gitHub 目录的根目录(bin 的父目录),确保您的 positives.txt 和底片。 txt 在这个目录下。同时将OpenCV目录中的opencv_createsamples.exe复制粘贴到这个目录中。

    这完成了我现在将解释主要问题:该项目一开始是为 Ubuntu 开发的,所以它很容易在 mac 上工作,但我认为你必须在 Windows 下。如果您还没有,请下载 Cygwin,因为它主要使用 Linux 命令。

    正如我所说,我遇到了类似的问题,所以我尝试直接使用 opencv_createsample 而不是 perl 脚本来查看问题是否来自那里,我注意到问题来自以下事实我的positives.txt 和negatives.txt 是Windows 格式而不是Unix,所以Perl 脚本无法正确读取它们

    windows 和 linux 之间的差异很大,Cygwin 并没有弥合差距,因此可能存在其他编码问题。所以我所做的肯定不是解决问题的最快方法,但它很容易。

    我刚刚在我的电脑上安装了一个 Ubuntu 虚拟机

    用TBB安装Opencv(网上很多教程,最好的是OpenCV site的那个)。

    我下载了 gitHub Classifier training,然后按照给出的命令,它运行良好。

    【讨论】:

    • 这对我有帮助,我已将 opencv 从源代码安装到一个文件夹中,需要将二进制文件复制到我的文件夹中并指定 ./opencv_createsamples 以使其运行。谢谢
    • 你刚刚拯救了我的一天。就像在父目录中复制粘贴 opencv_createcamples 一样简单
    【解决方案2】:

    另一个更简单的解释。假设您是 OpenCV 的新手(就像我一样),并且您只是按照其中一个教程视频来创建您的第一个对象检测器。您可能已经通过从网络上剪切粘贴创建了一个示例图像。示例图像必须是单色的,但不仅如此,它们还必须是单通道、8 位单色。如果您将样本 Photoshop 处理为显示单色,但没有更改其通道配置,那么如果它实际上有多个通道,opencv_createsamples 将忽略它。

    来源:~/apps/createsamples/utilities.cpp,函数 icvStartSampleDistortion()。

    【讨论】:

    • 我已经有了单通道图像。我真的不确定问题是什么。
    【解决方案3】:

    我在 Windows 中也遇到了类似的问题,但我的解决方案是检查 positives.txt 和negatives.txt 是否采用 createsamples.pl 文件可以理解的格式。我不确定这是否与您的问题相同,但我最终来到了这里,所以其他人也可能会这样做。

    我从与 createsamples.pl 相同的目录运行以下 python 脚本以形成文本文件,这似乎使 perl 文件对我有用:

    '''
    Run this from the folder containing the positive and negative samples' folders (Note: outputs the text files to this directory)
    '''
    import glob
    import sys
    
    def write_locations(folder, textFile):
        print('')
        file = open(textFile, 'w')
        for contents in glob.glob('{}/*'.format(folder)):
            try:
                fileName = contents.split("\\")[-1]
                file.write('\n./{0}/{1}'.format(folder, fileName))
                print('./{0}/{1}'.format(folder, fileName))
            except:
                pass
    
    write_locations('positive', 'positives.txt')
    write_locations('negative', 'negatives.txt')
    
    print('\n -Done.')

    我的文件夹的组织可能与教程略有不同(我只是为了 perl 文件而去那里),但我所做的只是检查文本文件的内容是否类似于:

    ./positive/1_1.png
    ./positive/1_2.png
    ./positive/1_3.png
    ./positive/1_4.png

    等等。

    【讨论】:

    • 这只是删除了整个positives.txt和negatives.txt
    【解决方案4】:

    我遇到了同样的问题。问题是我在文件名中有大写字母,但在终端代码中没有。

    【讨论】:

      【解决方案5】:

      我有一个类似的问题我会尝试解释我做了什么,我希望它能解决你的问题。

      首先,将文件命名为 positives.datnegatives.dat 而不是 positives.txtnegatives.txt

      其次,将positives.datnegatives.dat文件复制粘贴到当前目录下,然后运行:

      perl bin/createsamples.pl positives.dat negatives.dat samples 1000 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

      之后,检查您的示例文件夹,您应该会看到包含许多矢量文件的正负文件夹。

      【讨论】:

        【解决方案6】:

        这应该可行:

        perl bin/createsamples.pl positives.txt negatives.txt samples 3000 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 0  -maxyangle 0 maxzangle 0 -maxidev 40 -w 32 -h 32"
        

        【讨论】:

        • 这与问题中的命令有什么不同,这种差异如何改变事情?通过解释它们的工作原理和原因,几乎总是可以改进仅代码的答案。
        猜你喜欢
        • 2017-03-23
        • 1970-01-01
        • 2014-07-03
        • 1970-01-01
        • 1970-01-01
        • 2014-02-21
        • 1970-01-01
        • 2013-05-08
        • 1970-01-01
        相关资源
        最近更新 更多