How can I send an wxImage through wxSocket in c++? - c++

How can I send a wxImage through TCP wxSocket in c++?
Should I convert the wxImage to a wxString or can it be directly send over?
In that case how do I convert a wxImage tobe a wxString?

You have direct access to the image data via its GetData() member, so you could just send it directly, at least if you have an image without alpha. However in practice, compressing it first would probably be a good idea as uncompressed images are huge. You could either use zlib compression or, perhaps simpler, write the image in PNG or JPEG format to a memory buffer and send this buffer instead.
Converting the image to a string would be possible too but highly suboptimal.

Hai wxImage::GetData() return unsigned char* so you can easily send image as a string.Don't forget to send image width&height, this two attributes must need for again converting data into image.

Related

Compress Raw buffer data of video (C++)

I have raw buffer video data which I need to stream over the net as and when requested by the clients. This data is very huge. So I will need to compress and save it at my server location.
One way I understand of doing this convert the data into a video file ".avi" and save it and then stream it frame by frame as and when requested.
I have used the VideoWriter function of OpenCV for converting the buffer to mat and then to ".avi" file with MPEG4 encoding.
However I want to know if there is any way I can compress the raw buffer data and save it in a file. Can anyone suggest me if this is possible?
Thank You.

Read image and access bytes in boost::gil

Is it possible to:
read an image given by just a filename (not knowing the image format) to a 2d matrix rgb uncompressed form (e.g. read an JPG to a 2d array)
access the bytes of that image, copy them, change them... (e.g. inverse the colors, I need a pointer to the image bytes, setters/getters won't do )
save those bytes to any given image format (e.g. save the inversed image to PNG)
Is it possible with boost::gil ? Maybe there is a different library more appropriate for such a task?
Sample code would be highly appreciated.
Yes, you can do all that in boost::gil.
What you should know though, is that boost::gil is only a universal interface and doesn't handle reading/writing images all by itself. You still need to use a second library, e.g. libpng..
Yes, yes and yes.
There are functions that enable you to read and write JPEG, TIFF and PNG images: see here.
For the second bullet, it is what just GIL is meant to do. You can manipulate images using its facilities (click here).

How do I create a QIcon from binary data?

I have a custom file format which stores some images. I load these images into memory during the operation of my program. The images are loaded in binary format (i.e. the same way they would appear on disk). I know what format the images are in (pretty much all jpeg). The problem is that I dont know the width/height, but I want to display the images without writing them to some temp file on disk. Anyone know how to do this?
You can get the size of a qIcon using actual size
http://qt-project.org/doc/qt-5.0/qicon.html#actualSize
You shouldn't have to write anything to disk, you just need to read your binary into something like QIcon, so that you can use QTs methods to get the width and height of the image. You just need to get the data into one of QTs data structures.
Check out QImage and QPixmap, I think they have methods for reading in binary. Or you can check this SO post here: QImage from unsigned char buffer (jpg format)

Send Iplimage data as jpeg

I am trying to send Iplimage to another program as a array of bytes in c++/cli. The program needs to save the Iplimage as jpeg image. Let's say the Iplimage is img which I am obtaing by cvQyeryFrame from an avi video file, I am returning img->imagedata to the other program. Does img->imagedata contain the header for the jpeg image to be saved or does it only contain the data. If it only contains the data, how can I include the header? I can save the image using cvSaveImage and then read it but there should be a more direct way (maybe cvEncodeImage? )
thanks.
The data in the Iplimage is already decoded into own format of openCV (typically 8bit B,G,R) once it has been read from disk.
The newer versions of opencv can encode/decode an image in memory, see imencode.
If you need the entire JPEG data, you might want to consider reading the entire file from the disk with fread() instead of cvLoadImage().
If that's not going to work for you, consider Martin's answer.

OpenCV jpeg format image in memory

Is there a possibility of saving an image to a string instead of a file with OpenCV?
I have found just this function in the docs:
int cvSaveImage(const char* filename, const CvArr* image)
And it can only save to files.
How did you want to code the image in the string?
You could just store red,green,blue values as comma separated strings but coding the image binary as something like base64 would be more compact.
Edit: if you mean a jpeq format in memory see - OpenCV to use in memory buffers or file pointers
Maybe you can simply create a char* buffer and copy your IplImage data structure there ?
But be careful, you should carefully copy the pointer variables, such as imageData, imageDataOrigin and so on.
So the idea is to put everything in your buffer in the way you can decode it from the receiver's side.
And opencv is an opensource library and you can simply copy the opencv's savefile function body, replacing writing in a file to writing in your buffer