简体   繁体   中英

OpenCV Python detectMultiscale

Hi guys can you give me advice about OpenCV? When I want to print out r to see rejectLevels it only print's out empty array.

#!/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

Can you give me some solution or experience on Opencv detectMultiScale, I looked into c++ code source and it's looking fine there, but in Python it wont work as it should be. OpenCV version: 2.4.8 Python version: 2.7.6

I am not sure, if I see this correctly and if not, please correct me, but shouldn't rejectlevels be a float value? Furthermore, you aren't assigning anything to r , meaning it will always be an empty array and stay that way. I did something using opencv python's detectmultiscale recently, too and what I did is this:

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

where 1.3 is equivalent to rejectlevels.

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