窗口小部件出现在图片旁边?

时间:2018-01-18 02:07:46

标签: python image-processing pyqt pyqtgraph roi

我正在尝试将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_()

1 个答案:

答案 0 :(得分:1)

您不必旋转项目,但必须旋转图像才能使用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()