gpt4 book ai didi

c++ - OpenCV:如何创建 .vec 文件以与 opencv_traincascade 一起使用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:25:11 56 4
gpt4 key购买 nike

正如我在之前的帖子 here 中所解释的那样,我正在尝试生成一些 cascade.xml 文件来识别要在我的 iOS 应用程序中使用的欧元硬币。无论如何,我在理解如何生成 .vec 文件以作为 opencv_traincascade 的输入时遇到很多困难。这是因为我听到了很多不同意见:有人告诉我 vector 文件必须只包含正片图像,其中只包含要识别的对象;其他人(以及在我的教程中读到的)说 vector 文件必须包含“样本”图像,换句话说,随机背景,要识别的对象已通过 opencv_createsamples 添加。换句话说:

opencv_createsamples -img positives/1.png -bg negatives.txt -info 1.txt -num 210 -maxxangle 0.0 -maxyangle 0.0 -maxzangle 0.9 -bgcolor 255 -bgthresh 8 -w 48 -h 48

生成了 12000 张图像。最后,我创建了 .vec 文件:

cat *.txt > positives.txt

opencv_createsamples -info positives.txt -bg negatives.txt -vec 2.vec -num 12600 -w 48 -h 48

所以,我想问一下,下面两个 vector 文件中应该包含哪些正确的图像:

enter image description here

enter image description here

此外,启动训练的最终命令是什么?这是我到目前为止使用的那些:

opencv_traincascade -data final -vec 2.vec -bg negatives.txt -numPos 12000 -numNeg 3000 -numStages 20 -featureType HAAR -precalcValBufSize 2048 -precalcIdxBufSize 2048 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -w 48 -h -模式全部

其中 .vec 文件包含 12000 个样本图像(背景 + 要识别的硬币)。如果 .vec 文件仅包含正面图像(仅硬币),我该如何告诉 opencv_traincascade 使用样本图像进行训练?

我真的需要知道如何正确地做事,因为我已经启动了很多培训,但没有得到正确的结果,而且由于它们需要花费很多小时或几天才能执行,我不能再浪费时间了。

感谢大家的关注。

更新我设法用 LBP 创建了一个 cascade.xml 文件。如果我将用作训练样本的图像之一提供给一个简单的 OpenCV 程序,看看会发生什么:

enter image description here

同时使用如下图像:

enter image description here

它根本不起作用。我真的不知道我在哪里犯了错误。

更新也许首先将正图像转换为灰度图像会有所帮助? enter image description here

最佳答案

我使用了 INRIA 训练的负样本数据库http://pascal.inrialpes.fr/data/human/

和此输入(硬币周围具有 alpha 透明度的 png):

enter image description here

将其与此命令一起使用:

opencv_createsamples -img pos_color.png -num 10 -bg neg.txt -info test.dat -maxxangle 0.6 -maxyangle 0 -maxzangle 0.3 -maxidev 100
-bgcolor 0 -bgthresh 0

产生这样的输出:

enter image description here

enter image description here

所以背景颜色显然不起作用。然而,一开始转换为灰度给了我这个输入:

enter image description here

同样的命令会产生这样的输出:

enter image description here

enter image description here

enter image description here

enter image description here

我知道这不能回答您所有的问题,但也许它仍然有帮助。

关于c++ - OpenCV:如何创建 .vec 文件以与 opencv_traincascade 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35125138/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com