opencv级联分类器未检测到开放式手掌 [英] opencv cascade classifier no open palm detected

查看:201
本文介绍了opencv级联分类器未检测到开放式手掌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以检测img.jpg中的开放手掌:

#!/ usr / bin / env python
# - * - 编码:utf-8 - * -
import cv2
import glob


#somehow如果路径没有以\ n结尾它会引发另一个错误
classifier = cv2.CascadeClassifier(path / to / classifier.xml \ n)
r = classifier.detectMultiScale(cv2.cvtColor(img,cv2.CV_8U))
print r
cv2.rectangle(img,r [0],r [1],(0,0,255))
cv2.imshow(result,img)
cv2.waitKey(1000)
classifier.xml是由类似于

i =path / to / positives / images的脚本生成的。
cd $ i
#list of positive images
找到。 -name'*' - exec identify -format'%i 1 0 0%w%h'\ {\} \; > ls.txt
opencv_createsamples -vec $(pwd)/coll.vec -info ls.txt \
-bg negatives / ls.txt -w 24 -h 24 -num 1550
mkdir path / to / classifiers#我们放置分类器的目录

opencv_traincascade -data path / to / classifiers\
-bg negatives / ls.txt -vec coll.vec - featureType LBP \
-w 24 -h 24 -numPos 1300 -minHitRate 0.99 \
-precalcValBufSize 4096 -precalcIdxBufSize 4096
但是当我执行python脚本时它给了我以下输出

()
回溯(最近一次调用最后一次):
文件test1.py,第13行,< module>
cv2.rectangle(img,r [0],r [1],(0,0,255))
IndexError:元组索引超出范围
如何以及在哪里做错了?

解决方案

i
#list的正面图像
find。 -name'*' - exec identify -format'%i 1 0 0%w%h'\ {\} \; > ls.txt
opencv_createsamples -vec


(pwd)/coll.vec -info ls.txt \
-bg negatives / ls.txt -w 24 -h 24 -num 1550
mkdir路径/到/分类器#我们放置分类器的目录

opencv_traincascade -data path / to / classifiers\
-bg negatives /ls.txt-vec coll.vec -featureType LBP \
-w 24 -h 24 -numPos 1300 -minHitRate 0.99 \
-precalcValBufSize 4096 -precalcIdxBufSize 4096
但是当我执行时它为我提供了以下输出的python脚本

()
Traceback(最近一次调用最后一次):
文件test1.py,第13行,在< module>中
cv2.rectangle(img,r [0],r [1],(0,0,255))
IndexError:元组索引超出范围
如何以及在哪里做错了?


I have the following code which should detect a open palm in img.jpg:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import cv2
    import glob
    

    #somehow if the path doesn't end in \n it will raise another error
    classifier=cv2.CascadeClassifier("path/to/classifier.xml\n")
    r=classifier.detectMultiScale(cv2.cvtColor(img,cv2.CV_8U))
    print r
    cv2.rectangle(img,r[0],r[1],(0,0,255))
    cv2.imshow("result",img)
    cv2.waitKey(1000)
classifier.xml is generated by a script similar to

    i="path/to/positives/images"
    cd $i
    #list of the positive images
    find . -name '*' -exec identify -format '%i 1 0 0 %w %h' \{\} \; >ls.txt
    opencv_createsamples -vec $(pwd)/coll.vec -info ls.txt \
        -bg negatives/ls.txt -w 24 -h 24 -num 1550
    mkdir path/to/classifiers #the directory where we put the classifiers

    opencv_traincascade -data path/to/classifiers\
        -bg negatives/ls.txt -vec coll.vec -featureType LBP \
        -w 24 -h 24 -numPos 1300 -minHitRate 0.99 \
        -precalcValBufSize 4096 -precalcIdxBufSize 4096
But when I execute the python script it gives me the following output
 
    ()
    Traceback (most recent call last):
      File "test1.py", line 13, in <module>
        cv2.rectangle(img,r[0],r[1],(0,0,255))
    IndexError: tuple index out of range
How and where did I do wrong?

解决方案

i #list of the positive images find . -name '*' -exec identify -format '%i 1 0 0 %w %h' \{\} \; >ls.txt opencv_createsamples -vec


(pwd)/coll.vec -info ls.txt \ -bg negatives/ls.txt -w 24 -h 24 -num 1550 mkdir path/to/classifiers #the directory where we put the classifiers opencv_traincascade -data path/to/classifiers\ -bg negatives/ls.txt -vec coll.vec -featureType LBP \ -w 24 -h 24 -numPos 1300 -minHitRate 0.99 \ -precalcValBufSize 4096 -precalcIdxBufSize 4096 But when I execute the python script it gives me the following output () Traceback (most recent call last): File "test1.py", line 13, in <module> cv2.rectangle(img,r[0],r[1],(0,0,255)) IndexError: tuple index out of range How and where did I do wrong?


这篇关于opencv级联分类器未检测到开放式手掌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆