简体   繁体   English

OpenCV:训练级联分类器

[英]OpenCV: training a cascade classifier

I am trying to train a cascade classifier using OpenCV, a tutorial & UIUC Image Database for Car Detection .我正在尝试使用 OpenCV,一个用于汽车检测的教程UIUC 图像数据库来训练级联分类器。 However, the training 'hangs' at stage 0 and never generates any files;但是,训练在第 0 阶段“挂起”并且从不生成任何文件; in the tutorial, results are seen in a matter of minutes.在本教程中,几分钟内即可看到结果。

I am running OpenCV 2.4.8, which I have installed using conda, on a 2015 MBP running Yosemite (10.10.5)我正在运行使用 conda 安装的 OpenCV 2.4.8,在运行 Yosemite (10.10.5) 的 2015 MBP 上

Steps:脚步:

  1. Downloaded the dataset & saved the positive images in a pos folder and the negative images in a neg folder下载数据集并将正图像保存在 pos 文件夹中,将负图像保存在 neg 文件夹中
  2. generated a txt file for the positive images为正图像生成了一个txt文件

    find pos -iname "*.pgm" > cars.txt sed -i '' 's/.pgm/.pgm 1 0 0 100 40/g' cars.txt
  3. generated a txt file for the negative images为负片生成了一个 txt 文件

    find neg -iname "*.pgm" > bg.txt
  4. generated a vec file from cars.txt从cars.txt生成了一个vec文件

    opencv_createsamples -info cars.txt -num 550 -w 48 -h 24 -vec cars.vec
  5. create a data dir创建data目录

    mkdir data
  6. train cascade火车级联

    opencv_traincascade -data data -vec cars.vec -bg bg.txt -numPos 500 -numNeg 500 -numStages 2 -w 48 -h 24 -featureType LBP

Output:输出:

PARAMETERS:
cascadeDirName: data
vecFileName: cars.vec
bgFileName: bg.txt
numPos: 500
numNeg: 500
numStages: 2
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 48
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   500 : 500
NEG count : acceptanceRatio    500 : 1

I have waited for several hours but the training never progresses nor does it generate any files in my data directory.我已经等了几个小时,但培训从未进行过,也没有在我的data目录中生成任何文件。 What is causing the 'hanging'?是什么导致“挂”?

For what it's worth, I ran into the same symptom and it was driving me crazy.无论如何,我遇到了同样的症状,这让我发疯了。 Uninstalling and reinstalling opencv fixed it .卸载并重新安装 opencv 修复了它 The exact command that was hanging suddenly worked fine.挂起的确切命令突然工作正常。 It could be you have an old version of opencv lingering somewhere like I had:可能是你有一个旧版本的 opencv 像我一样在某处徘徊:

$ brew uninstall opencv
Uninstalling /usr/local/Cellar/opencv/2.4.12... (225 files, 36M)
opencv 2.4.11_1 is still installed.
Remove them all with `brew uninstall --force opencv`.

$ brew uninstall --force opencv
Uninstalling opencv... (222 files, 35M)

$ brew install opencv --with-tbb

At any rate, something to consider.无论如何,需要考虑的事情。

I run into the same problem.我遇到了同样的问题。 It turns out using haar cascade training works just fine.事实证明,使用 haar 级联训练效果很好。 You could specific more stages for it to improve accuracy.您可以为其指定更多阶段以提高准确性。

I just don't see how you expect to get anything good out of two training stages.我只是不明白你如何期望从两个训练阶段中获得任何好处。 You should train until your -acceptanceRatioBreakValue reaches 10e-5.您应该训练直到您的-acceptanceRatioBreakValue达到 10e-5。 You've ordered 10 burgers from OpenCV but left after only getting 2.你已经从 OpenCV 订购了 10 个汉堡,但只得到了 2 个就离开了。

See here: http://docs.opencv.org/3.1.0/dc/d88/tutorial_traincascade.html#gsc.tab=0见这里: http : //docs.opencv.org/3.1.0/dc/d88/tutorial_traincascade.html#gsc.tab=0

使用 --use-tbb (来自自制软件)编译 OpenCV 为我解决了这个问题,我相信这是 OS X 上 GCD 实现的一个错误,如下所述: https : //github.com/opencv/opencv/issues/4765

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM