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. Is this possible rotate Camera in GUI?
Qt 6.11 is out! See what's new in the release blog

Is this possible rotate Camera in GUI?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 817 Views 1 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.
  • H Offline
    H Offline
    haobo
    wrote on last edited by
    #1

    I test the Camera example from this website which is also the offical example of Qt.
    It works but I want to do some processing on live-image like rotating ,cropping, inverse and so on. I read the Doc. the part of QCamera and QCameraviewfinder, but i did not find any functions which could enable these requiments. Am I missing something, or is this not possible. If this is not possible, is there another approach (like using the Opecv API?) Thanks in advance!

    Z 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      the best option is always to use a camera that can natively rotate the frame, to avoid having to do software filtering. based on OP feature request, I wouldn't consider Qt the place to do that stuff. Maybe openCV?

      The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thomas Red
        wrote on last edited by
        #3

        To avoid using software filtering, it is usually preferable to utilize a camera that can rotate the frame naturally. I wouldn't think of Qt as the place to do that item based on the OP's feature request. perhaps openCV?

        1 Reply Last reply
        0
        • H haobo

          I test the Camera example from this website which is also the offical example of Qt.
          It works but I want to do some processing on live-image like rotating ,cropping, inverse and so on. I read the Doc. the part of QCamera and QCameraviewfinder, but i did not find any functions which could enable these requiments. Am I missing something, or is this not possible. If this is not possible, is there another approach (like using the Opecv API?) Thanks in advance!

          Z Offline
          Z Offline
          zare
          wrote on last edited by
          #4

          @haobo it is easy.
          create a class Inherits QAbstractVideoSurface as QCamera's viewfinder.
          you can dowith images in this class.
          next is my example:
          frameprocess.h

          #ifndef FRAMEPROCESS_H
          #define FRAMEPROCESS_H
          
          #include <QAbstractVideoSurface>
          
          class FrameProcess : public QAbstractVideoSurface
          {
              Q_OBJECT
          public:
              explicit FrameProcess(QObject *parent = nullptr);
          protected:
              QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const;
              bool present(const QVideoFrame &frame);
          signals:
              void sendIMG(QImage img);
          };
          
          #endif // FRAMEPROCESS_H
          

          frameprocess.cpp

          #include "frameprocess.h"
          
          FrameProcess::FrameProcess(QObject *parent) : QAbstractVideoSurface(parent)
          {
              this->setNativeResolution(QSize(800,600));
          }
          
          QList<QVideoFrame::PixelFormat> FrameProcess::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const
          {
              QList<QVideoFrame::PixelFormat> pixelformats;
              pixelformats.append(QVideoFrame::Format_RGB32);
              pixelformats.append(QVideoFrame::Format_YUV420P);
              return pixelformats;
          }
          
          bool FrameProcess::present(const QVideoFrame &frame)
          {
              QVideoFrame copy(frame);
              if(copy.isValid()){
                  copy.map(QAbstractVideoBuffer::ReadOnly);
                  QImage img(copy.bits(),copy.width(),copy.height(),QVideoFrame::imageFormatFromPixelFormat(copy.pixelFormat()));
                  QMatrix mat;
                  mat.rotate(180);
                  img = img.transformed(mat,Qt::FastTransformation);
                  emit sendIMG(img);
                  return true;
              }
              return false;
          }
          

          widget.h

          private:
              Ui::Widget *ui;
              QCamera *camera=Q_NULLPTR;
              QCameraImageCapture *imageCapture=Q_NULLPTR;
              FrameProcess *frame=Q_NULLPTR;
          

          widget.cpp

          camera = new QCamera(this);
              frame = new FrameProcess(this);
              connect(frame,&FrameProcess::sendIMG,this,&Widget::displayCamera);
              camera->setViewfinder(frame);
          
          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