Prev: acceleration to displacement accelerometer data
Next: Real-Time Windows Target and RS232 communication?
From: jordan a on 15 Apr 2010 22:50 hi, so i've made a gui that will be used for real time control of a robot. part of it includes reading from the robots webcam. the code i used is: vid=videoinput('winvideo',1); vidRes = get(vid, 'VideoResolution'); nBands = get(vid, 'NumberOfBands'); hImage = image( zeros(vidRes(2), vidRes(1), nBands) ); preview(vid, hImage); pretty standard. the image projects onto a set of axes in the gui. however, while getting info from the webcam, i can't do any other things with the gui (i.e move the robot). so i tried taking snapshots every few seconds but that creates a poor quality image (image(getsnapshot(vid))). is there a better way of doing this? thanks!
From: Berend Botje on 5 May 2010 22:32 Hi, I can at least tell you what the cause of the problem is, as I had the same issue last year and since then I have been searching for a solution. The problem is, that the snapshot function in Matlab reads out the current buffer of the webcam. When using the camera in video mode, the buffer will be read every 0.04 seconds (25 times per second). With snapshot, you take the buffer as is, without waiting for the buffer to fully 'load'. So... if you are unlucky, only a few photons will have hit the sensor (because the buffer was just cleared) and your snapshot will be nearly black. If you are lucky, however, you will have a close to full buffer to read out and your snapshot will be good. There seems to be, however, no workaround for this. You will have to use another function, or, what would be my preferred solution, another webcam that doesn't have this problem (if such a webcam exists). I have tried to find out if some webcams work better than others, but so far without success. Hopefully I will find the solution one day.
From: Mark Jones on 26 May 2010 08:31
jordan a wrote: > hi, > > so i've made a gui that will be used for real time control of a robot. > part of it includes reading from the robots webcam. > > the code i used is: > > vid=videoinput('winvideo',1); > vidRes = get(vid, 'VideoResolution'); > nBands = get(vid, 'NumberOfBands'); > hImage = image( zeros(vidRes(2), vidRes(1), nBands) ); > preview(vid, hImage); > > pretty standard. the image projects onto a set of axes in the gui. > however, while getting info from the webcam, i can't do any other things > with the gui (i.e move the robot). so i tried taking snapshots every few > seconds but that creates a poor quality image (image(getsnapshot(vid))). > is there a better way of doing this? thanks! Hi Jordan, The problem here is that the PREVIEW function is also being processed on the same thread as the other callback code. I do wonder if using a FramesAcquiredFcn that called PEEKDATA/GETDATA, set the CData on the IMAGE object, and then called DRAWNOW might allow your other callbacks to execute more smoothly. Mark |