Martin Gergov
Martin Gergov

Reputation: 1660

Make a webcam snapshot without external dependencies

I'm working with a very limited Linux system and would like to know how one could make a snapshot from a webcam(/dev/video0 etc.) without using libraries like OpenCV ? Can you work with the device file directly from C ? It's also perfectly ok if the code is platform specific, but a platform independent solution is preferred of course.

E.g. something like:

int main(int argc, char *argv[])
{
    int f;
    unsigned short result[640][480]; 

    f = open("/dev/video0", MODE);
    snapshot(f, result, 640, 480, COLOR_SCHEME);
    return 0;
}

Upvotes: 1

Views: 212

Answers (1)

Manthan Tilva
Manthan Tilva

Reputation: 3277

Yes, you can do that.If you are lucky to have camera which output data directly as JPEG format then you directly save data read from device as file. Otherwise you had to write tons of code to convert value read from device file to convert to JPEG/PNG etc, which is worthless. But there are very few such cameras and I haven't seen any integrated webcam with laptop with such feature.(But may there are some which haven't come across).

Your best chance is to use Video4Linux api, so you don't have to depend on any other library. And V4L supported by almost all popular linux distro and many fancy libraries using it underneath.

Upvotes: 1

Related Questions