简体   繁体   English

使用网络摄像头进行人体检测 python openCV

[英]Human detection with webcam python openCV

I wanted to do a human detection with a webcam, but I cannot get pass this error.我想用网络摄像头进行人体检测,但我无法通过此错误。

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-6-72d16e24e4b8> in <module>()
     33 
     34   ret, frame = cap.read()
---> 35   cv2.imshow( face_detector(frame))
     36   if cv2.waitKey(1) == 13: #13 is the Enter Key
     37     break

<ipython-input-6-72d16e24e4b8> in face_detector(img, size)
      7 def face_detector(img, size=0.5):
      8     # Convert image to grayscale
----> 9   gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
     10   faces = face_classifier.detectMultiScale(gray,1.3,5)
     11   if faces is ():

error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Here is my code which error:这是我的错误代码:

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

cv2.imshow( face_detector(frame))

I have already posted Answer on This question: https://stackoverflow.com/a/59279532/12059759我已经发布了这个问题的答案: https : //stackoverflow.com/a/59279532/12059759

let me know if it will work!让我知道它是否有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM