Reputation: 11
I have an econ see3cam 24CUG, want to access the camera and capture the images using openCV python or c++ based on trigger mode(external trigger signals). I have the trigger cable connected to camera, just want to capture and save the image only when the trigger signal is given to it.
Things i have tried,
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()
Upvotes: 1
Views: 1114
Reputation: 11
I just went through this. Oh god, it's dumb. While there is a V4L2 CMD.SET for trigger mode, would you guess that econsystems doesn't use it?
If you're using qtcam, that means you're in linux. The way they handled sending this command is by bypassing the system driver and talking directly to the ISP on the chip. This is why you have to start qtcam in sudo, their app bypasses os drivers and talks to hardware directly and you need a higher privilege to do that.
I'm using a 24CUG camera as well, so the specific VIDs and PIDs should carry over. The only thing this does is send the ext trigger command - nothing else with image capture. Just use this code in line with your opencv stuff. You should be able to send this command while qtcam or qv4l2 is running and capturing images. If it wasn't clear, this is a python script, but the nuts and bolts should be portable enough to anything that can write raw data packets to usb. You need to run this command in sudo - there's no way around that. Also, you're going to also want to manually set the exposure time - no auto - and if you keep your trigger lead tied to high, it will send multiple captures. Set the pulse to 10us high and the remainder low to keep it one frame at a time. Best of luck. (I cleaned this code up inline, so there may be some compiling typos, but the gist is there.)
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.
Upvotes: 1
Reputation: 9
According to e-con's blog post -
In "Master Mode" the camera will stream video frames waiting for a hardware trigger. In "Trigger Mode" the camera will not stream video frames.
Upvotes: -1