-   Programming (
-   -   Reading frames from webcam? (

wossy 04-29-2006 01:10 PM

Reading frames from webcam?
Am I right in thinking that Linux treats devices like webcams as if they were files? So in theory i can just read x number of bytes from the fil and it would give me the image from he camera?

I'd like to read images off my webcam but I don't know where to find the file that it relates to. Its a standard USB generic webcam. Will Linux find it automatically?

Basically how do I find my webcam?

exvor 04-29-2006 01:26 PM

As long as there is a driver in the kernel yes this is correct. See in order for the device AKA a special file to be created in the /dev directory (this is considered the userspace interface for the device) a kernel driver needs to understand the data from the device and convert it to something that can be used in the userspace area.

U need to have a driver for the device and also have video for linux compiled into the kernel. There is a list in the kernel documentation about what web cams are supported. NOTE: Usually it will only list chipsets supported not the model and such. I had to actually tear mine apart to find the chip used just to find out it wasent supported :p. Good luck.

wossy 04-29-2006 02:48 PM

Thanks for the tips. I have checked out the webcam how-to and it appears that i do have the drivers needed for webcam usage. Also if I run dmesg a few times and unplug / reconnect the camera, it does see it...

Boot video device is 0000:01:00.0
Linux video capture interface: v1.00
usb 1-3.1: V4L2 device registered as /dev/video0
usb 1-3.1: V4L2 device /dev/video0 deregistered
usb 1-3.1: V4L2 device registered as /dev/video0

lsmod also seems to have the driver up and running.

Am I riht in thinking that /dev/video0 is the file I should be reading? I have tried to read this file through code but I get an exception ("Disk full. Path /dev/video0").

ls reports the file to be zero bytes long.

I'd love to get this working (as it would be 100000 easier than doing the same thing in windows, the WIN32 API is a complete nightmare as far as webcams are concerned).

Any thoughts would be gratefully received.

Thanks again.

exvor 04-29-2006 03:06 PM

What programming code are you using.

Others with more expiance reading from a device rather then a file would probably be more helpfull then me but in C you would want to open the file as readonly. example code

FILE *cameradata;

cameradata = fopen("/dev/video0","r");

/* You would probably want to only grab a assiened amount of data
from the camera or however the assoicated driver works */

more then likely there is something more complicated your going to have to do like passing information back to the camera to make it grab a picture and transmit it back in a understandable format. Ive never done complicated programs like this before so im kinda in the dark. Mabye somone else here has an idea.

wossy 04-30-2006 05:02 AM

I'm just trying to open the file as a stream (C#)...

PHP Code:

public static int Main(string[] args)
//Application.Run(new frmMain(args));
Console.Write("Opening webcam: ");
FileStream fs = new FileStream("/dev/video0"FileMode.OpenFileAccess.ReadFileShare.None);
Console.WriteLine("OK - Bytes waiting: " fs.Length);
        catch (
Exception ex)
Console.WriteLine("Failed - couldn't open file...\n\n" ex.Message "\n\n");
Console.WriteLine("Failed - file not found.");
0//end sucessfully

I'm not actually trying to read any bytes out at the moment, just open it and try to see how much data is waiting on the stream. I'll try something else in he meantime.

freegianghu 04-30-2006 12:00 PM

Searching Video4Linux topic may help you much.

All times are GMT -5. The time now is 10:19 AM.