Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. What is the proper solution to process the frame of camera on android?
QtWS25 Last Chance

What is the proper solution to process the frame of camera on android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 2 Posters 1.6k 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.
  • T Offline
    T Offline
    tham
    wrote on 4 Sept 2017, 16:16 last edited by tham 9 May 2017, 02:01
    #1

    Qt5.9.1
    os : win 10 64bits
    Android sdk : 19
    Phone : GTS-6310
    android version : 4.1.2

    I 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

    Link of complete codes

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tham
      wrote on 4 Sept 2017, 18:37 last edited by
      #2

      I forgot the error message, put at pastebin

      M 1 Reply Last reply 4 Sept 2017, 20:30
      0
      • T tham
        4 Sept 2017, 18:37

        I forgot the error message, put at pastebin

        M Offline
        M Offline
        mvuori
        wrote on 4 Sept 2017, 20:30 last edited by
        #3

        I think Android may get confused with what formats it can handle. I'd try reducing your list of formats in supportedPixelFormats() to just Format_NV21

        T 1 Reply Last reply 4 Sept 2017, 23:53
        0
        • M mvuori
          4 Sept 2017, 20:30

          I think Android may get confused with what formats it can handle. I'd try reducing your list of formats in supportedPixelFormats() to just Format_NV21

          T Offline
          T Offline
          tham
          wrote on 4 Sept 2017, 23:53 last edited by
          #4

          @mvuori I change it to Format_NV21, still crash as before, extracting a frame from camera is not an trivial job

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tham
            wrote on 5 Sept 2017, 02:05 last edited by
            #5

            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

            1 Reply Last reply
            0

            1/5

            4 Sept 2017, 16:16

            • Login

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