MATLAB Answers

Viswas Guptha

Taking rgb values in a video preview dynamically(i.e run time)

Asked by Viswas Guptha
on 26 Apr 2013

Hello everyone!! I am stuck with a serious problem here! I have my video preview showing up in GUI. I wanted the user to select a particular color or a particular portion of the image by selecting it with mouse. Then I want to take the rgb values of the selected color into the program and operate with it. The part where the user has to select a portion of the image, I have no idea how to do it. I thought of using the crop function, but how to use it in run time. And all of this I have to do it in GUI and while the program is running. Please help.. :)


2 Answers

Answer by Image Analyst
on 26 Apr 2013
 Accepted answer

You can use imrect() or rbbox() to let the user select a box. Not sure if it works over a live image, but you could try it. If it doesn't, then capture a frame and let the user draw over that, then turn the video live again. To get the subimage out, you have to call getsnapshot(), which returns a frame from the live video into a variable in your program. Then you can use imcrop() to extract out that portion if you want, and then do whatever you want with it.


Answer by Anchit Dhar
on 26 Apr 2013

You can also try using the ROIPosition property of the videoinput object to get that subimage.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!