LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-29-2006, 01:10 PM   #1
wossy
LQ Newbie
 
Registered: Mar 2006
Location: Derby
Distribution: Fedora Core 4
Posts: 7

Rep: Reputation: 0
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?
 
Old 04-29-2006, 01:26 PM   #2
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
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 . Good luck.

Last edited by exvor; 04-29-2006 at 01:28 PM.
 
Old 04-29-2006, 02:48 PM   #3
wossy
LQ Newbie
 
Registered: Mar 2006
Location: Derby
Distribution: Fedora Core 4
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 04-29-2006, 03:06 PM   #4
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
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
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.
 
Old 04-30-2006, 05:02 AM   #5
wossy
LQ Newbie
 
Registered: Mar 2006
Location: Derby
Distribution: Fedora Core 4
Posts: 7

Original Poster
Rep: Reputation: 0
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: ");
    if(
File.Exists("/dev/video0"))
    {
        try
        {
            
FileStream fs = new FileStream("/dev/video0"FileMode.OpenFileAccess.ReadFileShare.None);
            
Console.WriteLine("OK - Bytes waiting: " fs.Length);
            
fs.Close();
        }
        catch (
Exception ex)
        {
            
Console.WriteLine("Failed - couldn't open file...\n\n" ex.Message "\n\n");
        }
    }
    else
    {
        
Console.WriteLine("Failed - file not found.");
    }
    return 
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.
 
Old 04-30-2006, 12:00 PM   #6
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Searching Video4Linux topic may help you much.
 
  


Reply

Tags
camera, device, file, frames, io, mono, video, webcam



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Install A Usb Webcam [Genius WebCam on Suse 9.1 Personal] ofvergara SUSE / openSUSE 4 11-29-2006 12:09 PM
I want to veiw my friends webcam, im using Lycoris, how do i c his webcam? CaffeinatedGamer Linux - Newbie 10 06-07-2005 07:23 PM
Possible to create a frames effect in an HTML page without using frames? furfurdemon666 General 10 12-12-2004 06:52 AM
How to capture live Video frames from webcam Madhukar Linux - General 0 04-14-2004 07:31 AM
How to capture video frames form webcam Madhukar Linux - Software 0 04-14-2004 07:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration