# Does the OpenCV included with UE5 come with JPEG compatibility?

**URL:** <https://forums.unrealengine.com/t/does-the-opencv-included-with-ue5-come-with-jpeg-compatibility/1498336>\
**Category:** Programming & Scripting\
**Tags:** opencv, unreal-engine, CPP, question\
**Created:** [December 6, 2023, 5:20pm UTC](https://forums.unrealengine.com/t/does-the-opencv-included-with-ue5-come-with-jpeg-compatibility/1498336 "2023-12-06T17:20:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sploul](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sploul](https://forums.unrealengine.com/u/Sploul)\
**Post date:** [December 6, 2023, 5:20pm UTC](https://forums.unrealengine.com/t/does-the-opencv-included-with-ue5-come-with-jpeg-compatibility/1498336/1 "2023-12-06T17:20:55Z")

</div>

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:

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

```

After investigating a bit, I’ve seen that in [cvconfig.h](https://github.com/EpicGames/UnrealEngine/blob/d4ab788a7191352128aa43720cff5b7dc25abcac/Engine/Plugins/Runtime/OpenCV/Source/ThirdParty/OpenCV/include/opencv2/cvconfig.h#L76) 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 🙂

---

<div class="post-metadata">

**Author:** ![behram\_patel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@behram\_patel](https://forums.unrealengine.com/u/behram_patel)\
**Post date:** [October 25, 2024, 7:12am UTC](https://forums.unrealengine.com/t/does-the-opencv-included-with-ue5-come-with-jpeg-compatibility/1498336/2 "2024-10-25T07:12:18Z")

</div>

**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](https://forums.unrealengine.com/t/debugging-exceptions-opencv-save-image-to-disk/2086942)

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
