Good evening everyone.
I have some concerns regarding a project that I am setting up.
Indeed, when I display a simple Rtsp video stream via OpenCv, I have no problems. Everything is fluid. However I am using an haarcascaded face detection code and I have a lot of latencies and frames loss when i use it in my code. I am looking for some avenues to explore because I can't find solutions despite my research on the Net. I tried to change my camera but the problem is the same.
Below is the code:
class Algo(Thread):
import numpy as np
import cv2
from threading import Thread
def __init__(self, frame):
Thread.__init__(self)
self.frame = frame
def run(self):
faces = face_cascade.detectMultiScale(gray, 1.3,5)
for (x,y,w,h) in faces:
cv2.rectangle(frame, (x,y), (x+y, y+h), (255,0,0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y+h, x:x+w]
cap = cv2.VideoCapture('rtsp://[username]:[password]@[IP]:554/Streaming/Channels/1/')
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
while(True):
# Capture frame-by-frame
cap.grab()
ret, frame = cap.retrieve()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
thread_1 = Algo(frame)
thread_1.start()
thread_1.join()
# Display the resulting frame
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Regards, Pinigseu