【问题标题】:my picam to raspberry pi 3 for face detection but i am getting this error我的 picam 到树莓派 3 进行人脸检测,但我收到此错误
【发布时间】:2018-09-17 13:21:02
【问题描述】:

gray = cv2.cvtColor(image_frame, cv2.COLOR_BGR2GRAY) cv2.error: /home/pi/Downloads/opencv/modules/imgproc/src/color.cpp:11095: 错误: (-215) scn == 3 ||函数 cvtColor 中的 scn == 4。 有没有办法在不更换picam的情况下解决?


# Import OpenCV2 for image processing
import cv2

# Start capturing video 
vid_cam = cv2.VideoCapture(0)

# Detect object in video stream using Haarcascade Frontal Face
face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# For each person, one face id
face_id = 5

# Initialize sample face image
count = 0

# Start looping
while(True):

# Capture video frame
_, image_frame = vid_cam.read()

# Convert frame to grayscale
gray = cv2.cvtColor(image_frame, cv2.COLOR_BGR2GRAY)

# Detect frames of different sizes, list of faces rectangles
faces = face_detector.detectMultiScale(gray, 1.3, 5)

# Loops for each faces
for (x,y,w,h) in faces:

    # Crop the image frame into rectangle
    cv2.rectangle(image_frame, (x,y), (x+w,y+h), (255,0,0), 2)

    # Increment sample face image
    count += 1

    # Save the captured image into the datasets folder
    cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y+h,x:x+w])

    # Display the video frame, with bounded rectangle on the person's face
    cv2.imshow('frame', image_frame)

# To stop taking video, press 'q' for at least 100ms
if cv2.waitKey(100) & 0xFF == ord('q'):
    break

# If image taken reach 100, stop taking video
elif count>100:
    break

# Stop video
vid_cam.release()

# Close all started windows
cv2.destroyAllWindows()code here

【问题讨论】:

  • 欢迎来到 SO。请以适当的方式重新格式化您的代码。

标签: python-3.5 raspberry-pi3 opencv3.0 face-recognition


【解决方案1】:

如果您使用的是 picam, 那么你必须import the picam module

import picamera

def getFrame():
    jpegBuffer = io.BytesIO()
    webcam.capture(jpegBuffer, format='jpeg')
    buff = numpy.fromstring(jpegBuffer.getvalue(), dtype=numpy.uint8)
    return cv2.imdecode(buff, 1)

image_frame = getFrame()

尝试一次,

【讨论】:

    猜你喜欢
    • 2020-04-30
    • 2015-07-08
    • 2013-12-07
    • 2011-06-21
    • 2021-06-04
    • 1970-01-01
    • 2018-07-08
    • 2019-11-11
    相关资源
    最近更新 更多