Python Forum

Full Version: Create a list of co-ordinates from Mouse press events
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to create a cv2.contour from Mouse press events( i.e., Drawing on the image and converting it into contour)
Here is the code, in this the list is having only 1 x,y coordinate, need to create a list for every Mousepress and convert to cv2.contour.
    def mouseMoveEvent(self, event):
        list = []
        if (event.buttons() & Qt.LeftButton) & self.drawing:
            painter = QPainter(self.image)
            painter.setPen(QPen(self.brushColor, self.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
            painter.drawLine(self.lastPoint, event.pos())
            # self.lastPoint = event.pos()
            lastPoint=event.pos()
            self.update()
            print("LASTPOINTS", self.lastPoint)
            self.x = (self.lastPoint.x())
            self.y = (self.lastPoint.y())
            list.append(self.x)
            list.append(self.y)

(Mar-12-2020, 08:46 AM)Jagruthi Wrote: [ -> ]I'm trying to create a cv2.contour from Mouse press events( i.e., Drawing on the image and converting it into contour)
Here is the code, in this the list is having only 1 x,y coordinate, need to create a list for every Mousepress and convert to cv2.contour using PyQt5
    def mouseMoveEvent(self, event):
        list = []
        if (event.buttons() & Qt.LeftButton) & self.drawing:
            painter = QPainter(self.image)
            painter.setPen(QPen(self.brushColor, self.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
            painter.drawLine(self.lastPoint, event.pos())
            # self.lastPoint = event.pos()
            lastPoint=event.pos()
            self.update()
            print("LASTPOINTS", self.lastPoint)
            self.x = (self.lastPoint.x())
            self.y = (self.lastPoint.y())
            list.append(self.x)
            list.append(self.y)