Does the OpenCV included with UE5 come with JPEG compatibility?

Hi there,

I’ve tried to use OpenCV’s imwrite method to save a capture of the scene. When I use BMP, PNG or EXR (with some more steps), no issue, the file is saved.
However, JPEG gives me an OpenCV error:
error: (-2:Unspecified error) could not find a writer for the specified extension in function 'cv::imwrite_'

I call it like this:

cv::imwrite("image.jpg", cvMatInThe-CV_8UC3-format);

After investigating a bit, I’ve seen that in cvconfig.h in the OpenCV plugin from UE5, HAVE_JPEG is not defined.

This leads me to think that I, by design, can’t save to JPEG.

Is there a reason for this, and how can I fix this?
Ideally, I’d like to use UE5’s OpenCV, but if it’s not possible, what would be the easiest alternative?

Thanks in advance :slight_smile:

1 Like

Edit 01
Your are right it’s not. However #define HAVE_OPENJPEG is supported and it works for me.

In my local opencv folder (C:\opencv ) jpeg is supported in the cvconfig.h

/* IJG JPEG codec */
#define HAVE_JPEG

so yeah, it’s probably not supported in UE’s inbuilt version which is 4.5.
End Edit 01

I hope you found your answer. Your question helped me find a partial answer to my question here.

debugging exceptions in opencv

After reading your post I changed the type to png and everything worked fine !
I still need to learn how I’d go about debugging this via the call stack .

Cheers,
b