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. Digital zoom for live stream
QtWS25 Last Chance

Digital zoom for live stream

Scheduled Pinned Locked Moved Unsolved General and Desktop
rtspdigital-zoomcameraopencvc++
4 Posts 3 Posters 750 Views
  • 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.
  • B Offline
    B Offline
    BigBen
    wrote on 22 Jun 2022, 04:17 last edited by BigBen
    #1

    Hi.

    I am live streaming (rtsp) from a camera and displaying the stream on a label with the following code:

    capture >> frame;
    cvtColor(frame, frame, cv::COLOR_BGR2BGRA);
    QImage image = (const unsigned char*)(frame.data), frame.cols, frame.rows, QImage::Format_RGB888;
    ui->label->setPixmap(QPixmap::fromImage(image).scaled(ui->label->width(), ui->label->height(), Qt::KeepAspectRatio));
    

    Now, I want to implement digital zoom for the stream with a button. Is there a way I can do that? I read that QCameraFocus might help with this. But QCameraFocus class is not available in Qt 6.3.0. Is there a solution for Qt 6.3.0? or using opencv maybe.

    C 1 Reply Last reply 22 Jun 2022, 06:51
    0
    • B BigBen
      22 Jun 2022, 04:17

      Hi.

      I am live streaming (rtsp) from a camera and displaying the stream on a label with the following code:

      capture >> frame;
      cvtColor(frame, frame, cv::COLOR_BGR2BGRA);
      QImage image = (const unsigned char*)(frame.data), frame.cols, frame.rows, QImage::Format_RGB888;
      ui->label->setPixmap(QPixmap::fromImage(image).scaled(ui->label->width(), ui->label->height(), Qt::KeepAspectRatio));
      

      Now, I want to implement digital zoom for the stream with a button. Is there a way I can do that? I read that QCameraFocus might help with this. But QCameraFocus class is not available in Qt 6.3.0. Is there a solution for Qt 6.3.0? or using opencv maybe.

      C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 22 Jun 2022, 06:51 last edited by
      #2

      @BigBen said:

      ui->label->setPixmap(QPixmap::fromImage(image).scaled(ui->label->width(), ui->label->height(), Qt::KeepAspectRatio));

      This makes multiple copies of the data and is unnecessarily slow.
      Replace the label with a plain QWidget and override its paintEvent. Use QPainter there to draw the image directly, without converting it to pixmap and then scaling. QPainter lets you draw the image with any transformation you want, so you can do zoom, pan, rotation, mirroring and more.

      1 Reply Last reply
      3
      • B Offline
        B Offline
        BigBen
        wrote on 22 Jun 2022, 07:20 last edited by BigBen
        #3

        @Chris-Kawa Thanks you for your answer.
        How should I override the paintEvent function, and what to write in the overridden one? Do I need to make a new class?

        J 1 Reply Last reply 22 Jun 2022, 07:47
        0
        • B BigBen
          22 Jun 2022, 07:20

          @Chris-Kawa Thanks you for your answer.
          How should I override the paintEvent function, and what to write in the overridden one? Do I need to make a new class?

          J Offline
          J Offline
          JonB
          wrote on 22 Jun 2022, 07:47 last edited by
          #4

          @BigBen
          Yes, you always need to write a new class which derives from the base class if you need to override a virtual method, as QWidget::paintEvent().

          The Analog Clock Example illustrates overriding paintEvent(). There will be hundreds of other examples online.

          1 Reply Last reply
          1

          4/4

          22 Jun 2022, 07:47

          • Login

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