Below is the relevant code
import cv2 as cv
import numpy as np
video = cv.VideoCapture(0) #tells obj to use built in camera\
#create a face cascade object
face_cascade =
cv.CascadeClassifier(r"C:\Users\xxxxxxx\AppData\Roaming\Python\Python36\site-
packages\cv2\data\haarcascade_frontalcatface.xml")
a = 1
#create loop to display a video
while True:
a = a + 1
check, frame = video.read()
print(frame)
#converts to a gray scale img
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
#create the faces
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
for(x, y, w, h) in faces:
print(x, y, w, h)
#show the image
cv.imshow('capturing', gray)
key = cv.waitKey(1) #gen a new frame every 1ms
if key == ord('q'): #once you enter 'q' the loop will be exited
break
print(a) #this will print the number of frames
#captures the first frame
video.release() #end the web cam
#destroys the windows when you are not defined
cv.destroyAllWindows()
The code displays a video captured from my webcam camera. Despite that, OpevCV doesn't seem to be processing any frames as all the frames look like this
[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]]
which I assume means that they are empty.
This I believe is preventing the algorithm from being able to detect my face in the frame. I have a feeling that the issue lies in the ffmpeg codec, but I'm not entirely sure how to proceed even if that is the case.
OS: Windows 10 Language: Python
EDIT: The Frame is not empty but all the values in the array seem to be '0'
Why is the frame empty and how can I get OpenCV to detect my face in the frame?