Python OpenCV避免使用视频源 - >捕获源对话框

时间:2015-06-27 03:02:53

标签: python python-2.7 opencv video webcam

所以我试图在python 2.7.5上创建一个简单的程序,窗口就是这样 显示用户选择时间的实时视频。

import numpy as np
import cv2
import time


def Func_VideoCapture(Float_Time = 10):
    Float_WantedTime = time.time() + Float_Time
    Float_CurentTime = time.time()

    cap = cv2.VideoCapture(0)

    while Float_CurentTime <= Float_WantedTime:
        #get current time
        Float_CurentTime = time.time()

        # Capture frame-by-frame
        ret, frame = cap.read()

        # Display the resulting frame
        cv2.imshow('frame',frame)

    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    Float_Time = float(raw_input(">>> "))
    Func_VideoCapture(Float_Time)

但是当我运行它时会出现一个对话框,要求我弹出相机(视频源 - &gt;捕获源)。 如何将其隐藏起来? 附:我也尝试过运行......

cap = cv2.VideoCapture(0)

...在主函数中但结果是相同的:

import numpy as np
import cv2
import time

def Func_VideoCapture(cap, Float_Time = 10):
    Float_WantedTime = time.time() + Float_Time
    Float_CurentTime = time.time()

while Float_CurentTime <= Float_WantedTime:
    Float_CurentTime = time.time()

    # Capture frame-by-frame
    ret, frame = cap.read()

    # Display the resulting frame
    cv2.imshow('frame',frame)

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

def main():
    cap = cv2.VideoCapture(0)
    Float_Time = float(raw_input(">>> "))
    Func_VideoCapture(cap, Float_Time)

if __name__ == "__main__":
    main()

P.S.#2我在Windows上,但我不一定要使用这个版本的python或OpenCV

1 个答案:

答案 0 :(得分:-1)

试试这个:

import numpy as np
import cv2
import time


def Func_VideoCapture(Float_Time = 10):
    Float_WantedTime = time.time() + Float_Time
    Float_CurentTime = time.time()

    cap = cv2.VideoCapture(0)



    while Float_CurentTime<=Float_WantedTime:
        #get current time
        Float_CurentTime = time.time()

        # Capture frame-by-frame
        ret, frame = cap.read()

        # Display the resulting frame
        cv2.imshow('frame',frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    Float_Time = float(raw_input(">>> "))
    Func_VideoCapture(Float_Time)