View Full Version : [Question(s)] Getting data from a webcam

10-15-2008, 06:41 AM
Second question of the day...
Where can I go to get examples or instructions on using a live webcam or live video camera attached to a Windows XP pc and converting the output to a 2 dimentional array with RGB values.
The goal is this... convert each frame to an array of 0-255 R, G and B values (so I can process the output with my other programs)
Know any sites, tutorial, examples???
(oh yea... C, C++ or Java plz)
Big time Thanks!!!!

10-15-2008, 11:44 AM
roborealm is a good start. They have lots of different filters and what not. If your willing to learn a new language, Cyclops by Cycling74 is an amazing program...pricey though. Roborealm is free...so have at it.


10-15-2008, 12:04 PM
But, AFAIK, won't perform the task he's asking for.

You haven't mentioned *which* C++, Eric. There's nothing for handling video natively in ANSI C++, it's all from libraries. And since libraries are dependant upon the vendor, we need to know which you're using.

10-15-2008, 01:33 PM
Thanks Adrenalynn! Which C++... I keep forgetting C++ isn't like Java.... many flavors. Tell you the truth... I don't know yet. I haven't messed with C++ in about 6 years.
I think I am seeing things a bit clearer on this. It probably depends on the vendor of the camera (right?). I know how to break down .jpgs and other still images by decompressing the image, stripping out the header and what's left is the 2D array with raw 0-255 values. I guess a followup question is this:
What methods are people using to take a video camera and convert the image/frame to an array? (without first saving the image as a mpg or jpg or other format.) Or is the only option to save it first as a file and strip down the saved file?
(side note: I am not intersted on any filters or processing of the image, I have my own algrothims for that... I am looking to get the image/frame in its most basic component, 2D array of values)

10-15-2008, 01:40 PM
On a side note: I would suggest playing with Roborealm just for fun though. It's awesome and easy to use. Nothing like being able to whip together vision processing demos in minutes using VBscript.

10-15-2008, 01:55 PM
Well, if it's DirectX, the data should be decompressed from its stream format into the YUV overlay in video memory. You should be able to snatch the frame from video memory in YUV.

Once it's in a YUV array, it's just basically

R(y,u,v) ((1.164 * (y - 16)) + (1.596 * ((v) - 128)))
G(y,u,v) ((1.164 * (y - 16)) - (0.813 * ((v) - 128)) - (0.391 * ((u) - 128)))
B(y,u,v) ((1.164 * (y - 16)) + (2.018 * ((u) - 128)))

to get to RGB (don't kill me if your colors are funky. That's from memory but it's gotta be pretty darned close).

If you need to, you should be able to use something like libmpeg4 or ffmpeg and grab the encoded stream and decode it into a YUV frame buffer, and then convert.

Lots of good libraries in ffmpeg and in mplayer (http://mplayerhq.hu) for doing this kinda stuff. They've both been ported to windows.

Really, for maximum quality, you should stay in the YUV space for as long as you can - the transforms aren't that tough...

10-16-2008, 06:17 AM
Thanks All,
Tyberius, darkback2, I will need to look into Roborealm. Most of what I will be doing is in pure research level, so I check it out to see if that is a possible jumping off point.
Adrenalynn... I am reminded of a Ron Wealsy quote from HP#1. "You're brilliant.... Scary... but brillant." I am looking into ffmpeg and libmpeg4 now. This is a great direction to study.

10-16-2008, 11:44 AM
Thanks, Eric, I think. :)

Do also check out mplayerhq.hu - some of that is based on libmpeg4 and ffmpeg, but it's a more complete solution that handles streaming natively, and can even decode windows media by loading their DLLs.

I've been doing video since we were all impressed with four colors or 16 shades of amber. ;) After awhile something rubs off. It's my primary area of expertise - most specifically CODEC design and interesting ways of accelerating said.

10-16-2008, 01:41 PM
Thanks again! Oh, I do mean the comment above in a most respectful way. Your wealth of information and intelligence on these boards is amazing.:eek:

10-16-2008, 02:37 PM
I know you did, sorry. I was hoping the emoticon would soften it, my bad. I do appreciate it - and I do relate to Miss Granger. ;)