PacktPublishing / Mastering-Computer-Vision-with-TensorFlow-2.0

Mastering Computer Vision with TensorFlow 2.0, published by Packt
MIT License
91 stars 68 forks source link

Chapter3_opencv_face&eyedetection_video --AttributeError: 'NoneType' object has no attribute 'copy' #5

Open mikechen66 opened 3 years ago

mikechen66 commented 3 years ago

I seems that the camera does not read images. The camera is a logitech new camera. It can show my image but could not capture images. So it quite strange.


AttributeError Traceback (most recent call last)

in 30 while True: 31 ret,frame = cap.read(0) ---> 32 frame = detect_face(frame) 33 frame = detect_eye(frame) 34 # gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) in detect_face(img) 9 10 def detect_face(img): ---> 11 face_img = img.copy() 12 # face_rects = face_cascade.detectMultiScale(face_img) 13 face_rects = face_cascade.detectMultiScale(face_img,scaleFactor=1.2,minNeighbors=5) AttributeError: 'NoneType' object has no attribute 'copy'
mikechen66 commented 3 years ago

I tried the script again after installing dlib and related libraries. I can see my face with executing the the 1st section of the code. However, the script could not execute the rest of the lines of the code. So it is quite strange.

1. Only execute the lines of code

I can see the camera works correctly and show my face. But camera screen is keep shaking.

from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
....
face_cascade = cv2.CascadeClassifier('./cv2/data/haarcascade_frontalface_default.xml')

img_size = 299

# -cam = cv2.VideoCapture(0)
cam = cv2.VideoCapture(-1)

cv2.namedWindow("test")

2. Do not execute the rest of the line of the code.

The rest of the lines of code are not executed. It is quite strange.

while True:
    ret,frame = cap.read(0)
    frame = detect_face(frame)
    frame = detect_eye(frame)
   # gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    cv2.imshow('video face detect', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
gaurav-packt commented 3 years ago

Hello @mikechen66,

Can you please your order details as to from where have you purchased the book?

Thanks