如何通过USB从多个DSLR相机捕获图像使用Python?

时间:2017-06-27 21:37:45

标签: opencv camera video-capture capture canon-sdk

我需要通过USB使用Python来同步和捕获来自几个(10-20)DSLR(佳能)的图像,但我不知道如何。

我用SparkoCam和这个python代码得到它,但它只适用于一个摄像头

import cv2
import numpy as np
cap = cv2.VideoCapture(1)
while True:
    ret,img=cap.read()
    cv2.imshow('video output',img)
    k=cv2.waitKey(10)& 0xff
    if k==27:
        break
cap.release()
cv2.destroyAllWindows()

有谁知道如何从DSLR捕获图像? opencv,sdk?

1 个答案:

答案 0 :(得分:0)

如果您坚持在此应用程序中使用opencv,只需修改代码以使用多个Videocapture对象即可使用

import cv2
import numpy as np
cap1 = cv2.VideoCapture(1)
cap2 = cv2.VideoCapture(2) #you can check what integer code the next camera uses
cap2 = cv2.VideoCapture(2) #you can check what integer code the next camera uses
#and so on for other cameras
#You could also make this more convenient and more readable by using an array of videocapture objects

while True:
    ret1,img1=cap1.read()
    cv2.imshow('video output1',img1)
    ret2,img2=cap2.read()
    cv2.imshow('video output2',img2)
    #and so on for the other cameras
    k=cv2.waitKey(10)& 0xff
    if k==27:
        break
cap1.release()
cap2.release()
#and so on for the other cameras
cv2.destroyAllWindows()
相关问题