Face detection and time - video
I have an issue with time and face detection. When I 'am inside for loop ,the time sticks a little bit.Code:
import cv2
from datetime import datetime
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('face_detection.avi' , fourcc , 10.0 , (640 , 480))
while True:
ret,frame = cap.read()
font = cv2.FONT_HERSHEY_SIMPLEX
date_time = str(datetime.today().strftime("%d-%m-%Y")) + ' ' + str(datetime.now().strftime("%H:%M:%S")) # show date and time
video = cv2.putText(frame,date_time,(30,400),font,1,(0,0,255),2,cv2.LINE_AA)
faces = cv2.CascadeClassifier('haarcascade_frontalface_default.xml').detectMultiScale(frame, 1.1, 4)
for(x,y,w,h) in faces:
cv2.rectangle(frame , (x,y) , (x+w , y+h) , (255,0,0) , 3)
cv2.imshow('Face Detection' , frame)
out.write(frame)
if(cv2.waitKey(1) == ord('q')):
break
cap.release()
out.release()
cv2.destroyAllWindows()
cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
this has to go before the loop. please do not reload a ~1mb xml file per frame (and then throw it away !)
Still doesn't work... seconds passes faster than normal... I tested many times. Why is this happening?(maybe of the for-loop inside while-loop??)
Here is tutorial link: Detect face
My problem is the time ,not detection The seconds passes faster than normal(maybe because of the for-loop inside while loop) Does anyone knows how to fix it?
sorry, but it's unclear what you mean now