opencv+qt+beaglebone 之获取摄像头数据。

最近在研究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();
}

 

效果

 

转载于:https://www.cnblogs.com/hebaichuanyeah/p/4887268.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值