Webcam generated image distorted and python stop working

asked 2020-09-08 21:41:37 -0600

shazni gravatar image

updated 2020-10-04 14:42:35 -0600

supra56 gravatar image

Code:

import cv2
import sys

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

video_capture = cv2.VideoCapture(0)

img_counter = 0

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()


    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    k = cv2.waitKey(1)
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.5,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('FaceDetection', frame)

    if k%256 == 27: #ESC Pressed
        break
    elif k%256 == 32:
        # SPACE pressed
        img_name = "facedetect_webcam_{}.png".format(img_counter)
        cv2.imwrite(img_name, frame)
        print("{} written!".format(img_name))
        img_counter += 1


# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

running the code works fine, but after i try to installed CMake and dlib library which i failed to do the image of the webcam is distorted and python stop working

this is the image generated from the webcam

edit retag flag offensive close merge delete

Comments

but after i try to installed CMake and dlib library

sorry, but that's unclear.

berak gravatar imageberak ( 2020-10-05 05:27:32 -0600 )edit