I am using matplotlib alongside openCV to plot some thresholding methods and the following warning with no output is thrown:
Warning: QT_DEVICE_PIXEL_RATIO is deprecated. Instead use:
QT_AUTO_SCREEN_SCALE_FACTOR to enable platform plugin controlled per-screen factors. QT_SCREEN_SCALE_FACTORS to set per-screen factors. QT_SCALE_FACTOR to set the application global scale factor.
I am using Ubuntu 19.04
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('gradient.jpg', 0)
_, th1 = cv.threshold(img, 50, 255, cv.THRESH_BINARY)
_, th2 = cv.threshold(img, 200, 255, cv.THRESH_BINARY_INV)
_, th3 = cv.threshold(img, 200, 255, cv.THRESH_TRUNC)
_, th4 = cv.threshold(img, 127, 255, cv.THRESH_TOZERO)
_, th5 = cv.threshold(img, 127, 255, cv.THRESH_TOZERO_INV)
titles = ['Original Image', 'BINARY', 'BINARY_INV', 'TRUNC', 'TOZERO', 'TOZERO_INV']
images = [img, th1, th2, th3, th4, th5]
for i in range(6):
plt.subplot(2, 3, i + 1), plt.imshow(images[i], 'gray')
plt.title(titles[i])
plt.xticks([]), plt.yticks([])
Thank you all. For me only Elyte's answer did the trick. To use this in python, you could use:
from os import environ
def suppress_qt_warnings():
environ["QT_DEVICE_PIXEL_RATIO"] = "0"
environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
environ["QT_SCREEN_SCALE_FACTORS"] = "1"
environ["QT_SCALE_FACTOR"] = "1"
if __name__ == "__main__":
suppress_qt_warnings()
# Init QT etc...
I solved the problem by using the same method with @elyte5star. Before Running the program, running following commands in your terminal:
export QT_DEVICE_PIXEL_RATIO=0
export QT_AUTO_SCREEN_SCALE_FACTOR=1
export QT_SCREEN_SCALE_FACTORS=1
export QT_SCALE_FACTOR=1
The warnings are about a change in the underlying Qt libraries:
In Qt 5.4, there was an experimental implementation of high DPI scaling introduced via the QT_DEVICE_PIXEL_RATIO environment variable, that you could set to a numerical scale factor or auto. This variable was deprecated in Qt 5.6. (source)
Since it's only a deprecation, I'm not sure that switching to the newer options will fix the problem of missing the output window. See the comments you got under your question for that.
But to get rid of the warnings, this should work in the shell when starting your script:
export QT_AUTO_SCREEN_SCALE_FACTOR=1;
python myscript.py;
For details, see: Qt Documentation: High DPI Displays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With