c++opencv获取编码的网络摄像头流
c++ opencv get encoded webcam stream
我目前正在从事一个项目,该项目从网络摄像头捕获视频,并通过UDP发送编码流以进行实时流传输。
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
return 0;
}
有人说从cap.read(frame)得到的帧已经是解码帧了,我不知道这是如何发生的,也不知道什么时候发生的。我想要的是编码的帧或流。我该怎么办才能拿到它?我应该重新编码吗?
根据文档,调用VideoCapture::read()
相当于先调用VideoCapture::grab()
,然后调用VideoCapture::retrieve()
。
Retrieve
函数的文档表示,它确实对帧进行了解码。
为什么不只是使用解码的帧;大概你会在远端解码吧?
OpenCV API不提供对编码帧的访问。
您将不得不使用更低级的库,可能依赖于设备和平台。如果您的操作系统是Linux,Video4Linux2
可能是一个选项,则必须有适用于Windows/MacOS的等效库。您还可以看看mjpg流媒体,它的功能与您想要实现的功能非常相似(仅在linux上)。
请注意,图像的确切编码将取决于您的网络摄像头,一些usb网络摄像头支持mjpeg压缩(甚至h264),但其他摄像头只能发送原始数据(通常在yuv颜色空间中)。
另一种选择是使用Opencv获取解码后的图像,并对其进行重新编码,例如使用imencode。它具有简单和便携的优点,但图像重新编码将占用更多的资源。
相关文章:
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 使用源读取器从网络摄像头源获取 H264 样本
- 为什么我不能让 3 个网络摄像头与 pthreads 并行运行?
- 从 OpenCV 3 切换到 OpenCV 4 会导致网络摄像头以最大 5 fps 的速度录制,而不是通常的 30 f
- 媒体基金会可以允许多个客户端同时访问单个网络摄像头设备吗?
- 从C++调用网络摄像头并在 Python 中显示图像
- 从 WinPE 下的网络摄像头捕获?
- OpenCV没有显示来自Macbook网络摄像头的视频
- 使用OpenCV和C++在按键上截取网络摄像头源的屏幕截图
- 我正在尝试在树莓派中连接两个网络摄像头
- 使用 FFmpeg 编码和带有网络摄像头的 UDP
- TensorFlow OpenCV网络摄像头悬挂
- 使用来自视频文件或网络摄像头的 Kinect 面部跟踪
- OpenCV 将剪影与网络摄像头流隔离
- OpenCV-从C/C++中的默认网络摄像头获取图片-GTK问题
- 在 OpenCV 中,设置曝光会导致我的网络摄像头软件无法自动调整曝光
- 无法使用OpenCV从辅助网络摄像头读取VideoCapture中的帧
- 使用Opencv直接从网络摄像头获取灰度图像
- 使用Qt显示来自OpenCV的网络摄像头流