Is this possible rotate Camera in GUI?
-
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! -
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?
-
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?
-
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!@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_Hframeprocess.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);