main.py
main.py is the main program that includes a variety of functions that call functions from other files. From each file name, main.py imports functions in those files, and those functions can now be called in main.py. Each function in main.py takes care of a different task.
callTrain()
flightProgram()
qrProgram()
taxiProgram()
main.py includes a function named showVideo(), and it displays a user’s default webcam. This function calls methods from videoDisplayWorker.py and decklinkSrcWorker_taxi.py. In decklinkSrcWorker_taxi.py, a DeckLinkSRC object is created, and continuously grabs frames from the device’s webcam. Since all parameters in python are pass by reference, the piplineOut parameter is constantly updated to a new frame using the put() function. In showVideo, both functions videoDisplay() and decklinkSrcWorker() are run in a list of parallel processes. Since both functions run in parallel and the pipelineOut variable is constantly updated, this variable can be passed into videoDisplay() as a parameter for every new frame taken from the decklink webcam.
videoDisplayWorker.py
Video display in python uses OpenCV, which is a library of programming functions that allow various functionalities in real-time computer vision. This includes video and image processing, object detection, tracking, and many more. In the videoDisplayWorker.py file, the OpenCV library is imported and used to display the user’s default webcam.
In videoDisplayWorker.py, the videoDisplay() function takes in the frame captured by dekclinkSrcWorker_taxi() as a parameter (pipelineIn). In a continuous loop, the videoDisplay() function uses the cv2.imshow() method which creates as new window and sets the pipelineIn as the current frame. In the program, this displays each frame at a high speed in a loop. Altogether, these output a new window showing the user’s webcam video. Note that there is an if statement that closes the window when ‘q’ is clicked on the user’s keyboard. This closes the window but does not disactivate the user’s webcam (webcam light remains on). To completely end the program, click on the garbage can icon to the right of the terminal. This is highlighted in yellow below.
As mentioned before, main.py runs decklinkSrcWorker_taxi() and videoDisplay() functions at the same time. The frame acquired by decklinkSrcWorker_taxi() is instantly passed into videoDisplay() and output to the screen. This is done continuously to create a full video stream. The high-speed frames that are acquired and output is what creates a functional webcam display.