简体   繁体   English

制作无外部依赖的网络摄像头快照

[英]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?我正在使用一个非常有限的 Linux 系统,想知道如何在不使用 OpenCV 之类的库的情况下从网络摄像头(/dev/video0 等)制作快照? Can you work with the device file directly from C?您可以直接使用 C 中的设备文件吗? It's also perfectly ok if the code is platform specific, but a platform independent solution is preferred of course.如果代码是特定于平台的,那也完全没问题,但当然首选独立于平台的解决方案。

Eg 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;
}

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.是的,你可以这样做。如果你有幸拥有相机,其中 output 数据直接为 JPEG 格式,那么你可以直接将从设备读取的数据保存为文件。 Otherwise you had to write tons of code to convert value read from device file to convert to JPEG/PNG etc, which is worthless.否则,您必须编写大量代码来将从设备文件读取的值转换为 JPEG/PNG 等,这是毫无价值的。 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.最好的机会是使用Video4Linux api,这样您就不必依赖任何其他库。 And V4L supported by almost all popular linux distro and many fancy libraries using it underneath.几乎所有流行的 linux 发行版都支持 V4L,并且许多花哨的库都在下面使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM