Ask Your Question
0

faceCascade.detectMultiScale error

asked 2017-04-19 13:38:12 -0600

patagonia gravatar image

updated 2017-04-19 19:11:52 -0600

berak gravatar image

I want to test face detection, An error occurs. Please help me

python-3.6.1-amd64.exe numpy-1.12.1+mkl-cp36-cp36m-win_amd64.whl opencv_python-3.2.0-cp36-cp36m-win_amd64.whl scipy-0.19.0-cp36-cp36m-win_amd64.whl

import cv2
import sys
import glob

cascPath = "E:\Job\Work_TEMP\20170419_face\haarcascade_frontalface_default.xml"

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)


files=glob.glob("*.jpg")
for file in files:
    # Read the image
    image = cv2.imread(file)

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


    # Detect faces in the image
    #faces = faceCascade.detectMultiScale(gray, 1.3, 5)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags = cv2.CASCADE_SCALE_IMAGE
    )

    print ("Found {0} faces!".format(len(faces)))

    # Crop Padding
    left = 10
    right = 10
    top = 10
    bottom = 10

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        print (x, y, w, h)

        # Dubugging boxes
        # cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)


    image  = image[y-top:y+h+bottom, x-left:x+w+right]

    print ("cropped_{1}{0}".format(str(file),str(x)))
    cv2.imwrite("cropped_{1}_{0}".format(str(file),str(x)), image)

image description

edit retag flag offensive close merge delete

Comments

1

could you try again with the image ? also the error is missing.

berak gravatar imageberak ( 2017-04-19 19:13:15 -0600 )edit
1

the last 3 lines have to go into the for loop (needs 1 more indent)

you can only do anything if it found faces

berak gravatar imageberak ( 2017-04-20 01:21:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-2

answered 2017-08-18 21:38:38 -0600

supra56 gravatar image

Change this:

cascPath = "E:\Job\Work_TEMP\20170419_face\haarcascade_frontalface_default.xml"

to

cascPath = "haarcascade_frontalface_default.xml"
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-19 13:38:12 -0600

Seen: 6,036 times

Last updated: Aug 18 '17