What is the proper solution to process the frame of camera on android?
Unsolved
Mobile and Embedded
-
Qt5.9.1
os : win 10 64bits
Android sdk : 19
Phone : GTS-6310
android version : 4.1.2I am trying to process camera frame of android by QCamera and QAbstractVideoSurface. What I try
class camera_frame_grabber : public QAbstractVideoSurface { Q_OBJECT public: camera_frame_grabber(QObject *parent = nullptr); QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override; bool present(const QVideoFrame &frame) override; signals: void frame_available(QImage frame); }; camera_frame_grabber::camera_frame_grabber(QObject *parent) : QAbstractVideoSurface(parent) { } QList<QVideoFrame::PixelFormat> camera_frame_grabber::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const { Q_UNUSED(handleType); return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_ARGB32 << QVideoFrame::Format_ARGB32_Premultiplied << QVideoFrame::Format_RGB32 << QVideoFrame::Format_RGB24 << QVideoFrame::Format_RGB565 << QVideoFrame::Format_RGB555 << QVideoFrame::Format_ARGB8565_Premultiplied << QVideoFrame::Format_BGRA32 << QVideoFrame::Format_BGRA32_Premultiplied << QVideoFrame::Format_BGR32 << QVideoFrame::Format_BGR24 << QVideoFrame::Format_BGR565 << QVideoFrame::Format_BGR555 << QVideoFrame::Format_BGRA5658_Premultiplied << QVideoFrame::Format_AYUV444 << QVideoFrame::Format_AYUV444_Premultiplied << QVideoFrame::Format_YUV444 << QVideoFrame::Format_YUV420P << QVideoFrame::Format_YV12 << QVideoFrame::Format_UYVY << QVideoFrame::Format_YUYV << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21 << QVideoFrame::Format_IMC1 << QVideoFrame::Format_IMC2 << QVideoFrame::Format_IMC3 << QVideoFrame::Format_IMC4 << QVideoFrame::Format_Y8 << QVideoFrame::Format_Y16 << QVideoFrame::Format_Jpeg << QVideoFrame::Format_CameraRaw << QVideoFrame::Format_AdobeDng; } bool camera_frame_grabber::present(const QVideoFrame &frame) { if(frame.isValid()) { QVideoFrame clone_frame(frame); //if I do not call map, the app wouldn't crash clone_frame.map(QAbstractVideoBuffer::ReadOnly); clone_frame.unmap(); } return false; }
I use the frame buffer as following
camera_frame_grabber frame_grabber; QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); for(QCameraInfo const &cameraInfo : cameras) { cam_.reset(new QCamera(cameraInfo)); cam_->setViewfinder(&frame_grabber_); pimpl_->cam_->start(); break; }
Always crash on android, but works perfect on windows. I guess this is another bug of android
-
I give every solutions a shot, none of them work.
Qt QML Camera to C++ QImage on Android
https://stackoverflow.com/questions/28041741/qt-qml-camera-to-c-qimage-on-android
[Use of QAbstractVideoSurface [closed]]https://stackoverflow.com/questions/26229633/use-of-qabstractvideosurface