I used a cam with the raspberryPI v. 4b with openvcv, but, when I start the program, tha stream start to lag and I can’t use it properly. I tried to use a sleep but nothing change. The code is this:
import cv2
import numpy as np
import time
cap = cv2.VideoCapture(0)
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
while True:
ret, frame = cap.read()
if not ret:
print("erore durante la lettura del frame")
break
frame = cv2.resize(frame, (640, 480))
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
boxes, weights = hog.detectMultiScale(frame, winStride=(8,8))
boxes = np.array([[x, y, x + w, y + h] for (x, y, w, h) in boxes])
for (xA, yA, xB, yB) in boxes:
cv2.rectangle(frame, (xA, yA), (xB, yB), (0, 255, 0), 2)
img = cv2.resize(frame, (640, 480))
cv2.imshow("Frame", img)
time.sleep(0.1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
If you have any clue write under this question. Thank you
Sandro-Ale1205 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.