OpenCV Python detectMultiscale

时间:2014-05-17 10:47:25

标签: python c++ opencv

大家好,你能给我一些关于OpenCV的建议吗? 当我想打印出 r 来查看rejectLevels时,它只打印出空数组。

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys, logging, time
import numpy as np
import cv2
import cv2.cv as cv


face_cacade = '../home/haarcascade_frontalface_default.xml'

xml = cv2.CascadeClassifier(face_cascade)

array_of_images = [] --> Some images

for image in array_of_images:              

        img   = cv2.imread(image)

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

        gray  = cv2.equalizeHist(gray)

        **r**  =  []
        x  =  []

        #cv2.CascadeClassifier.detectMultiScale(image, rejectLevels, levelWeights[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize[, outputRejectLevels]]]]]]) → objects
        faces = xml.detectMultiScale(image = img, rejectLevels = **r**, levelWeights = x ,scaleFactor=1.05, minNeighbors=1, minSize=(30, 30), flags = cv.CV_HAAR_SCALE_IMAGE)


        file_out  = open('/tmp/faces_score.txt','w+',0)

        for (x,y,w,h) in faces: 

        cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),1)

        roi_gray  = gray[y:y+h, x:x+w]

        roi_color = img[y:y+h, x:x+w]

        print **r**, x

你能给我一些关于Opencv detectMultiScale的解决方案或经验,我查看了c ++代码源,它看起来很好,但在Python中它不会像它应该的那样工作。 OpenCV版本:2.4.8 Python版本:2.7.6

1 个答案:

答案 0 :(得分:0)

我不确定,如果我看到这个正确,如果没有,请纠正我,但不应该拒绝等级是浮动价值?此外,您没有为 r 分配任何内容,这意味着它将始终是一个空数组并保持这种状态。我最近也使用opencv python的detectmultiscale做了一些事情,我做的是这个:

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

其中 1.3 相当于拒绝级别。