Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 显示视频并请求用户输入_Python_Video_While Loop - Fatal编程技术网

Python 显示视频并请求用户输入

Python 显示视频并请求用户输入,python,video,while-loop,Python,Video,While Loop,我试图为用户显示视频,并在视频播放时请求输入。 这两个循环需要一起工作,我不知道怎么做 这就是我到目前为止所做的: import cv2 # basic video display from openCV doc def showVideo(): videoPath = "something" cap = cv2.VideoCapture(videoPath) # display the video infinitely while cap

我试图为用户显示视频,并在视频播放时请求输入。 这两个循环需要一起工作,我不知道怎么做

这就是我到目前为止所做的:

import cv2


# basic video display from openCV doc
def showVideo():
    videoPath = "something"
    cap = cv2.VideoCapture(videoPath)
    # display the video infinitely
    while cap.isOpened():
        ret, frame = cap.read()
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow('frame', gray)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()


# basic user input function
def askInput():
    something = input("please enter a number: ")
    isNUmber = False
    while not isNUmber:
        try:
            x = int(something)
            isNUmber = True
        except ValueError:
            print("This is not a number")
            something = input("please enter a number: ")

如果您有更好的想法,而不是让它们一起工作,我很高兴听到它

您可以试试线程