简体   繁体   English

如何在C ++中读取网络摄像头的输入?

[英]How to read input from a webcam in C++?

is it possible to read data from a generic webcam in C++ as you would from a stream object? 是否可以像在流对象中那样从C ++中的通用网络摄像头读取数据? Is there a common API or standard that works with all webcams? 是否有适用于所有网络摄像头的通用API或标准?

I'm talking about C++ in *nix environment. 我在* nix环境中谈论C ++。

Thanks in advance. 提前致谢。

For linux, V4L . 对于linux, V4L AFAIR, BSD uses the same codebase. AFAIR,BSD使用相同的代码库。 I do not know about the others... 我不知道其他人......

In Linux, webcams are supported using Video4Linux . 在Linux中,使用Video4Linux支持网络摄像头。 Take a look at the userspace API and an Video4Linux introduction . 查看用户空间APIVideo4Linux简介

您可能想检查网络摄像头是否与TWAIN兼容,并使用他们的api来做到这一点。

First find out if the web cam streams video or not? 首先找出网络摄像头是否流式传输视频? Typically they would stream the video to a particular port. 通常,他们会将视频流式传输到特定端口。 You can then open a Socket in C++ on that port and get the video data. 然后,您可以在该端口上打开C ++中的Socket并获取视频数据。 Most webcams should be able to do this. 大多数网络摄像头应该能够做到这一点。

The main thing here is you need to understand what video format does the webcam use and how to process it. 这里最重要的是您需要了解网络摄像头使用的视频格式以及如何处理它。 Silverlight or DirectX will help as they can directly listen at the particular port, but you have not mentioned which OS you are using. Silverlight或DirectX将有所帮助,因为他们可以直接在特定端口侦听,但您没有提到您正在使用的操作系统。

In case the web cam does not stream it should at least have the feature to save video to a file. 如果网络摄像头不流,它至少应具有将视频保存到文件的功能。 In this case also find out the video format and that should help you decide which API to use. 在这种情况下,还要找出视频格式,这应该可以帮助您决定使用哪种API。

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

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