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

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! :+1:

Thanks very much, Nick

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.

if True:
  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 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.