469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Access USB Webcam using c++ on linux (asus eee)

Hi

I am attempting to get access to the data stream from the webcam on my asus eee, I have no clue as to where to start. I am trying to get to the stream so that I can distribute it over a local wireless network. I am OK with the socket programming bit, it is just getting to the stream which I am finding hard. There is little info that I can find on the web so any help would be appreciated.

I am thinking that I may want to store the stream in a temporary buffer, before encrypting a chunk of it and sending it via a udp socket?
Aug 18 '08 #1
15 11313
The best place to start is by determining what driver is being used. From there, search for what functionality that driver has and what calls are supported. Then all you need to do is make those calls in your program.

Interfacing with a webcam, even if a driver exists can be difficult. I would look for examples of code which are interfacing with the same/or a similar driver and use those as a template.

Edward
Aug 18 '08 #2
OK I will look into that, even when I have the calls how do you connect to the camera to send them? Am I right in saying that it is done in the same way as opening a file but with the usb devices mounted name as the filename?

Cheers
Aug 19 '08 #3
TamusJRoyce
110 100+
It seems like you are needing to deal with video4linux. Kernel hacking is about the best way, since you are dealing with encryption and streaming (two things linux excells at).

With video4linux, it makes it pretty simple to access any and all cameras supported's frame-buffer pretty easy (once you get through setting everything up).

I don't remember the link (and linking to there is forbidden, if I remember correctly), but I know there is excellent documentation out there. Just make sure you use v4l2 documentation instead of v4l1 because of several major differences in the api.

As for whether you need it in user mode or kernel mode...

Hopefully this helps you stream your webcam : )
Aug 19 '08 #4
It seems like you are needing to deal with video4linux. Kernel hacking is about the best way, since you are dealing with encryption and streaming (two things linux excells at).

With video4linux, it makes it pretty simple to access any and all cameras supported's frame-buffer pretty easy (once you get through setting everything up).

I don't remember the link (and linking to there is forbidden, if I remember correctly), but I know there is excellent documentation out there. Just make sure you use v4l2 documentation instead of v4l1 because of several major differences in the api.

As for whether you need it in user mode or kernel mode...

Hopefully this helps you stream your webcam : )
OK, i have had a look at the v4l2 stuff and the examples that I have found which use the code are huge. I really am just looking for simple code that will allow me to store frames in a buffer/data structure before being encrypted and sent over a socket. If no one knows of a solution then maybe a book/resource could be recommended.

Thanks
Aug 19 '08 #5
The three tasks you mentioned are not really do-able with just a simple program. My suggestion would be to study the example code and break it down to the bare minimum. As for the encryption and sockets, I would suggest finding libraries that take care of the tasks. Even using libraries, the program is not likely to be simple.

Edward
Aug 19 '08 #6
The three tasks you mentioned are not really do-able with just a simple program. My suggestion would be to study the example code and break it down to the bare minimum. As for the encryption and sockets, I would suggest finding libraries that take care of the tasks. Even using libraries, the program is not likely to be simple.

Edward
The sockets and encryption are the easy bit as I have done them before, but I was hoping that the frame capture wouldnt be too hard, the other option would be to buy an IP camera I suppose because that stream would be in packets already...
Aug 19 '08 #7
If you post the specifics for the camera (manufacturer and model number should work) you are tyring to use I can try to write/find some simple code though I will not be able to test it as I wont have the same camera. If you know the specific driver you want to use that would work as well.

One other matter to consider is what format the frame needs to be stored as. This could potentially make a big difference in how easy it is. (I have done some basic work with capturing images from webcams but I only had to deal with the most basic functionality as someone had written a header file to do most of the work.)

Edward
Aug 19 '08 #8
I will try to find out the make and model, It is the built in webcam on the asus eee701 laptop if that helps?

Regards

Scott
Aug 19 '08 #9
Try going to the terminal and typing lsusb (I think that is the command). If the webcam is connected via usb (which seems to be the case in most laptops now days) then you should be able to determine the make and model by looking at the resulting list of usb devices.

Hope that helps.

Edward

Edit: After a little research it apears that the webcam is connected by usb so the above command should yield results.
Aug 19 '08 #10
Try going to the terminal and typing lsusb (I think that is the command). If the webcam is connected via usb (which seems to be the case in most laptops now days) then you should be able to determine the make and model by looking at the resulting list of usb devices.

Hope that helps.

Edward

Edit: After a little research it apears that the webcam is connected by usb so the above command should yield results.
I will see if that works when I get home later and have acces to the laptop
Aug 20 '08 #11
TamusJRoyce
110 100+
Oh... I thought with the encryption you where being "high tech."

Only reason I know about v4l2 is because I had a malfunctioning cheap camera whose driver didn't quite work. A project that was never completed because it's above my head as well.

Your best bet is to use sdl. It has a module which will interact with v4l giving you an easy to access frame buffer.

Agg. Well, on windows that's the case. I think the one for the Panasonic camera sdl_camera addon would work for any camera, but I dunno.

I hope this answers your question. Never used sdl's camera on linux, though sdl runs great on linux, from what I've done.

maybe you need a command line tool or something to capture the frame buffer for you. "tv tools" pick up web cam's just as easy as tv-tuner cards. All based ontop of v4l. Or maybe their is an easy to use api they might implement.
Aug 20 '08 #12
Oh... I thought with the encryption you where being "high tech."

Only reason I know about v4l2 is because I had a malfunctioning cheap camera whose driver didn't quite work. A project that was never completed because it's above my head as well.

Your best bet is to use sdl. It has a module which will interact with v4l giving you an easy to access frame buffer.

Agg. Well, on windows that's the case. I think the one for the Panasonic camera sdl_camera addon would work for any camera, but I dunno.

I hope this answers your question. Never used sdl's camera on linux, though sdl runs great on linux, from what I've done.

maybe you need a command line tool or something to capture the frame buffer for you. "tv tools" pick up web cam's just as easy as tv-tuner cards. All based ontop of v4l. Or maybe their is an easy to use api they might implement.
I have tried looking online at SDL and it appears to be for producing graphics/games etc. but I cannot see anything about accessing images from cameras?
Aug 20 '08 #13
TamusJRoyce
110 100+
sdl-camera was what I was talking about. It says it does streaming using video4linux.

Patched to work with gentoo (though not required shows it's compatible with the latest & greatest). Look thought the code to see if it's right. Again, I've only used webcams with windows, so I could be wrong about this.

Try looking at v4l2 example (at http://v4l2spec.bytesex.org/v4l2spec-0.24.tar.bz2) for example.c and videodev2.h

Try accessing the buffer in buffers. maybe that would help? Or look at sdlcam above to see how it accesses v4l.

I doubt you want to access your camera low level through it's driver, and so far those are the only two alternatives I've pulled up so far. I'll be looking for another...
Aug 22 '08 #14
TamusJRoyce
110 100+
Ah... Look here . Search for "Applications and Libraries."

You probably would want to use DirectFB, which is a simple way to access the Frame Buffer *hits self on head and says duh* and is suppose to be similar to directx (hence me referring you to sdl, with it being cross platform). It's linux specific and uses v4l which is what I was looking for in the first place.

It also shows Xawtv which may also have some good tools/api's to access your webcam? Dunno if you can program with it, but I've used xawtv for tv-tuner card as well as webcams. Maybe an api for accessing it exists?

Unfortunately the data doesn't come in streams, but rather an area in memory where the pixels are refreshed according to the camera's refresh rate. You may be able to open that part of memory like a file, but who knows what format it will be in, or if the memory is even linear (meaning the camera only uses a part of the whole memory and determining the size is almost impossible, scewing your video line by line across the screen).

That's where SDL, DirectX, DirectFB, and such come in. They do the conversion to what you want for you. Just takes a bit to set them up.

Alter an example and ignore the setup part of the code. Just know you can access that array of bytes in the format you need it.

Yay. DirectFB for the win! Simple way to access the FB of your webcam? Now only if it worked in lolcode :P

Post back if this helps and if you have any success with it.
Aug 22 '08 #15
I had a look and play around with that directfb stuff but it doesnt seem to have much support for webcams??? I have come across libfg but am having trouble with that also? Any other ideas?
Oct 7 '08 #16

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Steven Burn | last post: by
2 posts views Thread by SBK | last post: by
1 post views Thread by Joris Kempen | last post: by
3 posts views Thread by mairhtin o'feannag | last post: by
2 posts views Thread by KemperR | last post: by
3 posts views Thread by hanz | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.