Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Note: I don't use Java in combination wit opencv, but it should work like this:

If the procedure you described really is in the same method scope you could simply extract the letters behind the last '.' of the path from the image path you pass to _imread_ - i.e. 'jpg' from "h:\opencv.jpg" - and then pass it on to _imencode_

For this to work you need to save the path of the image loaded, i.e.

String image_in = "h:/opencv.jpg";
Mat image = Highgui.imread(image_in);

Later you use i.e. String.split function

String[] image_in_splits = image_in.split(".");
String fileFormat = image_in_splits[image_in_splits.length - 1];