当前位置:网站首页>ffmpeg AVFrame 转 cv::Mat
ffmpeg AVFrame 转 cv::Mat
2022-07-01 18:45:00 【lcyw】
//AVFrame 转 cv::mat
cv::Mat frame_to_mat(const AVFrame * frame) {
int width = frame->width;
int height = frame->height;
cv::Mat image(height, width, CV_8UC3);
int cvLinesizes[1];
cvLinesizes[0] = image.step1();
if( NULL == _swsContext) {
_swsContext = sws_getContext(width, height,
(AVPixelFormat)frame->format, width, height,
AVPixelFormat::AV_PIX_FMT_BGR24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
}
sws_scale(_swsContext, frame->data,
frame->linesize, 0, height, &image.data, cvLinesizes);
return image;
}
上面函数传入的参数frame中的图像格式,可以是YUV, RGB ,等等,,
经过sws_scale()转换之后,写入cv::Mat 数据区。
还有一种方式 是直接将AVFrame 中的RGB数据赋值给cv::Mat
cv::Mat img;
img = cv::Mat(height, width, CV_8UC3);
img.data = _rgb_frame->data[0];
边栏推荐
- EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
- Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
- 采集抖音视频
- Getting started with kubernetes command (namespaces, pods)
- MySQL common graphics management tools | dark horse programmers
- 【To .NET】C#集合类源码解析
- 原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
- 【pytorch记录】模型的分布式训练DataParallel、DistributedDataParallel
- B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
- 为什么一定要从DevOps走向BizDevOps?
猜你喜欢

sql查询去重统计的方法总结

Dlib+opencv library for fatigue detection

ddr4测试-2

Chaos engineering platform chaosblade box new heavy release

Detailed explanation of JUnit unit test framework

Junit单元测试框架详解

What must be done in graduation season before going to Shanhai

Lake Shore continuous flow cryostat transmission line

Nacos configuration file publishing failed, please check whether the parameters are correct solution

XML语法、约束
随机推荐
Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
数字化转型企业成功的关键,用数据创造价值
kubernetes命令入门(namespaces,pods)
白盒加密技术浅理解
Collation of open source protocols of open source frameworks commonly used in Web Development
宝,运维100+服务器很头疼怎么办?用行云管家!
web开发常用的开源框架的开源协议整理
Nacos configuration file publishing failed, please check whether the parameters are correct solution
CMU AI PhD 第一年总结
Lake Shore—CRX-EM-HF 型低温探针台
sql查询去重统计的方法总结
[go ~ 0 to 1] day 4 June 30 defer, structure, method
【pytorch记录】自动混合精度训练 torch.cuda.amp
PostgreSQL varchar[] 数组类型操作
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
Lake Shore M91快速霍尔测量仪
axure不显示元件库
[pytorch record] automatic hybrid accuracy training torch cuda. amp
[pytorch record] distributed training dataparallel and distributeddataparallel of the model