I use Opencv to detect faces from IP cameras via MJPEG protocol. Very slow? Here is my code. We hope you can help. Is there any way to do it faster? Or did I do something wrong? My IP camera views data from live MJPEG very quickly. But when using Opencv it is slow, very slow!
cap = cv2.VideoCapture('http://root:[email protected]/mjpeg')
cap.set(cv2.CAP_PROP_FPS, 30)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('m', 'j', 'p', 'g'))
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
ret, frame = cap.read()
cv2.imshow('mjpeg', frame)
img = recognize(frame, clf, faceCascade)
frames = cv2.imencode('.jpg', img)[1].tobytes()
yield (b'--framern'b'Content-Type: image/jpegrnrn' + frames + b'rn')
key = cv2.waitKey(1)
if key == 27:
break
I have used different versions of opencv, but still very slow
New contributor
Hiến Dương Đức is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.