概述
第一步 在XXX.pro中添加
INCLUDEPATH +=/usr/local/include/opencv
/usr/local/include/opencv2
LIBS += /usr/local/lib/libopencv_calib3d.so
/usr/local/lib/libopencv_contrib.so
/usr/local/lib/libopencv_core.so
/usr/local/lib/libopencv_features2d.so
/usr/local/lib/libopencv_flann.so
/usr/local/lib/libopencv_gpu.so
/usr/local/lib/libopencv_highgui.so
/usr/local/lib/libopencv_imgproc.so
/usr/local/lib/libopencv_legacy.so
/usr/local/lib/libopencv_ml.so
/usr/local/lib/libopencv_objdetect.so
/usr/local/lib/libopencv_ts.so
/usr/local/lib/libopencv_video.so
第二 QT界面设置
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "opencv2/core/core.hpp"
#include"opencv2/highgui/highgui.hpp"
#include"opencv/cv.h"
#include"opencv/highgui.h"
#include<QFileDialog>
#include<QPixmap>
#include<QImage>
#include<QLabel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_open_clicked()
{
CvCapture *capture = NULL;// 视频获取结构, 用来作为视频获取函数的一个参数
capture = cvCreateCameraCapture(0);//打开摄像头,从摄像头中获取视频
IplImage* frame;//申请IplImage类型指针,就是申请内存空间来存放每一帧图像
while(1) {
frame = cvQueryFrame( capture );// 从摄像头中抓取并返回每一帧
if( !frame ) break;
QImage *image;
uchar *imgData=(uchar *)frame->imageData;
image=new QImage(imgData,frame->width,frame->height,QImage::Format_RGB888);
ui->QImgShow->resize(frame->width/3,frame->height/3);
ui->QImgShow->setPixmap(QPixmap::fromImage(*image).scaled(ui->QImgShow->size()));
char c = cvWaitKey(33);//延时,每秒钟约33帧;符合人眼观看速度;
if( c == 27 ) break;//由于是死循环,而且没有控制台,当按下键盘exc键,退出循环;
}
cvReleaseCapture( &capture );//释放内存;
}
void MainWindow::on_close_clicked()
{
}
最后
以上就是负责铃铛为你收集整理的ubuntu下QT+OpenCV控制摄像头通过label 显示的全部内容,希望文章能够帮你解决ubuntu下QT+OpenCV控制摄像头通过label 显示所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复