ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.