import dxcam
import cv2
import numpy as np
# Create DXcam camera instance
camera = dxcam.create(output_color="BGR") # returns a DXCamera instance on primary monitor and frames are outputed in BGR format for direct processing in OpenCV.
camera.start() #runs on a seperate thread, captures at 60hz
while camera.is_capturing:
cv2.imshow('feed', camera.get_latest_frame()) #/creates window application rendering return a numpy array representing an image
cv2.waitKey(3000)
camera.stop()
I've read the documentation regarding how cv2.imshow() and cv2.waitKey() works but there are parts im still confused about. Here's my high level understanding (some parts i'm not sure about but i'll mention those points below):
CF2.imshow() will pass an event to the window's GUI event loop detailing it to render the numpy array returned by camera.get_latest_frame() into the windows application named "feed". When cv2.waitKey(3000) is executed, the thread responsible for executing this python script will trigger the OS's GUI system, telling it to process the contents of its event loop to which it then pauses execution of the current thread whilst the thread responsible for the OS GUI system is given control for at least the specified time (3s).
There's a couple things i don't get:
-
In my code, does the first execution of "cv2.imshow('feed', camera.get_latest_frame())" create the windows application to which subsequent execution just internally refers to this same windows application?
-
is this python thread responsible for processing the OS GUI event loop as well or is there two threads: this python thread and a thread dedicated to handling the windows OS GUI event loop meaning that they are just prompting each other on when they can continue executing