Regarding the saving the image in Android using QVideoProbe



  • Hi,

    I want to get the frames in video mode, i have used QML Camera, and QVideoProbe Class to get the frames. I am getting the frames but all the images are blank, i saw the size it is not 0 kb size, it was of 51.14 kb.

    And retreived the image and displayed in QLabel.
    It is blank.

    Here is the image

    https://postimg.org/image/ircprtnd7/

    Guidance is required.

    Thanks,


  • Moderators

    @Pradeep-Kumar said in Regarding the saving the image in Android using QVideoProbe:

    Guidance is required.

    code is required ;)



  • Hi the code snippet

    void className::funcName(){ 
            cam_ = new QQuickWidget();
            context_ = cam_->engine()->rootContext();
            context_->setContextProperty("MyWidget", this);
            cam_->setSource(QUrl("qrc:///declarative-camera.qml"));
            m_qmlCameraQObject = cam_->rootObject()->children().at(0)->findChild<QObject*>("CameraObject");
            QVariant mediaObject = m_qmlCameraQObject->property("mediaObject");
    
            if(mediaObject.isValid()){
    
                qDebug()<<"----Variant object is valid----- \n";
    
                m_QCameraObj = mediaObject.value<QCamera*>();
            
           if(m_QCameraObj && m_QCameraObj->availability() == QMultimedia::Available){
    
                    m_videoProbe = new QVideoProbe(this);
                    if(m_videoProbe->setSource(m_QCameraObj)){
    
     connect(m_videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(manageVideoFrame(QVideoFrame)));
    
                      }
               }
          }
    }
    

    And in the slot:

    void ClassName::manageVideoFrame(QVideoFrame frame)
    {
            QVideoFrame cloneFrame(frame);
            cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
    
            QImage::Format imageFormat;
            if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)
            {
    
                QImage image(cloneFrame.size(), QImage::Format_ARGB32);
    
                if (!image.isNull())
                {
    
                    QDateTime dateTime = dateTime.currentDateTime();
                    QString dateTimeString = dateTime.toString("yyyyMMddhhmmss");
    
                    QString appendString = "image_";
                    appendString.append(dateTimeString);
    
                    QString str = "/storage/sdcard1/DCIM/";
                    str.append(appendString+".jpg");
            }
       }
    }
    

  • Moderators

    @Pradeep-Kumar said in Regarding the saving the image in Android using QVideoProbe:

    if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)

    Shouldn't it be != instead of == here:

    if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)
    

    You create a image:

    QImage image(cloneFrame.size(), QImage::Format_ARGB32);
    

    but you do not write any data into that image and I cannot see where you actualy save the image.



  • Hi,

    Sorry about that , i have used save method.

           if (!image.isNull())
            {
    
                QDateTime dateTime = dateTime.currentDateTime();
                QString dateTimeString = dateTime.toString("yyyyMMddhhmmss");
    
                QString appendString = "image_";
                appendString.append(dateTimeString);
    
                QString str = "/storage/sdcard1/DCIM/";
                str.append(appendString+".jpg");
    
                if (image.save(str, "JPG"))
                {
                    qDebug()<<"Image saved successfully \n";
                }
                else
                {
                    qDebug()<<"There is problem in image saving \n";
                }
        }
    

    Image is inserted successfully.

    Thanks,



  • Hi,

    Is the code not valid or am i missing something?.

    Thanks,


  • Moderators

    @Pradeep-Kumar As I said before I cannot see where you're writing anything into image.
    You only create one:

    QImage image(cloneFrame.size(), QImage::Format_ARGB32);
    

    but never write any pixel data into it.



  • Can u clarify and correct the previous code snippet .
    Correct me if i am wrong , i didnt assign the frames captured to QImage, is that the point?.

    Thanks,


  • Moderators

    @Pradeep-Kumar Yes, you do not write anything into the image.
    QVideoFrame documentation says:
    "The pixel contents of a video frame can be mapped to memory using the map() function. While mapped, the video data can accessed using the bits() function, which returns a pointer to a buffer."
    So, first you need to map the frame data into memory calling http://doc.qt.io/qt-5/qvideoframe.html#map, then you can access the frame data using http://doc.qt.io/qt-5/qvideoframe.html#bits and write the data into the image via http://doc.qt.io/qt-5/qimage.html#loadFromData.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.