Does anyone know how to use the video writer? I have a simple script that will detect faces with haar_cascades with laptop webcam and I am trying to figure out how write the output to a video file with the boxes around the detected faces. The .xml file for haar cascade is saved to directory and program runs in a loop format. What I have commented out below is #cv2.VideoWriter.write(frame)
which is not working as the video writer is not expecting a numpy array.
import numpy as np
import cv2, time
import matplotlib.pyplot as plt
haar_face_cascade = cv2.CascadeClassifier('opencv-master/opencv-master/data/haarcascades/haarcascade_frontalface_alt.xml')
video = cv2.VideoCapture(0)
a = 0
while True:
a = a + 1
check, frame = video.read()
print(check)
print(frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = haar_face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5);
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
cv2.imshow("Face Detector", frame)
#cv2.VideoWriter.write(frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
print(a)
video.release()
cv2.destroyAllWindows()