Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem caused by the change from libjpeg to libjpeg-turbo #65

Closed
Marco-LIU opened this issue Jan 23, 2018 · 1 comment
Closed

Problem caused by the change from libjpeg to libjpeg-turbo #65

Marco-LIU opened this issue Jan 23, 2018 · 1 comment

Comments

@Marco-LIU
Copy link

Expected behaviour

cv2.imread in different versions should return same values for the same JPG file.

Actual behaviour

001
For this image(w=153, h=209), pixel[0, 207] will get different value between 3.3 and 3.4
screenshot from 2018-01-19 18-41-01
In 3.3, pixel[0, 207] = [115, 52, 226]
screenshot from 2018-01-19 18-42-01
In 3.4, pixel[0, 207] = [111, 52, 223]

Steps to reproduce

  • example code
    import cv2
    print(cv2.__version__)
    img = cv2.imread('001.jpg')
    print(img[0, 207])
  • operating system
    linux
  • architecture (e.g. x86)
    x64
  • opencv-python version
    3.4

I have tested the libjpeg and libjpeg-turbo, and this difference is caused by these two libs. (Test code in https://github.com/Marco-LIU/libjpeg-test)

Though the libjpeg-turbo has better performance than libjpeg, this difference will make a TRAP, and cause some machine learning models give DIFFERENT results for same input file. We've trained a model in v3.3, but got a wrong test result in v3.4 for that beauty pic.

@skvark
Copy link
Member

skvark commented Feb 19, 2018

Hmm, I thought that I already wrote a reply here but apparently I didn't...

Anyhow, I can confirm that there seems to be differences between these libraries. Most likely the issue is related to the optimizations which have been done in libjpeg-turbo. I have no way of knowing what might cause these differences but I presume that different decoding algorithms are used under the hood. In addition, the usage SIMD extensions might cause some inaccuracies to the results. Due to the nature of the JPEG's lossy format there's no way to "fix" this issue.

I'll be changing also macOS and Windows jpeg libs to libjpeg-turbo at some point. You can always compile OpenCV by yourself if you need extremely stable environment. I hope you understand that I cannot guarantee that these builds remain consistent across releases.

Edit: See also this comment in the official repository: opencv/opencv#10887 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants