Qt5和opencv常用函数

convert Mat to QImage
1 void MainWindow::nextFrame()
2 {
3     camera>>frame;//已在头文件里声明camera和frame
4     if(!frame.empty())
5     {
6         image=Mat2QImage(frame);
7         ui->label->setPixmap(QPixmap::fromImage(image));
8     }
9 }
取一帧,并把其展示到label
 1 void MainWindow::on_pushButton_2_clicked()
 2 {
 3     if (capture.isOpened())
 4            capture.release();     //decide if capture is already opened; if so,close it
 5        capture.open(0);           //open the default camera
 6        if (capture.isOpened())
 7        {
 8            rate= capture.get(CV_CAP_PROP_FPS);
 9            capture >> frame;
10            if (!frame.empty())
11            {
12 
13                image = Mat2QImage(frame);
14                ui->label->setPixmap(QPixmap::fromImage(image));
15                QTimer *timer = new QTimer(this);
16                timer->setInterval(1000/rate);   //set timer match with FPS
17                connect(timer, SIGNAL(timeout()), this, SLOT(nextFrame()));
18                timer->start();
19            }
20        }
21 }
摄像头预览函数

 

posted on 2018-12-01 20:25  墨飞飞 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/Songhe/p/10050874.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值