How to replace "getsnapshot" with the button on my webcam?
显示 更早的评论
I need to capture a picture from my webcam, but I want to do it with an external trigger. The preferred trigger is the webcam button, but I'm open for other suggestions.
I know how to open the preview window and use the getsnapshot to get a snapshot.
The code is as follows:
%%initially
clear
clc
close all
%%display image options
imaqhwinfo
%%define webcam and open camera window
vid = videoinput('winvideo', 1, 'RGB24_320x240');
preview(vid);
%%get snapshot
data = getsnapshot(vid);
What I want to do is substitute the getsnapshot(vid) with an endless loop that checks if I pressed the button. When that condition is satisfied, the loop breaks, and I continue with proccessing my image.
采纳的回答
更多回答(2 个)
Siddharth Shankar
2011-1-30
1 个投票
What you are asking for is a "hardware trigger". You could check if your VIDEOINPUT object supports hardware triggers by using the TRIGGERINFO command. For ex:
triggerinfo(vid)
Most webcams I have worked with only have "immediate" as the trigger type.
One possibility is to connect a debouncer switch to your system via the serial port, or maybe a data acquisition card. You can then have a call to GETSNAPSHOT as soon as you detect a switch press. You can read more about trigger types for image acquisition devices here: Comparison of Trigger Types.
David Tarkowski
2011-2-18
0 个投票
Webcams don't expose access to their hardware buttons in a consistent manner, so there is no good way for us to expose those buttons as hardware trigger inputs.
I think that Jiro's suggestion of using a uicontrol is probably the best solution. In the callback for the uicontrol you would call getsnapshot and then call your processing routine.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrox Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!