Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Receiving NV21 pixel format from camera using an implemented QAbstractVideoSurface class but result is gray not colorful

    Mobile and Embedded
    2
    4
    141
    Loading More Posts
    • 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.
    • J
      Jafar.Sag.Sibil last edited by Jafar.Sag.Sibil

      The following code is used to write every video frame.
      but the result is gray.

      problem 1 :

      frame.image().isNull();// true forever
      

      problem 2 :

      frame.image().convertToFormat(someFormat).isNull();//true forever
      

      problem 3 :

      QImage	defaultImage ( frame.bits ( ), frame.width ( ), frame.height ( ), frame.bytesPerLine ( ), QImage::Format_Grayscale8 );// this operation does not work for every format and many of those make our result image null other than Alpha8, Mono, MonoLSB (all make our image terrible), Indexed, grayscale8 (gray style)
      

      videosurface.cpp

      bool VideoSurfacer::present ( const QVideoFrame & f )
      {
      	QVideoFrame frame ( f );
      	if ( frame.isValid ( ) && frame.map ( QAbstractVideoBuffer::MapMode::ReadWrite ) )
      		{
      			QImage	defaultImage ( frame.bits ( ), frame.width ( ), frame.height ( ), frame.bytesPerLine ( ), QImage::Format_Grayscale8 );
      			QString path = QStandardPaths::writableLocation ( QStandardPaths::GenericDataLocation ) + "/download/" + QString::number ( ++i );
      			QFile ( path + ".jpg" ).remove ( );
      			defaultImage.save ( path + ".jpg", "JPG" );
      
      			frame.unmap ( );
      		}
      	return true;
      }
      

      attention : QVideoFrame::imageFormatFromPixelformat(frame.pixelFormat());
      returns Format_Invalid which makes our image terrible like Mono etc

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        So from the documentation you can only access it when mapping the frame. So you have to manage the data yourself.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Did you check the handle type ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 1
          • J
            Jafar.Sag.Sibil last edited by

            Handle type is NoHandle

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              So from the documentation you can only access it when mapping the frame. So you have to manage the data yourself.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 0
              • First post
                Last post