• 2678阅读
  • 2回复

基于opencv的图像采集,用qt显示 [复制链接]

上一主题 下一主题
离线yuanye
 

图酷模式  只看楼主 正序阅读 楼主  发表于: 2019-11-05
大家好
imax6q的板子,5.9.5的qt creator,kernel 4.1.15

我用opencv采集v4l2的摄像头,然后用qt的label显示出来。目前可以显示,但是感觉图像有追帧。


下面附上部分代码


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    cout << "####### step 1 ###########" <<endl;

thread1 = new myThread;


    videoMode = 0;
    connect(&theTimer, &QTimer::timeout, this, &MainWindow::updateImage);   //QBasicTimer
    connect(ui->buttonCapture, SIGNAL(clicked()), this, SLOT(captureImage()));
    connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveImage()));
    connect(ui->buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
    connect(this, SIGNAL(openMenuMsg()), this, SLOT(openMenuEvent()));
    connect(this, SIGNAL(hideMenuMsg(int)), this, SLOT(hideMenuEvent(int)));
    connect(this, SIGNAL(upItemMsg(int)), this, SLOT(upItemEvent(int)));
    connect(this, SIGNAL(downItemMsg(int)), this, SLOT(downItemEvent(int)));
    connect(this, SIGNAL(openSecMenuMsg()), this, SLOT(openSecMenuEvent()));
    connect(this, SIGNAL(videoModeSwitMsg(int)), this, SLOT(videoModeSwitEvent(int)));
    connect(this, SIGNAL(openTrdMenuMsg()), this, SLOT(openTrdMenuEvent()));

    if(videoMode == 0)
        cam.open("imxv4l2src device=/dev/video2 ! videoconvert ! appsink");// ! videoconvert ! appsink
//         cam.open("/dev/video2");
    else if(videoMode == 1)
        cam.open("imxv4l2src device=/dev/video1 ! videoconvert ! appsink");
    if (!cam.isOpened())        // check if we succeeded
    {
        cout << "####### step cannot open camera ###########" <<endl;
        exit(0);
    }

    cout << "w is " << cam.get(CV_CAP_PROP_FRAME_WIDTH) << "h is "<< cam.get(CV_CAP_PROP_FRAME_HEIGHT) << endl;
    double rate = cam.get(CV_CAP_PROP_FPS);
    cout<<"帧率为:"<<rate<<endl;

    cout<<"thread end"<<endl;

    {
        input_image = Mat::zeros(cam.get(CV_CAP_PROP_FRAME_HEIGHT), cam.get(CV_CAP_PROP_FRAME_WIDTH), CV_8UC3);

        theTimer.start(20);//20   3


        /***********************************************/
        /***********************************************/


    }
    cout << "####### step 2 ###########" <<endl;
    imageLabel = new QLabel(this);
    ui->ImageView->addWidget(imageLabel);
    ui->ImageCapture->setScaledContents(true);
    ui->listWidget->hide();
    ui->listWidget_2->hide();
    ui->listWidget_3->hide();
    ui->listWidget_IR->hide();




感谢各位
离线guanxian0907

只看该作者 2楼 发表于: 2022-01-02
离线big_mouse

只看该作者 1楼 发表于: 2020-04-14
快速回复
限100 字节
 
上一个 下一个