我使用 matplotlib 和 openCV 来绘制一些阈值方法,并抛出以下没有输出的警告:
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.
我使用的是 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([])
最佳答案
谢谢大家。只适合我Elyte's answer成功了。要在 python 中使用它,您可以使用:
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...
关于python - 警告 : QT_DEVICE_PIXEL_RATIO is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58194247/