简体   繁体   中英

haar-cascade nothing come up with xml file

I am student and I am trying to create my first own haar-cascade(for learn) with a basic hand recognition. I collected 510 positives samples and 1276 negatives samples. Everything is ok with my training (I guess, I let you see the terminal window for that).

The only thing is when I am using my xml file with a basic script (you see that after it) nothing come up. I launch it with my terminal and I have no error. I have camera dropped few time after it!(but it's slower) but no window appears. If I am using an other xml file from web, it works... I don't no why...

Someone can help me?

Python 3.5 and opencv 3.2

 Charless-MacBook-Pro:desktop charles$ opencv_traincascade -data data -vec Positive_image.vec -bg Negative_image.text -numPos 449 -numNeg 1276 -numStages 10 -w 50 -h 50 -featureType LBP
    PARAMETERS:
    cascadeDirName: data
    vecFileName: Positive_image.vec
    bgFileName: Negative_image.text
    numPos: 449
    numNeg: 1276
    numStages: 10
    precalcValBufSize[Mb] : 1024
    precalcIdxBufSize[Mb] : 1024
    acceptanceRatioBreakValue : -1
    stageType: BOOST
    featureType: LBP
    sampleWidth: 50
    sampleHeight: 50
    boostType: GAB
    minHitRate: 0.995
    maxFalseAlarmRate: 0.5
    weightTrimRate: 0.95
    maxDepth: 1
    maxWeakCount: 100

    ===== TRAINING 0-stage =====
    <BEGIN
    POS count : consumed   449 : 449
    NEG count : acceptanceRatio    1276 : 1
    Precalculation time: 18
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        1|
    +----+---------+---------+
    |   2|        1|        1|
    +----+---------+---------+
    |   3|        1| 0.402821|
    +----+---------+---------+
    END>
    Training until now has taken 0 days 0 hours 1 minutes 31 seconds.

    ===== TRAINING 1-stage =====
    <BEGIN
    POS count : consumed   449 : 449
    NEG count : acceptanceRatio    1276 : 0.403542
    Precalculation time: 19
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        1|
    +----+---------+---------+
    |   2|        1|        1|
    +----+---------+---------+
    |   3| 0.995546| 0.300157|
    +----+---------+---------+
    END>
    Training until now has taken 0 days 0 hours 3 minutes 14 seconds.

    ===== TRAINING 2-stage =====
    <BEGIN
    POS count : consumed   449 : 451
    NEG count : acceptanceRatio    1276 : 0.121674
    Precalculation time: 19
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        1|
    +----+---------+---------+
    |   2|        1|        1|
    +----+---------+---------+
    |   3|        1| 0.413009|
    +----+---------+---------+
    END>
    Training until now has taken 0 days 0 hours 4 minutes 59 seconds.

    ===== TRAINING 3-stage =====
    <BEGIN
    POS count : consumed   449 : 451
    NEG count : acceptanceRatio    1276 : 0.0501789
    Precalculation time: 20
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        1|
    +----+---------+---------+
    |   2|        1|        1|
    +----+---------+---------+
    |   3|        1|0.0783699|
    +----+---------+---------+
    END>
    Training until now has taken 0 days 0 hours 6 minutes 46 seconds.

    ===== TRAINING 4-stage =====
    <BEGIN
    POS count : consumed   449 : 451
    NEG count : acceptanceRatio    1276 : 0.00391926
    Precalculation time: 20
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        0|
    +----+---------+---------+
    END>
    Training until now has taken 0 days 0 hours 8 minutes 44 seconds.

    ===== TRAINING 5-stage =====
    <BEGIN
    POS count : consumed   449 : 451
    Train dataset for temp stage can not be filled. Branch training terminated.

Here is my basic script with python:

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('/Users/charles/Desktop/closedFist.xml')

cap = cv2.VideoCapture(0)

while 1:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = img[y:y+h, x:x+w]

    cv2.imshow('img',img)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

EDIT :

It works. I have collected 2100 positives samples and 4500 negatives samples. 25 stages for my xml file. My mistake was to have negatives and positives samples with the same resolution : 50x50 px. Now negative samples are in 16:9 ratio. 160x90px. and it works!!!

I have some experience with making a HAAR cascade classifier. In your training phase, the terminal dump you've provided has TRAINING 5-stage terminated . So the training phase has been aborted.(You have specified 10 stages of training in your code, but the 5th one has failed and aborted the whole training process...)

I would suspect that you need more positive samples for object identification. There are way too many negative files. I used a 2:1 ratio of positive to negative samples. Experiment with different ratios, but preferably have more positive samples. (Also depends on your vector file creation options!)

If you can describe how you created the vector files and started the train command, the SO community can help you out better. :)


EDIT:

I just found out that the "error" message stating " Train dataset for temp stage can not be filled. Branch training terminated " means that the algorithm has reached a logical ending. It means that the classification model cannot be made any better with the given image dataset. So use stage=5 as stage=6 leads to this problem... Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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