Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter3_face keypoint_detection: The script is fixed at the cv2.namedWindow("test") #12

Open
mikechen66 opened this issue Oct 28, 2020 · 1 comment

Comments

@mikechen66
Copy link

mikechen66 commented Oct 28, 2020

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 exectue 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.

img_counter = 0

while(True):
    ret, frame = cam.read()
    faces = face_cascade.detectMultiScale(frame, 1.3, 5)
    for (x,y,w,h) in faces:
        if w >130:
            detected_face = frame[int(y):int(y+h), int(x):int(x+w)] 
            cv2.imshow("test", detected_face)
    if not ret:
        break
    k = cv2.waitKey(1)

    if k%256 == 27:
        # ESC pressed
        print("hit Esc to skipe and hit Space bar to save image")
        break
    elif k%256 == 32:
        # SPACE pressed 
        faceresize = cv2.resize(detected_face, (img_size,img_size)) 
        img_name = "dataset/opencv_frame_{}.jpg".format(img_counter)
        cv2.imwrite(img_name, faceresize)
        print("{} written!".format(img_name))
        img_counter += 1
    
cam.release()
........

3. Can not exit from the camera

The camera is keeping moving and working. After closing the script with jupyter notebook, I still can not exit from the camera. The camera is showing my face until turning off the computer.

@gaurav-packt
Copy link
Collaborator

Hello @mikechen66,

Can you please share relevant order details as to from where did you purchased the book so that we can assist you?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants