# Did cv::imencode() once have a JPEG quality-not-being-set bug?

**URL:** https://forum.opencv.org/t/did-cv-imencode-once-have-a-jpeg-quality-not-being-set-bug/17925
**Category:** C++
**Tags:** imgcodecs
**Created:** [June 13, 2024, 3:01pm UTC](https://forum.opencv.org/t/did-cv-imencode-once-have-a-jpeg-quality-not-being-set-bug/17925 "2024-06-13T15:01:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nickpelling](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@nickpelling](https://forum.opencv.org/u/nickpelling)
#### Post date: [June 13, 2024, 3:01pm UTC](https://forum.opencv.org/t/did-cv-imencode-once-have-a-jpeg-quality-not-being-set-bug/17925/1 "2024-06-13T15:01:41Z")

</div>

Hi everyone,

I’ve been handed the code for a system built on Debian Bullseye using a prebuilt libopencv 4.5, but where cv::imencode seems to ignore the quality settings. That is, the caller is passing it a std::vector containing [cv::IMWRITE\_JPEG\_QUALITY, 50] (or 60, or whatever) but the JPEG image that it returns always has quality 95. [According to ImageMagick.]

Did imencode have a ancient JPEG quality-not-being-set bug circa 4.5 that has since been fixed? (I looked in the changelog but couldn’t see anything.) Even a pointer as to where I might usefully look would be really helpful! 👍

Thanks very much, Nick

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [June 13, 2024, 4:00pm UTC](https://forum.opencv.org/t/did-cv-imencode-once-have-a-jpeg-quality-not-being-set-bug/17925/2 "2024-06-13T16:00:59Z")

</div>

if you want to investigate, you could use the python package. generate a virtual environment (a python thing), install specified version, run a bit of code, repeat.

```python
if True:
  print(cv. __version__ )
  im = np.random.randint(256, size=(512,512))
  (rv, data) = cv.imencode(".jpg", im, [cv.IMWRITE_JPEG_QUALITY, 10]); print(data.shape)
  (rv, data) = cv.imencode(".jpg", im, [cv.IMWRITE_JPEG_QUALITY, 50]); print(data.shape)
  (rv, data) = cv.imencode(".jpg", im, [cv.IMWRITE_JPEG_QUALITY, 90]); print(data.shape)

```

I’m currently on 4.10 and this works as expected

| Python | OpenCV | yay or nay |
| --- | --- | --- |
| 3.11 | 4.10.0 | OK |
| 3.11 | 4.5.5.64 | OK |
| 3.9 | 4.5.1 | OK |

That’s all on Windows though.

I wouldn’t bet on there having been a bug. there might have been. might have been platform-specific, or for very few versions.

you’ll have to investigate this yourself. it’s the least effort for everyone if you do it.
