2012-06-02 140 views
4

我正在嘗試使用3340正面圖像和1224負面圖像爲OpenCV中的行人訓練haar-like分類器。 (在一個.txt文件中,我保留了負片圖像名稱,即負片(1).bmp,並且在一個txt文件中我保留了正片,即圖片(1).bmp 1 0 0 64 128. 實際上,的行人,所以我只需要指定一個正面樣本每個圖像)。哈爾培訓OpenCV斷言失敗

在期間停止並說在訓練過程中的一些點:

"Opencv Error: Assertion failed (elements_read==1)in unknown function, file c:\path\cvhaartraining.cpp, line 1858"

任何想法是什麼原因造成的?

+0

您正在使用哪種版本的OpenCV?這可能是下面的斷言失敗:'assert(img-> rows * img-> cols ==((CvVecFile *)userdata) - > vecsize);' 這意味着行和列不對應的大小矢量。但我不知道是什麼原因造成的。 –

+0

嗨,我使用預裁剪圖像64X128的opencv 2.4。謝謝 – valentin

+0

你可以找出它是否只是一個特定的圖片,導致這一點,或者如果他們都沒有工作?如果它是一個特定的圖像,你可以看到hwat在這個圖像中是不同的。如果所有這些都不起作用,我們可以看看這些圖像本身。 –

回答

10

這個問題是由上OpenCV的DevZone網站的實用工具創世in June 2012.

回答引述瑪麗亞:

The problem is that your vec-file has exactly the same samples count that you passed in command line -numPos 979. Training application used all samples from the vec-file to train 0-stage and it can not get new positive samples for the next stage training because vec-file is over. The bug of traincascade is that it had assert() in such cases, but it has to throw an exception with error message for a user. It was fixed in r8913. -numPose is a samples count that is used to train each stage. Some already used samples can be filtered by each previous stage (ie recognized as background), but no more than (1 - minHitRate) * numPose on each stage. So vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. I hope it can help you to create vec-file of correct size and chose right numPos value.

它爲我工作。我也有同樣的問題,我是繼famous tutorial on HAAR training,但想嘗試與 -npos 7000 -nneg 2973

較新的訓練工具,所以我做了以下Calcs(計算):

VEC文件必須包含> =( numPos +(numStages-1)*(1 - minHitRate)* numPos)+ S

7000 >= (numPos + (20-1) * (1 - 0.999) * numPos) + 2973

(7000 - 2973)/(1 + 19*0.001) >= numPos

numPos <= 4027/1.019

numPos <= 3951 ~~ 3950

,並用於:

-npos 3950 -nneg 2973

它的工作原理。我還注意到其他人也在減少numPos方面取得了成功:here

+1

沒有其他人發現-numPos和-numPose是兩個不同的東西混淆?或者只是一個錯字?在這裏的文檔中不存在numPose:http://docs.opencv.org/doc/user_guide/ug_traincascade.html#cascade-training 我知道這是一個直接的qoute,但爲了清楚起見,它可能是很好的編輯它 – EdgeCaseBerg