简体   繁体   中英

my print(“Found faces”, str(len(faces))) not executed

I'm trying to detect multiple faces using opencv in python. I'm doing this in raspbian OS (raspberry Pi 3). Although the code is working properly, ie, it's detecting a face and drawing a rectangular boundary around the face. It successfully saves the image in my local folder as well. The problem is : the statement print("Found faces", str(len(faces))) isn't working and the console remains blank. What am I missing here or where am I going wrong?

import io
import picamera
import cv2
import numpy
stream = io.BytesIO()

with picamera.PiCamera() as camera:
    camera.resolution = (320, 240)
    camera.hflip = True
    camera.capture(stream, format='jpeg')


buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)

image = cv2.imdecode(buff, 1)

face_cascade = cv2.CascadeClassifier('face1.xml')

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

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

print("Found faces", str(len(faces)))

for (x,y,w,h) in faces:
    cv2.rectangle(image,(x,y),(x+w,y+h),(255,255,0),2)

cv2.imwrite('result.jpg',image)

正确的代码是

print("Found faces= "+str(len(faces)))

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