基于外部触发器的econ see3cam上的图像捕获



我有一个econ see3cam 24CUG,想要访问相机并基于触发模式(外部触发信号)使用openCV python或c++捕获图像。我有触发电缆连接到相机,只是想捕捉和保存图像只有当触发信号给它。

我尝试过的事情

  1. 使用opencv捕获
def nativeMethod():
# define a video capture object
vid = cv2.VideoCapture(0)

while(True):
if vid.isOpened():
# Capture the video frame
# by frame
ret, frame = vid.read()

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

# the 'q' button is set as the
# quitting button you may use any
# desired button of your choice
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# After the loop release the cap object
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()
  1. using qtcam软件-这是工作的触发器,但它只是在gui的形式。
  2. <
  3. v4l-utils工具/strong>

根据e-con的博客文章-

https://www.e-consystems.com/blog/camera/camera-board/external-trigger-usage-of-see3cam_cu135-camera/

Master Mode"摄像机将流式传输视频帧,等待硬件触发。在触发模式下摄像机将无法传输视频帧

我刚刚看过这个。天啊,太蠢了。虽然一个V4L2 CMD。SET为触发模式,你猜生态系统不使用它吗?

如果你正在使用qtcam,那就意味着你在linux中。他们处理发送此命令的方式是绕过系统驱动程序并直接与芯片上的ISP交谈。这就是为什么你必须在sudo中启动qtcam,他们的应用程序绕过os驱动程序直接与硬件对话,你需要更高的权限才能做到这一点。

我也使用24CUG相机,所以具体的vid和pid应该延续下去。它所做的唯一的事情就是发送ext触发器命令—没有其他任何图像捕获。只需使用与您的opencv内容一致的代码。您应该能够在qtcam或qv4l2运行并捕获图像时发送此命令。如果不是很清楚,这是一个python脚本,但是具体细节应该可以移植到任何可以将原始数据包写入usb的设备上。您需要在sudo中运行这个命令——没有别的办法。此外,你还需要手动设置曝光时间,而不是自动曝光,如果你把触发线调高,它会发送多张照片。将脉冲设置为高10us,其余的设置为低,以保持一次一帧。祝你好运。(我内联清理了这段代码,所以可能会有一些编译错别字,但要点在那里。)

import usb.core
import usb.util
import sys
dev=usb.core.find(idVendor=0x2560, idProduct=0xc128) #lsusb to list attached devices in case your id's are different. 
#print(dev) #uncomment to see the configuration tree. 
#Follow the tree: dev[0] = configuration 1. 
#interfaces()[2] = HID interface
#0x06 = Interrupt OUT. (Endpoint)
if dev is None:
raise ValueError('Device not found')
cfg=-1
i = dev[0].interfaces()[2].bInterfaceNumber
cfg = dev.get_active_configuration()
intf = cfg[(2,0)]
if dev.is_kernel_driver_active(i):
try:
reattach = True
dev.detach_kernel_driver(i)
#print("eh") #debug making sure it got in here. 
except usb.core.USBError as e:
sys.exit("Could not detach kernel driver from interface({0}): {1}".format(i, str(e)))

print(dev) #not needed, just helpful for debug
msg = [0] * 64
#msg = [0xA0, 0xc1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00] #gotta send a 64 byte message. 
msg[0] = 0xA8 #these command sets are in the qtcam source code. 
msg[1] = 0x1c
msg[2] = 0x01 # 01= ext trigger. 00 = Master mode. 
msg[3] = 0x00

dev.write(0x6,msg,1000) #wham bam, thank you ma'am. Just write msg to the 0x06 endpoint. The 1000 is a timeout in ms. That should go back down, but it's an artifact of debugging. Also, for debugging, I recommend using wireshark set to capture usb packets while you're sending them from qtcam. 

最新更新