OpenCV:如何创建.vec文件以使用opencv_traincascade [英] OpenCV: how to create .vec file to use with opencv_traincascade
问题描述
正如我在上一篇文章中所述
此外,这是最终命令,以启动训练?这是我已经使用到现在:
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 48 -mode ALL
其中.vec文件包含12000个样本图像(背景+硬币识别)。
如果.vec文件只包含正图像(只有硬币),我应该如何告诉 opencv_traincascade
使用示例图像训练?
我真的需要知道如何做正确的事情,因为我已经发起了许多培训,然后导致没有正确的结果,并且由于他们需要许多小时或几天执行,我不能再浪费时间了。
感谢大家的注意。
UPDATE
管理使用LBP创建一个 cascade.xml
文件。看看如果我把一个图像作为训练样本给一个简单的OpenCV程序,会发生什么:
,同时显示以下图片:
它根本不工作。我真的不知道我在哪里犯错误。
UPDATE
也许首先将正图像转换为灰度可能有帮助吗?
OpenCV级联(HAAR,LBP)具有永久特征的对象。作为示例,所有面部在相同的地方具有鼻子,眼睛和嘴。 OpenCV级联被训练以在所需的对象类中搜索共同特征,并忽略从对象到对象改变的特征。问题的结论是,级联使用搜索窗口的矩形形状,但硬币具有圆形。因此,硬币的图像总是具有背景的一部分。
所以训练图像的硬币必须包括所有可能的背景,以便分类器可以忽略它们(否则它将被检测硬币只在特定的背景)。
所有训练样本必须具有相同的图像比例,大小和位置的硬币(方形图像与硬币在中心,硬币直径= 0.8-0.9图像宽度) ,和不同的背景!
As I explained in my previous post here, I am trying to generate some cascade.xml
files to recognize euro coins to be used in my iOS app. Anyway, I am founding many difficulties in understanding how to generate a .vec file to give as input to opencv_traincascade
. This because I heard many dissenting views: someone told me that vector file must include only positive images containing only the object to recognize; someone else instead (and also as read in my tutorials) said that vector file must include "samples" images, in other words random backgrounds to which the object to recognize has been added by opencv_createsamples
. In oter words with:
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
which generated 12000 images. Finally, I have created the .vec file with:
cat *.txt > positives.txt
opencv_createsamples -info positives.txt -bg negatives.txt -vec 2.vec -num 12600 -w 48 -h 48
So, I would like to ask you which the correct images to be contained in vector files from the following two:
Moreover, which is the final command to give to launch the training? This is the ones I have used up to now:
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 48 -mode ALL
where the .vec files contains 12000 samples images (background + coin to recognize).
Should the .vec file contain only positive images (only coins), how shall I tell opencv_traincascade
to train using the samples images?
I really need to know how to do things correctly because I have launched many training which then lead to no correct result and since they take many hours or days to execute, I can't waste time anymore.
Thank to all for your attention.
UPDATE
I managed to create a cascade.xml
file with LBP. See what happens if I give one of the image used as training samples to a simple OpenCV program:
while with an image like the following:
it does not work at all. I really don't know where I am making the mistake.
UPDATE Maybe firstly converting positive images to gray scale could help?
OpenCV cascades (HAAR, LBP) can excellently detect objects which have permanent features. As example all faces have nose, eyes and mouth at the same places. OpenCV cascades are trained to search common features in required class of object and ignore features which changes from object to object. The problem is conclude that the cascade uses rectangular shape of search window, but a coin has round shape. Therefore an image of the coin always will be have part of background. So training images of the coin must includes all possible backgrounds in order to classifiers can ignore them (otherwise it will be detect coin only on the specific background).
So all training samples must have the same image ratio, size and position of the coin (square images with coin in center, diameter of coin = 0.8-0.9 image width), and different background!
这篇关于OpenCV:如何创建.vec文件以使用opencv_traincascade的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!