Ask Your Question

Revision history [back]

Removing lag from camera video stream using Opencv/Gstreamer

I have a camera application that will display the cameras live stream:

void MainWindow::on_start() {

if(video.isOpened())
{

    video.release();
    return;
}

if(!isCameraFound || !video.open(pipeline.trimmed().toStdString(), cv::CAP_GSTREAMER))
{
    QMessageBox::critical(this,
                            "Video Error",
                            "Must be the correct USB Camera connected!");
    return;
}



Mat frame;
while(video.isOpened())
{
    video >> frame;


    if(!frame.empty())
    {
        QImage qimg(frame.data,
                    frame.cols,
                    frame.rows,
                    frame.step,
                    QImage::Format_RGB888);
        pixmap.setPixmap( QPixmap::fromImage(qimg.rgbSwapped()) );
        ui->graphicsView->fitInView(&pixmap, Qt::KeepAspectRatio);
    }

...

And I have a function that does processing and has a loop to inspect the first 250 frames because the camera gives off a specific frame when something is found. But when doing this loop the videostream lags so much it basically freezes until the loop is done. How would I be able to go about removing the lag caused by the frame grabbing loop to be able to go through the loop and have the videostream not lag?

void MainWindow::on_push() { Mat test;

for(int i = 0; i < 250; i++){

    video >> test;

...