小部件出现在图像旁边?
Widget is appearing next to image?
我正在尝试将 pyqtgraph ROI 小部件(信息 here)放在 .PNG 图像之上。当我将图像导入程序时,它以错误的方式旋转和翻转。我认为这是一个错误。为了尝试修复它,我旋转了图像,但是当我这样做时,我的 ROI 小部件从图像上消失了。我该如何解决?
无图像旋转:
i = Image.open("del.png")
a = array(i) #converting to numpy array
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
一旦我将 img1a.rotate(90)
添加到上面的代码中,ROI 小部件就会从屏幕上消失。 如何以正确的方式定位图像并让我的 ROI 小部件正常显示在图像顶部?
完整代码见下方(根据本例编辑发现here.)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
from numpy import array
from PIL import Image
## create GUI
app = QtGui.QApplication([])
w = pg.GraphicsWindow(size=(1000,800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')
text = """text"""
w1 = w.addLayout(row=0, col=0)
label1 = w1.addLabel(text, row=0, col=0)
v1a = w1.addViewBox(row=1, col=0, lockAspect=True)
#img1a = pg.ImageItem(arr)
i = Image.open("del.png")
a = array(i)
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
img1a.rotate(90)
v1a.disableAutoRange('xy')
v1a.autoRange()
rois = []
rois.append(pg.EllipseROI([150, 150], [1, 1], pen=(4,9)))
rois.append(pg.EllipseROI([0, 0], [300, 300], pen=(4,9)))
for roi in rois:
v1a.addItem(roi)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
您不必旋转项目,但必须旋转图像才能使用 numpy.rot90:
i = Image.open("del.png")
a = array(i)
a = np.rot90(a, -1)
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
v1a.disableAutoRange('xy')
v1a.autoRange()
我正在尝试将 pyqtgraph ROI 小部件(信息 here)放在 .PNG 图像之上。当我将图像导入程序时,它以错误的方式旋转和翻转。我认为这是一个错误。为了尝试修复它,我旋转了图像,但是当我这样做时,我的 ROI 小部件从图像上消失了。我该如何解决?
无图像旋转:
i = Image.open("del.png")
a = array(i) #converting to numpy array
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
一旦我将 img1a.rotate(90)
添加到上面的代码中,ROI 小部件就会从屏幕上消失。 如何以正确的方式定位图像并让我的 ROI 小部件正常显示在图像顶部?
完整代码见下方(根据本例编辑发现here.)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
from numpy import array
from PIL import Image
## create GUI
app = QtGui.QApplication([])
w = pg.GraphicsWindow(size=(1000,800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')
text = """text"""
w1 = w.addLayout(row=0, col=0)
label1 = w1.addLabel(text, row=0, col=0)
v1a = w1.addViewBox(row=1, col=0, lockAspect=True)
#img1a = pg.ImageItem(arr)
i = Image.open("del.png")
a = array(i)
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
img1a.rotate(90)
v1a.disableAutoRange('xy')
v1a.autoRange()
rois = []
rois.append(pg.EllipseROI([150, 150], [1, 1], pen=(4,9)))
rois.append(pg.EllipseROI([0, 0], [300, 300], pen=(4,9)))
for roi in rois:
v1a.addItem(roi)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
您不必旋转项目,但必须旋转图像才能使用 numpy.rot90:
i = Image.open("del.png")
a = array(i)
a = np.rot90(a, -1)
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
v1a.disableAutoRange('xy')
v1a.autoRange()