#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QList<QCameraInfo> infos2 = QCameraInfo::availableCameras();
foreach(QCameraInfo info,infos2)
{
qDebug()<<info.deviceName()<<":"<<info.description();
ui->comboBox->addItem((info.deviceName()));
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//Mat image = imread("F:\\VS\\untitled5\\messi5.jpg"); //存放自己图像的路径
//if (image.empty())
//{
// printf("could not load image...\r\n");
//}
//imshow("显示图像", image);
// waitKey();
// destroyAllWindows();
// ui->setupUi(this);
QString StrWidth,StrHeigth;
QString filename="F:\\VS\\opencv_test\\messi5.jpg";
QImage* img=new QImage,* scaledimg=new QImage;//分别保存原图和缩放之后的图片
if(! ( img->load(filename) ) ) //加载图像
{
QMessageBox::information(this,
tr("打开图像失败"),
tr("打开图像失败!"));
delete img;
return;
}
int Owidth=img->width(),Oheight=img->height();
int Fwidth,Fheight; //缩放后的图片大小
ui->label->setGeometry(0,0,400,300);
int Mul; //记录图片与label大小的比例,用于缩放图片
if(Owidth/400>=Oheight/300)
Mul=Owidth/400;
else
Mul=Oheight/300;
Fwidth=Owidth/Mul;
Fheight=Oheight/Mul;
*scaledimg=img->scaled(Fwidth,Fheight,Qt::KeepAspectRatio);
ui->label->setPixmap(QPixmap::fromImage(*scaledimg));
}
void MainWindow::on_bstart_clicked()
{
ca2=new QCamera(ui->comboBox->currentText().toUtf8(),this);
ui->widget->show();
capture2 = new QCameraImageCapture(ca2);
connect(capture2,SIGNAL(imageCaptured(int,QImage)),this,SLOT(show_pic(int,QImage)));
QCameraViewfinder *v2 =new QCameraViewfinder(ui->widget);
v2->resize(ui->widget->size());
ca2->setViewfinder(v2);
v2->show();
ca2->start();
}
void MainWindow::on_bstop_clicked()
{
ca2->stop();
ui->widget->hide();
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Qt+opencv实现打开图片打开摄像头关闭摄像头源码,可供学习参考。 #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
资源推荐
资源详情
资源评论
收起资源包目录
基于Qt+opencv实现打开图片打开摄像头关闭摄像头源码.zip (8个子文件)
mainwindow.h 845B
mainwindow.cpp 3KB
Task.pro 2KB
main.cpp 183B
Task.pro.user 23KB
mainwindow.ui 3KB
messi5.jpg 71KB
opencv_videoio_ffmpeg460_64.dll 19.94MB
共 8 条
- 1
资源评论
GJZGRB
- 粉丝: 1075
- 资源: 5911
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功