当前位置:网站首页>V4L2+QT视频优化策略
V4L2+QT视频优化策略
2022-06-26 00:23:00 【爱学习的诸葛铁锤】
问题描述
之前写了这样一篇文章: V4L2+QT+USB摄像头实时显示视频(Arm,Linux,window均适用)
程序运行在Linux系统中,视频不掉帧,显示很稳定;但是编译之后运行在Arm9开发板时,能感到明显的延迟
解决问题过程中发现这样一个论坛: Qt用QLabel来显示摄像头,CPU占用率过高的问题,定时器变不准
总结一下内容:
- QLabel控件不适合做频繁刷新的图像显示,没有效率;
- 可以开多线程来解决显示问题
- 可用QPixmap+QPainter替代QLabel控件
不妨尝试用多线程+QPainter来显示视频帧
编程
QPainter显示图像
首先是QPainter显示图像,先学习一下 QPainter Class,核心代码
/* 显示的每帧图像 */
QImage img;
/* 重写父类下的protected方法*/
protected:
void paintEvent(QPaintEvent *);
......
void videoshow::paintEvent(QPaintEvent *){
try{
QPainter painter(this);
if(!img.isNull()){
painter.drawImage(QPointF(0,0),img);
}
}catch(...){
}
}
这里选择不缩放显示图像,参考以下函数

QThread线程开启
官方文档: QThread Class
QT使用线程主要有两种方法,其中之一就是继承QThread,然后重写run()的方法
class V4l2Thread : public QThread{
public:
explicit V4l2Thread(QWidget *parent = 0);
~V4l2Thread();
/* QThread 虚函数 run */
void run();
}
void V4l2Thread::run(){
/* V4l2的编程就可以写在`run()`函数中 */
}
线程的启动start(),线程的销毁destroyed()
/* 实例化V4l2Thread */
t = new V4l2Thread();
......
t.start();
......
t->destroyed();
边栏推荐
- Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou
- CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
- CS144 环境配置
- readv & writev
- LeetCode 31 ~ 40
- Abnova丨CSV 单克隆抗体解决方案
- What happens from entering a web address in the browser's input box to seeing the contents of the web page?
- PTA class a simulated seventh bomb: 1160-1163
- Focal loss
- GUN make (7) 执行make
猜你喜欢

阳光男孩陈颢天 受邀担任第六季完美童模全球总决赛代言人

通俗易懂C语言关键字static

Explication du script correspondant à l'assertion Postman

Pointnet/Pointnet++学习

GNN (graph neural network) introduction vernacular

Disruptor(一)Sequence

recvmsg & sendmsg

How to add a "security lock" to the mobile office of government and enterprises?

CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕

Postman斷言對應脚本的解釋
随机推荐
LeetCode 41 ~ 50
PTA class a simulated seventh bomb: 1160-1163
Cs144 environment configuration
丨EGFR FISH 探针解决方案
Input 3 integers and output them from large to small
User unlock status query
Finding the sum of N multiplications
readv & writev
biggan:large scale gan training for high fidelity natural image synthesis
LeetCode 31 ~ 40
wifi 的理论速度计算方法
Difference between app test and web test
recv & send
清甜女孩李斯霞 受邀担任第六季完美童模全球总决赛小主持人
PTA class a simulated second bullet: 1136-1139
Redis7.0的安装步骤
Abnova丨CSV 单克隆抗体解决方案
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou
Perfdog
LeetCode 31 ~ 40