问题描述
我使用 pyqtgraph ViewBox 通过 ImageItem 类处理图像,并使用 ROI 类标记图像的重要部分。我正在处理的图像要求我使用具有给定 x 和 y 像素大小的 setAspectLocked。
问题是,如果我在 ViewBox 上设置纵横比锁定,则 ROI 缩放旋转手柄在旋转时会被拉伸。有没有办法锁定它?或者有没有办法只在 ImageItem 类上而不是整个 ViewBox 上应用 setAspectLocked?
# -*- coding: utf-8 -*-
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore,QtGui
import numpy as np
pg.setConfigOptions(imageAxisOrder='row-major')
## create GUI
app = QtGui.QApplication([])
w = pg.GraphicslayoutWidget(show=True,size=(1000,800),border=True)
w.setwindowTitle('pyqtgraph example: ROI Examples')
w3 = w.addLayout(row=1,col=0)
v3 = w3.addViewBox(row=1,col=0)
v3.setAspectLocked(True,1.8/18)
r3a = pg.ROI([0,0],[10,10])
v3.addItem(r3a)
## handles scaling horizontally around center
r3a.addScaleHandle([1,0.5],[0.5,0.5])
r3a.addScaleHandle([0,0.5])
## handles scaling vertically from opposite edge
r3a.addScaleHandle([0.5,1])
r3a.addScaleHandle([0.5,1],0])
## handles scaling both vertically and horizontally
r3a.addScaleHandle([1,[0,0])
r3a.addScaleHandle([0,[1,1])
r3b = pg.ROI([20,10])
v3.addItem(r3b)
## handles rotating around center
r3b.addRotateHandle([1,0.5])
r3b.addRotateHandle([0,0.5])
## handles rotating around opposite corner
r3b.addRotateHandle([1,1])
r3b.addRotateHandle([0,0])
## handles rotating/scaling around center
r3b.addScaleRotateHandle([0,0.5])
r3b.addScaleRotateHandle([1,0.5])
v3.disableAutoRange('xy')
v3.autoRange()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore,'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)