标签:
最近在研究opencv。
把opencv获取摄像头数据调试成功。
一个简单的测试代码
mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QLabel> #include <QGridLayout> #include <QPushButton> #include <QComboBox> #include <QImage> //#include <core.hpp> //#include <imgproc.hpp> #include <highgui.h> #include <cv.h> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(); ~MainWindow(); private: QWidget* mainWindow; QGridLayout * mainLayout; QPushButton * buttonStart; QPushButton * buttonStop; QLabel * pictureCamera; QLabel * pictureProcess; CvCapture * pCapture; IplImage * pImage; void paintEvent(QPaintEvent *event); private slots : void startVideo(); void stopVideo(); }; #endif
mainwindow.c艹~
#include "mainwindow.h" #include <QPainter> #include <iostream> #include <sstream> #include <math.h> using namespace std; MainWindow :: MainWindow() { mainWindow = new QWidget; this->setCentralWidget(mainWindow); buttonStart = new QPushButton("START"); buttonStart->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); buttonStop = new QPushButton("STOP"); buttonStop->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); pictureCamera = new QLabel(); pictureProcess = new QLabel(); pCapture = cvCreateCameraCapture(0); pImage = cvQueryFrame(pCapture); mainLayout = new QGridLayout; mainLayout->addWidget(buttonStart,0,0,1,1); mainLayout->addWidget(buttonStop,0,1,1,1); mainLayout->addWidget(pictureCamera,1,0,5,5); mainLayout->addWidget(pictureProcess,1,5,5,5); mainWindow->setLayout(mainLayout); QObject::connect(buttonStart,SIGNAL(clicked()),this,SLOT(startVideo())); QObject::connect(buttonStop,SIGNAL(clicked()),this,SLOT(stopVideo())); this->setWindowTitle("beaglebone opencv test~"); this->resize(QSize(600,300)); } MainWindow :: ~MainWindow() { cvReleaseCapture(&pCapture); mainWindow->deleteLater(); mainLayout->deleteLater(); buttonStart->deleteLater(); buttonStop->deleteLater(); pictureCamera->deleteLater(); pictureProcess->deleteLater(); } void MainWindow::startVideo() { pImage = cvQueryFrame(pCapture); QImage showImage((const uchar *)pImage->imageData,pImage->width,pImage->height,QImage::Format_RGB888); pictureCamera->setPixmap(QPixmap::fromImage(showImage)); } void MainWindow::stopVideo() { } void MainWindow::paintEvent(QPaintEvent *event) { }
main.c艹
#include <QApplication> #include <QFont> #include "mainwindow.h" int main(int argc ,char* argv[]) { QApplication app(argc,argv); MainWindow myWindow; myWindow.show(); return app.exec(); }
效果
opencv+qt+beaglebone 之获取摄像头数据。
标签:
原文地址:http://www.cnblogs.com/hebaichuanyeah/p/4887268.html