How to convert a cv::mat header and data part into a single qbytearray?

347 views Asked by At

I want to use Qftp module of Qt 4.8.1 to send opencv images to a FTP server. I wrote the following code:

        ftp = new QFtp(this);
        //ftp initilization
          .
          .
          .
          . 
        //
        cv::Mat InputImage(100,100,CV_8UC1,cv::Scalar::all(75));
        QImage FTP_Result = QImage((const uchar *) InputImage.data, InputImage.cols, InputImage.rows, InputImage.step, QImage::Format_Indexed8);
        QByteArray byteMe((char *) FTP_Result.bits());

        qDebug()<<"Image size is: "<<FTP_Result.height()<<"*"<<FTP_Result.width(); //it returns 100*100
        ftp->put(byteMe,"Sample.jpg");

When I go into the ftp server hard disk I find Sample.jpg, and it is filled with "K" character which is the Asci equivalent of "75". It seems the header is missing so the operating system thinks it is just a simple text file. I think this is because I only copied InputImage.data into the QByteArray variable so no information about the image is available. what should I do to copy "InputImage" header information into the "byteMe" variable so I could store a healthy JPEG file ?

1

There are 1 answers

0
UhWhoMe On

Try

QByteArray byteMe((char *) FTP_Result.bits(), FTP_Results.byteCount());

When you construct with a simple char * its going to look for a null terminated string.