Sai*_*man 6 python qt opencv matplotlib python-3.x
我正在使用 matplotlib 和 openCV 来绘制一些阈值方法,并抛出以下没有输出的警告:
警告:不推荐使用 QT_DEVICE_PIXEL_RATIO。而是使用:
QT_AUTO_SCREEN_SCALE_FACTOR 启用平台插件控制的每屏幕因素。QT_SCREEN_SCALE_FACTORS 设置每个屏幕的因素。QT_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([])
Run Code Online (Sandbox Code Playgroud)
谢谢你们。对我来说,只有Elyte 的回答才奏效。要在 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...
Run Code Online (Sandbox Code Playgroud)
我通过使用与@elyte5star相同的方法解决了这个问题。在运行程序之前,在终端中运行以下命令:
export QT_DEVICE_PIXEL_RATIO=0
export QT_AUTO_SCREEN_SCALE_FACTOR=1
export QT_SCREEN_SCALE_FACTORS=1
export QT_SCALE_FACTOR=1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9728 次 |
| 最近记录: |