Python Cv2的说法是;“发现照相机”;即使不是
我正在尝试制作一个程序,如果它检测到输入,就会自动启动显示视频。但它仍然认为视频输入在那里,即使相机没有连接,它应该在我连接外部相机后立即显示视频,但它没有 这是我的代码:Python Cv2的说法是;“发现照相机”;即使不是,python,opencv,video,webcam,Python,Opencv,Video,Webcam,我正在尝试制作一个程序,如果它检测到输入,就会自动启动显示视频。但它仍然认为视频输入在那里,即使相机没有连接,它应该在我连接外部相机后立即显示视频,但它没有 这是我的代码: import numpy as np import cv2 ImageSource = 1 cap1 = cv2.VideoCapture(ImageSource) def testDevice(source): #this is to make the auto show feature. while (True):
import numpy as np
import cv2
ImageSource = 1
cap1 = cv2.VideoCapture(ImageSource)
def testDevice(source): #this is to make the auto show feature.
while (True):
if (cap1.isOpened):
print('got video output')
break
testDevice(ImageSource)
if (cap1.isOpened):
while(cap1.isOpened):
# Capture frame-by-frame
ret, frame = cap1.read()
# Display the resulting frame
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap1.release()
cv2.destroyAllWindows()