I’m seeing strange artifacts when using imread and imshow from PNG files.
If I load a JPEG image it is displayed correctly. However, even if I convert the correctly displayed JPEG image to PNG (using Photoshop for example), I get a very distorted image when loaded using OpenCV.
This a JPEG image exported as PNG (used Photoshop’s “Quick Export as PNG”) and displayed using OpenCV:
Any ideas what could be the cause here? This happens with every PNG file I try to load.
I did build the OpenCV lib myself – could this be caused by wrong build settings?
This is a screenshot of what OpenCV’s imshow outputs. The same PNG is displayed correctly if I open it with Preview or Photoshop, so there is no other way to clearly illustrate the problem.
While working on a reproducible example I figured out the cause of the issue. My project uses wxWidgets for UI, which for some reason was affecting how OpenCV handles PNG files. Specifically, if I link to “-lwxpng-3.1” then the PNG corruption appears. If I remove it then the PNG files are displayed correctly.
Since my project is not compiling without “-lwxpng-3.1”, I discovered that if I link to OpenCV’s libraries first and wxWidgets’ libraries second, then the PNG issue is resolved.