Richard Knop
Richard Knop

Reputation: 83755

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.

Upvotes: 3

Views: 5257

Answers (2)

Martin Beckett
Martin Beckett

Reputation: 96197

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

Upvotes: 1

Andrew
Andrew

Reputation: 24866

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

Upvotes: 1

Related Questions