Opencv - based image acquisition, qt display
Everybody is good
Imax6q board, qt creator of 5.9.5, kernel 4.1.15
I collect the camera of v4l2 with opencv and display it with the label of qt.Currently it can be displayed, but it feels like the image has a chase frame.
Part of the code is attached below
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();
thank you