Webcam generated image distorted and python stop working

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

shazni gravatar image

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 =

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
k = cv2.waitKey(1)
faces = faceCascade.detectMultiScale(
    minSize=(30, 30),

# 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
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