python - 警告 : QT_DEVICE_PIXEL_RATIO is deprecated

标签 python python-3.x qt opencv matplotlib

我使用 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/

相关文章:

c++ - 获取选定的菜单项

python - 导航到 PyCharm 中的特定模块

python-3.x - 为什么我的 cron 命令没有在日志文件中输出?

linux - 如何在 Linux 上的 Win7 VM 中使用多播?

python - 根据 pandas Data Frame 中的其他索引值对索引值进行分组

python-3.x - 如何在opencv python中为摄像头视频赋予透明边框?

c++ - 将指向单例的指针分配给对象字段

python - 在正则表达式匹配之间插入空格

python - 陈旧元素引用异常

python - 使用子进程检查 sudo-apt install 返回值?