现在只会显示坐标,不会改了呀,代码贴下面,求老哥们帮看看
from PyQt5.QtWidgets import QWidget, QApplication, QLabel
from PyQt5.QtCore import QRect, Qt
from PyQt5.QtGui import QImage, QPixmap, QPainter, QPen, QGuiApplication
import cv2
import sys
class myLabel(QLabel):
x0 = 0
y0 = 0
x1 = 0
y1 = 0
flag = False
def mousePressEvent(self,event):
self.flag = True
self.x0 = event.x()
self.y0 = event.y()
print(self.x0,self.y0)
class Example(QWidget):
def init(self):
super().init()
self.initUI()
def initUI(self):
self.resize(1000, 500)
self.setWindowTitle('name')
self.lb = myLabel(self)
self.lb.setGeometry(QRect(200, -100, 1000, 700))
img = cv2.imread('D:/1001.jpg')
height, width, bytesPerComponent = img.shape
bytesPerLine = 3 * width
cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img)
QImg = QImage(img.data, width, height, bytesPerLine,QImage.Format_RGB888)
pixmap = QPixmap.fromImage(QImg)
self.lb.setPixmap(pixmap)
self.lb.setCursor(Qt.CrossCursor
self.show()
if name == 'main':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
为什么要点击时才显示鼠标当前位置下,图片的像素灰度?
实时显示鼠标位置下的图片像素灰度不是更好..
QImage.pixelColor()
代码没错。只是显示运行方法没有加上。
抱歉我不太会