qq_41721190
丿葬爱丶贵族丨
2018-12-04 09:34

OPencv使用下cvtColor 出错

  • net....

环境:树莓派3 raspberry
代码片段:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

faceCasecade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

while(True):
ret,frame = cap.read()

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

faces = faceCascade.detectMultiscale(
    gray,
    scaleFactor=1.2,
    minNeighbors = 5,
    minSize = (30, 30)
    )
print("Found {0} faces!".format(len(faces)))
for(x, y, w, h) in faces:
    cv2.rectangele(frame,(x,y),(x+w,y+h),(0,255,0),2)

cv.inshow('frame',frame)
if cv2.waitKey(1)& 0xFF ==ord('q'):
    break
cap.release()
cv2.destroyAllwindows()

    报错:
    Traceback (most recent call last):

File "/home/pi/Desktop/OPenCV/live.py", line 11, in
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.3) /home/pi/opencv-3.4.3/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

如何解决

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答