Move the thread and mainloop at the end of cv2.waitKey, but not before waitKey/
Move the thread and mainloop at the end of cv2.waitKey, but not before waitKey/waitKey.