Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. plot pictures from char buffer

plot pictures from char buffer

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 844 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.
  • JulianJ Offline
    JulianJ Offline
    Julian
    wrote on last edited by
    #1

    Hello All. I hope you all are doing well.

    I have a raspberry pi and with openCV and a webcam it captures pictures, processes it and sends it using socket. In the socket server side, there is an application created by Qt. I got the data but Im having a problem to plot the image.
    Please, remember that as I using socket in armbian system, it sends the data as a char data type flux.

    This is what I tried (first sending a grayscale images)

    char buffer [307200]; //its big but the data that server gets takes packets with 1000 bytes size (308 packets to form an image of 640*480
     QImage *img;
    
        img = new QImage ((uchar *)buffer, 640, 480, QImage::Format_Grayscale8);
    
    
        ui->label->setPixmap(QPixmap::fromImage(*img));
    

    But it always shown a black pictures.

    1 Reply Last reply
    0
    • mranger90M Offline
      mranger90M Offline
      mranger90
      wrote on last edited by
      #2

      The first thing to check is that the data really isn't all zeros.
      Also, I've had better luck displaying Format_Indexed8 with a grayscale color table for 8 bit data.

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        from http://doc.qt.io/qt-5/qimage.html#QImage-3:

        data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.

        You are basically missing an argument to use http://doc.qt.io/qt-5/qimage.html#QImage-5

        QImage img(reinterpret_cast<uchar*>(buffer), 640, 480, 640,QImage::Format_Grayscale8);

        The below is an example showing white noise:

        int main(int argc, char *argv[])
        {
            QApplication a(argc,argv);
            uchar buffer [648*480];
            std::default_random_engine generator;
            std::uniform_int_distribution<quint16> distribution(0,0xff);
            for(auto i=std::begin(buffer);i!=std::end(buffer);++i)
                *i=distribution(generator);
            QImage testImg(buffer,640,480,640,QImage::Format_Grayscale8);
            QLabel result;
            result.setPixmap(QPixmap::fromImage(testImg));
            result.show();
            return a.exec();
        }
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        3
        • JulianJ Offline
          JulianJ Offline
          Julian
          wrote on last edited by
          #4

          Thanks a lot! problem solved!

          1 Reply Last reply
          0

          • Login

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