Receiving raw image data from camera



  • I am working on a GUI to display image from sensor. The GUI acts as a client while the sensor acts as a server. Once I send a command to the sensor, the sensor will send streaming raw image data (binary data) continuously to the GUI through TCP. The data will be an exact copy of the image memory with size width (1240) x height (1028) coded in U8 (unsigned 8 bit). The size of one incoming data is (1240 x 1028 x 1 byte) + 20 byte (meta header) = 1.3MByte.

    My biggest obstacles are:
    1.) how can I receive and store the streaming data from sensor continuously for display purpose?
    2.) how can I display the raw data?

    I have tried the code as below, but it is not working. Please advise:

    "client.h"
    @ #ifndef CLIENT_H
    #define CLIENT_H

    #include <QObject>
    #include <QWidget>
    #include <QTcpSocket>

    class Client : public QWidget
    {
    Q_OBJECT
    public:
    explicit Client(QWidget *parent = 0);
    int capture (int mode, int NBRLine);

    signals:

    public slots:

    private:
    QTcpSocket* socket;

    };

    #endif // CLIENT_H@

    "client.cpp"
    @#include "client.h"
    #include <QHostAddress>
    #include "mainwindow.h"
    #include <QtGui>
    #include <QAbstractSocket>
    #include <QImage>

    Client::Client(QWidget *parent) :
    QWidget(parent)
    {
    socket = new QTcpSocket(this);
    }

    int Client::capture(int mode, int NBRLine)
    {
    if (socket->state() != QTcpSocket::ConnectedState)
    {
    socket->connectToHost("192.168.0.65", 1096);
    }

    /* send command to retrieve raw image data from sensor */
    if(socket->waitForConnected(5000))
    {
        QByteArray block;
        QDataStream out(&block, QIODevice::WriteOnly);
        out.setVersion(QDataStream::Qt_4_0);
        out.setByteOrder(QDataStream::LittleEndian);
        out << qint32(0) << qint32(0) << qint32(0) << qint32(1);
        out << qint32(9) << qint32(1) << qint32(0) << mode << qint32(10) << qint32(2) << qint32(0) << NBRLine ;
        socket->write(block);
        socket->flush();
    }
    else
    {
        return false;
    }
    /**********************************************************/
    
    /* to get data size of each scan through width and height in the meta header */
    QDataStream input(socket);
    input.setVersion(QDataStream::Qt_4_0);
    input.setByteOrder(QDataStream::LittleEndian);
    qint32 buffer, cmdID, counter, metaSize, width, height;
    do
    {
        if (socket->waitForReadyRead(1000))
        {
            input >> cmdID;
            if (cmdID == 101)
            {
                input >> buffer >>  buffer >> buffer >> buffer;
            }
        }
        else
        {
            socket->disconnectFromHost();
            break;
    
        }
    } while (cmdID != 1);
    
    input >> counter >> metaSize;
    if (metaSize != 8) return false;
    
    input >> width >> height;
    quint32 datasize =  width * height;
    
    /**********************************************************/
    
    /* Receiving streaming data which I have problem here !!!! */
    while (socket->bytesAvailable() < datasize + 80) {
        if (!socket->waitForReadyRead(1000)) {
            socket->disconnectFromHost();
            break;
        }
    }
    
    QImage img;
    input >> img;
    
    if (img.isNull())
    {
        return 0;
    }
    img.save("E:/temp1");
     return 1;
    

    }@


Log in to reply
 

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