i have a django web application hosted locally on a desktop workstation that is supposed to retrieve a video feed/video frames from a webcamera connected via usb. What then happens is that the frame would used as input into an object detection model to count some stuff, but since the objects are small, i need to retrieve the frame at a higher resolution (720, 1280) instead of the default resolution. after the counting is done, i stop reading frames from the web camera - here is the sequence:
- Press button in web application to start retrieving video from webcamera
- create new opencv cap, since i need a higher resolution, i have to specify the resolution
cap = cv2.VideoCapture(0 + cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
-
while
loop that include frame retrieval, counting logic and visualization of the frame with inference results using opencvcv2.imshow()
- stop retrieving video frames (
cv2.destroyAllWindows()
andbreak
out of while loop) after counting is done, finally callingcap.release()
the problem with this sequence is that the video stream takes a few seconds (about 3 seconds) to load (this means that after clicking the button in step 1, i only see the video stream in step 3 after about 3 seconds which is quite slow, and there is an autofocus that takes about 1 second after the video stream pops up)
i am considering this new sequence which does not involve the release of the cap. i found that the video stream takes much faster to load and there is no autofocus each time the video stream is loaded:
- when starting the django server, create the opencv cap and specify the required resolution (meaning this is only done once)
cap = cv2.VideoCapture(0 + cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
-
while
loop that include frame retrieval, counting logic and visualization of the frame with inference results using opencvcv2.imshow()
- stop retrieving video frames (
cv2.destroyAllWindows()
andbreak
out of while loop WITHOUT callingcap.release()
)
Would the second flow result in any problems or damage to the webcamera, especially if the cap is opened for a long time (like weeks or even months).