どこが間違っているのかよくわかりません-自分で撮った+/-画像を使用して、オブジェクト検出のためにOpenCVをトレーニングしようとしています。すべての手順は正常に機能しますが、最終的に Python スクリプトは XML カスケード ファイルを読み取れません (ただし、組み込みの顔検出ファイルの 1 つが読み込まれます)。
ちなみに、私は Mac Lion で Python 2.7.3 を実行しています。
私のプロセス:
- ポジティブ イメージのバウンディング ボックスを含むコレクション ファイルを作成します。
- ネガティブなイメージのリストを作成する
opencv_createsamples
次のコマンドを使用して使用します。opencv_createsamples -info collection.txt -bg negativeImages.txt -vec positiveVectorFile.vec -num 20 -w 32 -h 24
- ベクトル ファイルを確認してください: 画像は少しつぶれていますが、見た目は問題ありません
traincascade
次のコマンドを使用してプログラムを実行します。opencv_traincascade -data directoryToStoreFiles -vec positiveVectorFile.vec -bg negativeImageList.txt -numPos 16 -numNeg 20 -numStages 5 -mem 1000 -maxHitRate 0.95 -w 32 -h 24
次に、次の Python スクリプトを実行します (通常の顔検出 XML で動作します)。
import cv
img = cv.LoadImage("test.jpg", 0)
# load detection file (various files for different views and uses)
cascade = cv.Load("cascade.xml") # doesn't work
#cascade = cv.Load("frontalface.xml") # works
# detect faces, return as list
detected = cv.HaarDetectObjects(img, cascade, cv.CreateMemStorage())
# iterate detected objects, drawing a rectangle around each
for (x,y, w,h), n in detected:
cv.Rectangle(img, (x,y), (x+w, y+h), 255)
# create a window to display the results
windowTitle = "Test Cascade"
cv.NamedWindow(windowTitle, cv.CV_WINDOW_AUTOSIZE)
# display tested image until the escape key is pressed
while True:
cv.ShowImage(windowTitle, img)
# watch for escape key (ASCII 20)
key = cv.WaitKey(20)
if key == 27:
# save the image to file is specified
if saveIt == True:
cv.SaveImage("detected.png", img)
# ... and quit
exit()
結果はエラーです:
cv2.error: The node does not represent a user object (unknown type?)
ここにカスケード ファイルをアップロードしました: http://pastebin.com/w7uRjyN7。それが私のカスケードファイルなのか、途中で他の問題なのか、それとも明らかな何かなのかわかりませんか?