Pergunta

I want to send OpenCV single channel images (CV_8UC1) and multichannel images (CV_8UC3) to a ftp server using QNetworkAccessManager object in Qt 5.2.

I tried put method of QNetworkAccessManager which sends data in one of the following formats:

QNetworkReply *put(const QNetworkRequest &request, QIODevice *data);
QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart);

and it works fine for text files or images which I read from hard disk. but I don't know how to send opencv grayscale and color images which I have them on my RAM using this method ?

I think I have to change my format to Qbytearray and then send it, but by searching The Internet I didn't find anything useful. I only found this which is not suitable for my application and it's somehow waste some time to produce that image and also I need to change my cv::mat to IplImage ....

Thanks

Foi útil?

Solução

You could basically use the following method on the server side:

QImage QImage::fromData(const uchar * data, int size, const char * format = 0) [static]

Constructs a QImage from the first size bytes of the given binary data. The loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader probes the file for a header to guess the file format. binary data. The loader attempts to read the image, either using the optional image format specified or by determining the image format from the data.

If format is not specified (which is the default), the loader probes the file for a header to determine the file format. If format is specified, it must be one of the values returned by QImageReader::supportedImageFormats().

If the loading of the image fails, the image returned will be a null image.

Just make sure you send the raw data through properly. Also, make sure that your image format is actually supported by Qt as follows:

QList QImageReader::supportedImageFormats() [static]

Returns the list of image formats supported by QImageReader.

By default, Qt can read the following formats:

Format  MIME type   Description
BMP image/bmp   Windows Bitmap
GIF image/gif   Graphic Interchange Format (optional)
JPG image/jpeg  Joint Photographic Experts Group
PNG image/png   Portable Network Graphics
PBM image/x-portable-bitmap Portable Bitmap
PGM image/x-portable-graymap    Portable Graymap
PPM image/x-portable-pixmap Portable Pixmap
XBM image/x-xbitmap X11 Bitmap
XPM image/x-xpixmap X11 Pixmap
SVG image/svg+xml   Scalable Vector Graphics

Reading and writing SVG files is supported through the Qt SVG module. The Qt Image Formats module provides support for additional image formats.

Note that the QApplication instance must be created before this function is called.

Outras dicas

You could create a QByteArray containing the image data (unsigned char* Mat::data). Then append the height, width and number of channels (format) of the original image to the array (or put that info on the front of the QByteArray; or send them separately!).

The server will receive the QByteArray, and then reconstruct an image by using the constructor:

QImage ( uchar * data, int width, int height, Format format )
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top