我写了一个代码,用两个不同的帧来播放一个视频线程。那个代码看起来不错,但是cv2.imshow方法不显示正在播放的视频。视频播放器立即打开和关闭。
解决问题所需的帮助。在import threading
import cv2
def print_cube(num):
"""
function to print cube of given num
"""
print("start")
print(num)
cv2.imshow("video1",num)
print("end")
cv2.destroyAllWindows()
def print_square(num):
"""
function to print square of given num
"""
print("start1")
print(num)
cv2.imshow("video2",num)
print("end2")
if __name__ == "__main__":
# creating thread
cap = cv2.VideoCapture("C:\\Users\shakarna\Desktop\video.mp4")
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
t1 = threading.Thread(target=print_square, args=(frame,))
t2 = threading.Thread(target=print_cube, args=(gray,))
# starting thread 1
t1.start()
# starting thread 2
t2.start()
# wait until thread 1 is completely executed
t1.join()
# wait until thread 2 is completely executed
t2.join()
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()