2017-03-06 115 views
1

画像をPyQtラベルに表示した後、表示された画像の上に長方形を描きたい。私は、ユーザーがイメージ上の四角形をどこに描画するかのように「描画」を意味するわけではありませんが、イメージの上に四角形を作成したいだけであることに注意してください。 matplotlib軸に相当するコードがありますが、PyQtで同じことをする方法がわかりません。PyQt - 画像に矩形を重ねる方法

# Create Figure/Axes Instance 
figure,axes = matplotlib.pyplot.subplots() 
axes.imshow(imageRGB) 

# Draw Rectangle 
axes.add_patch(matplotlib.patches.Rectangle((50,50),100,100,fill=False,edgecolor='red')) 

答えて

4
# convert image file into pixmap 
self.pixmap_image = QtGui.QPixmap(self.filename) 

# create painter instance with pixmap 
self.painterInstance = QtGui.QPainter(self.pixmap_image) 

# set rectangle color and thickness 
self.penRectangle = QtGui.QPen(QtCore.Qt.red) 
self.penRedBorder.setWidth(3) 

# draw rectangle on painter 
self.painterInstance.setPen(self.penRectangle) 
self.painterInstance.drawRect(xPos,yPos,xLen,yLen) 

# set pixmap onto the label widget 
self.ui.label_imageDisplay.setPixmap(self.pixmap_image) 
self.ui.label_imageDisplay.show() 
関連する問題