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 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.

    Chris KawaC 1 Reply Last reply
    0
    • B BigBen

      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.

      Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 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 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?

        JonBJ 1 Reply Last reply
        0
        • B BigBen

          @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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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

          • Login

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