2017-03-06 11 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() 
관련 문제