Recently in the study of OpenCV.
The OpenCV gets the camera data debug successfully.
A simple test code
Mainwindow.h
#ifndef Mainwindow_h#defineMainwindow_h#include<QMainWindow>#include<QLabel>#include<QGridLayout>#include<QPushButton>#include<QComboBox>#include<QImage>//#include <core.hpp>//#include #include #include<cv.h>classMainWindow: Publicqmainwindow{Q_object Public: MainWindow (); ~MainWindow ();Private: Qwidget*MainWindow; Qgridlayout*mainlayout; Qpushbutton*Buttonstart; Qpushbutton*Buttonstop; Qlabel*Picturecamera; Qlabel*pictureprocess; Cvcapture*pcapture; Iplimage*Pimage; voidPaintEvent (Qpaintevent *Event);PrivateSlots:voidStartvideo (); voidStopvideo ();};#endif
MAINWINDOW.C 艹 ~
#include"mainwindow.h"#include<QPainter>#include<iostream>#include<sstream>#include<math.h>using namespacestd; MainWindow:: MainWindow () {MainWindow=NewQwidget; This-Setcentralwidget (MainWindow); Buttonstart=NewQpushbutton ("START"); Buttonstart-Setsizepolicy (qsizepolicy::fixed,qsizepolicy::fixed); Buttonstop=NewQpushbutton ("STOP"); Buttonstop-Setsizepolicy (qsizepolicy::fixed,qsizepolicy::fixed); Picturecamera=NewQlabel (); Pictureprocess=NewQlabel (); Pcapture= Cvcreatecameracapture (0); Pimage=Cvqueryframe (pcapture); Mainlayout=Newqgridlayout; 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 ( -, -)); }mainwindow::~MainWindow () {cvreleasecapture (&pcapture); MainWindow-Deletelater (); Mainlayout-Deletelater (); Buttonstart-Deletelater (); Buttonstop-Deletelater (); Picturecamera-Deletelater (); Pictureprocess-deletelater ();}voidMainwindow::startvideo () {pimage=Cvqueryframe (pcapture); Qimage ShowImage ((ConstUchar *) pimage->imagedata,pimage->width,pimage->height,qimage::format_rgb888); Picturecamera-Setpixmap (Qpixmap::fromimage (ShowImage));}voidMainwindow::stopvideo () {}voidMainWindow::p aintevent (Qpaintevent *Event){}
MAIN.C 艹
#include <QApplication><QFont>"mainwindow.h"int Main (int argc,Char* argv[]) { qapplication app (ARGC,ARGV); MainWindow Mywindow; Mywindow.show (); return app.exec ();}
Effect
The
Opencv+qt+beaglebone gets the camera data.