CascadeClassifier doesn't work with cascade.xml trained by myself. It always blocked when use method detectMultiScale()

asked 2019-06-05 00:43:06 -0600

zyuwang gravatar image

updated 2019-06-05 03:44:48 -0600

supra56 gravatar image

I have built opencv from source detached at 3.4.6. And then I use /path_opencv_built/bin/opencv_traincascade to train a cascadeclassifier.xml.

opencv_createsamples -info pos.txt -num 10000 -w 100 -h 100 -vec pos.vec

opencv_traincascade -data data -vec pos.vec -bg neg.txt -numPos 9000 -numNeg 100 -w 24 -h 24 -numStages 15

I thought it should be right because I have got reasonable output.

PARAMETERS:

cascadeDirName: data

vecFileName: pos.vec

bgFileName: neg.txt

numPos: 9000

numNeg: 100

numStages: 15

precalcValBufSize[Mb] : 1024

precalcIdxBufSize[Mb] : 1024

acceptanceRatioBreakValue : -1

stageType: BOOST

featureType: HAAR

sampleWidth: 24

sampleHeight: 24

boostType: GAB

minHitRate: 0.995

maxFalseAlarmRate: 0.5

weightTrimRate: 0.95

maxDepth: 1

maxWeakCount: 100

mode: BASIC

Number of unique features given windowSize [24,24] : 162336

===== TRAINING 0-stage =====

<begin< p="">

POS count : consumed 9000 : 9000

NEG count : acceptanceRatio 100 : 1

Precalculation time: 2

+----+---------+---------+

| N | HR | FA |

+----+---------+---------+

| 1| 0.998556| 0.76|

+----+---------+---------+

| 2| 0.998556| 0.76|

+----+---------+---------+

| 3| 0.999444| 0.77|

+----+---------+---------+

| 4| 0.999889| 0.8|

+----+---------+---------+

| 5| 1| 0.8|

+----+---------+---------+

| 6| 1| 0.8|

+----+---------+---------+

| 7| 0.999| 0.41|

+----+---------+---------+

END>

Training until now has taken 0 days 0 hours 12 minutes 4 seconds.

...

...

===== TRAINING 14-stage =====

<begin< p="">

POS count : consumed 9000 : 9394

NEG count : acceptanceRatio 100 : 0.0045939

Precalculation time: 2

+----+---------+---------+

| N | HR | FA |

+----+---------+---------+

| 1| 0.998111| 0.76|

+----+---------+---------+

| 2| 0.998111| 0.76|

+----+---------+---------+

| 3| 0.999333| 0.76|

+----+---------+---------+

| 4| 0.996111| 0.44|

+----+---------+---------+

END>

Training until now has taken 0 days 1 hours 41 minutes 42 seconds.

And I have got files. (cascade.xml params.xml stage0.xml stage1.xml stage10.xml stage11.xml stage12.xml stage13.xml stage14.xml stage2.xml stage3.xml stage4.xml stage5.xml stage6.xml stage7.xml stage8.xml stage9.xml)

But when I use the cascade.xml, I always blocked using the method detectMultiScale(), without any responses even ctrl+c didn't work.

BTW, it runs well when I use origin haarcascade_fullbody.xml. I just don't know where the problem is.

My code shows below.

import cv2

import time


model_haar = cv2.CascadeClassifier("cascade.xml")

cam = cv2.VideoCapture('video.mp4')

print("load success.")

while True:

    _, img = cam.read()

    gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    print("read image")

    t0 = time.time()

    result = model_haar.detectMultiScale(gray_img)

    print(time.time() - t0)

    for resule_x, result_y, result_w, result_h in result:

        cv2.rectangle(img, (resule_x, result_y), (resule_x + result_w, result_y + result_h), (255, 0, 255), 2)

    cv2.imshow('img', img)

    key = cv2.waitKey(30) & 0xff

    if key == ord('q'):

        break

cam.release()

cv2.destroyAllWindows()

it block at "result = model_haar.detectMultiScale(gray_img)", I telled that because it never reach "print(time.time() - t0)", and no any responses with ctrl+c.

Thanks for any advice~

edit retag flag offensive close merge delete

Comments

if necessary, here is the link of my cascade.xml file.

link text

zyuwang gravatar imagezyuwang ( 2019-06-05 03:01:01 -0600 )edit