MATLAB Answers

How to show an image saved in runtime at a matrix as a video?

2 views (last 30 days)
Francisco Mendoza
Francisco Mendoza on 7 Dec 2014
Hi, all, i have a problem with this script that doesn't do what a need to; i'm getting initiated in Matlab, so i'm waiting you to support me for. I'll be very grateful.
The code is:
_____________________________________________________
function videomonocolor
vid = videoinput('macvideo', 1, 'YCbCr422_1280x720');
k=0;
c=1;
start(vid);
while c<100
A = getsnapshot(vid);
A=imresize(A,0.3);
rgb = A;
I = ycbcr2rgb(rgb);
imshow(I)
c=c+1;
end
end
__________________________________________________________
As You can see, the script is very austere; then well, what im trying to do is take a snapshot from my macbook's camera and give it to a matrix that could be modified, saving, so, all informatión of image, then work with it, and display it again. All this have a purpose, but now, I just have one problem: the imshow doesn't show me anything. Some times show just the last image that was taken, when the program it's done. I think isn't the appropriate way to display every image and show almost at runtime, just like a video motion. I don't want to take a sequence of photos, then use the comand that convert this same sequence to a video. I want to work with an image at the time, and show the same information that has been token. I know about the function that do this, showing a preview of the video.. but i want every snapshot for do something with it... I apologise for my english, that is not the best. Greetings from México, and good night here.

Answers (2)

Image Analyst
Image Analyst on 7 Dec 2014
Edited: Image Analyst on 7 Dec 2014
The badly-named I is probably a double and imshow doesn't like RGB doubles. Cast it to uint8 and it will probably be okay. But a worse problem is that you're possibly taking an RGB image and passing it in to ycbcr2rgb() which expects an input that is of YCbCr color space, not RGB color space. If you call imshow(A), does it look like a normally colored image? If so why are you even calling ycbcr2rgb() since A is already RGB?
How do you make sure the badly-named A is an RGB image? Well after you instantiate vid you have to set the returned color space:
vid.ReturnedColorSpace = 'rgb';
  12 Comments
Francisco Mendoza
Francisco Mendoza on 7 Dec 2014
Thanks for the script, and all the support. I'll work on it :')

Sign in to comment.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by