Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Modify frames from Camera/Video before displaying
Forum Updated to NodeBB v4.3 + New Features

Modify frames from Camera/Video before displaying

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    If you want minimal perturbation, you have to go low level and do your preprocessing in advance thus pre-loading frames to have enough time to apply your operations. You'll have to benchmark things. You can't expect something nice if it requires 100ms per frame for a movie at 24fps.

    What kind of operations do you have in mind ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    M 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      If you want minimal perturbation, you have to go low level and do your preprocessing in advance thus pre-loading frames to have enough time to apply your operations. You'll have to benchmark things. You can't expect something nice if it requires 100ms per frame for a movie at 24fps.

      What kind of operations do you have in mind ?

      M Offline
      M Offline
      magicstar
      wrote on last edited by
      #3

      @SGaist ,
      As of now, I plan to apply

      1. Kalman filter
      2. Color detection
      3. Smoothing, etc.

      In Opencv, these algorithms do work at 24 fps. The major delay is converting from QVideoFrame to OpenCV Mat.

      I want to avoid this conversion time

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        What about doing it the other way around, do everything with OpenCV and only the display at the end with Qt ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        2
        • SGaistS SGaist

          What about doing it the other way around, do everything with OpenCV and only the display at the end with Qt ?

          M Offline
          M Offline
          magicstar
          wrote on last edited by
          #5

          @SGaist ,
          I am have Opencv based VideoPlayer using both Thead and Timer based approach. However, I face following issues:

          1. How much delay should I give. If exact delay is given as below:
            45 secs video would finish in 55 secs to be approx without any operations. I don't understand how can I minimize this delay.
          int delay = (1000/frameRate);
              while(!stop){
                  if (!capture.read(frame))
                  {
                      stop = true;
                  }
                  if (frame.channels()== 3){
                      cv::cvtColor(frame, RGBframe, CV_BGR2RGB);
                      img = QImage((const unsigned char*)(RGBframe.data),
                                        RGBframe.cols,RGBframe.rows,QImage::Format_RGB888);
                  }
                  else
                  {
                      img = QImage((const unsigned char*)(frame.data),
                                           frame.cols,frame.rows,QImage::Format_Indexed8);
                  }
                  emit processedImage(img);
                  QThread::msleep(delay);
              }
          
          1. Sync with audio. I see some solutions using opencv SDL. However, I am currently overwhelmed with situations and not exactly sure which way to go.
          A 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            How are you reading the audio data with OpenCV ?
            I just realize something, IIRC, there are frame format that allows construction without copy of the data. Did you check that ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply
            0
            • SGaistS SGaist

              How are you reading the audio data with OpenCV ?
              I just realize something, IIRC, there are frame format that allows construction without copy of the data. Did you check that ?

              M Offline
              M Offline
              magicstar
              wrote on last edited by
              #7

              @SGaist said in Modify frames from Camera/Video before displaying:

              IIRC

              My mistake. ffmpeg is used to read audio and OpenCV to read video.

              there are frame format that allows construction without copy of the data

              • I am not sure which frame format you are saying and how it would help resolve the issue.
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                It looks like ffmpeg is directly supported by OpenCV. Did you check that ?

                As for the format, if using something like RGB 8 bit, you will have data that are following the same memory layout be it for OpenCV Mat or QImage so no conversation needed.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply
                0
                • SGaistS SGaist

                  It looks like ffmpeg is directly supported by OpenCV. Did you check that ?

                  As for the format, if using something like RGB 8 bit, you will have data that are following the same memory layout be it for OpenCV Mat or QImage so no conversation needed.

                  M Offline
                  M Offline
                  magicstar
                  wrote on last edited by
                  #9

                  @SGaist

                  I saw that post and there are few tutorials for audio video sync with opencv.

                  However, for opencv Mat to QImg, I need to call BGR to RGB converter. There is still some delay.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    Are you using OpenCV to do that conversion ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    M 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Are you using OpenCV to do that conversion ?

                      M Offline
                      M Offline
                      magicstar
                      wrote on last edited by
                      #11

                      @SGaist
                      I have tried both OpenCV convert and rgbswapped of QT. There is not much difference in performance

                      1 Reply Last reply
                      0
                      • M magicstar

                        @SGaist ,
                        I am have Opencv based VideoPlayer using both Thead and Timer based approach. However, I face following issues:

                        1. How much delay should I give. If exact delay is given as below:
                          45 secs video would finish in 55 secs to be approx without any operations. I don't understand how can I minimize this delay.
                        int delay = (1000/frameRate);
                            while(!stop){
                                if (!capture.read(frame))
                                {
                                    stop = true;
                                }
                                if (frame.channels()== 3){
                                    cv::cvtColor(frame, RGBframe, CV_BGR2RGB);
                                    img = QImage((const unsigned char*)(RGBframe.data),
                                                      RGBframe.cols,RGBframe.rows,QImage::Format_RGB888);
                                }
                                else
                                {
                                    img = QImage((const unsigned char*)(frame.data),
                                                         frame.cols,frame.rows,QImage::Format_Indexed8);
                                }
                                emit processedImage(img);
                                QThread::msleep(delay);
                            }
                        
                        1. Sync with audio. I see some solutions using opencv SDL. However, I am currently overwhelmed with situations and not exactly sure which way to go.
                        A Offline
                        A Offline
                        anil_arise
                        wrote on last edited by anil_arise
                        #12

                        @magicstar this is example with openCV to modify frames:

                        cv::VideoCapture CaptureVideo;
                        bool val = CaptureVideo.open(videoFile.toStdString());
                        if(CaptureVideo.isOpened())
                        {
                            while(1)
                            {
                                if(isFinished || isStopped)
                                {
                                    CaptureVideo.release();
                                    break;
                                }
                                cv::Mat frame;
                                CaptureVideo >> frame;
                                if(!frame.empty())
                                {
                                    QImage qimg(frame.data,
                                                frame.cols,
                                                frame.rows,
                                                frame.step,
                                                QImage::Format_RGB888);
                                    // Editing frame with date and time or color change etc.. 
                                    {
                                        // qimg.fill(Qt::red);
                                        QPainter p;
                                        if (!p.begin(&qimg))
                                            qDebug()<<"Not";
                                        p.setPen(QPen(Qt::yellow));
                                        // p.setOpacity(0.5);
                                        p.setFont(QFont("Times", 18, QFont::Bold));
                                        p.drawText(qimg.rect(), Qt::AlignVertical_Mask, "  "+QDateTime::currentDateTime().toString("ddd MMMM dd yyyy  HH:mm:ss"));
                                        p.end();
                                    }
                                }
                            }
                        }
                        
                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved