Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分享连点模式的自用的修改,并且想要dalao添加新功能。 #160

Closed
zhouyang986 opened this issue May 4, 2024 · 4 comments

Comments

@zhouyang986
Copy link

分享连点模式的自用的修改,并且想要dalao添加新功能。

修改了三个地方:

1.创造模式、连点模式描点的时候,老是手型鼠标样式,这样不能精确的知道把点描到哪里了,但是QT鼠标的拖动事件的鼠标样式优先级太高。笨方法是,在main.py里加了一行,把全局都改成十字线样式了。。

app = QtWidgets.QApplication([''])
# 设置整个应用程序使用CrossCursor光标样式,优先级最高
app.setOverrideCursor(QCursor(Qt.CrossCursor))

mainwindow = MainWindow()

2.连点模式下,那些用作辅助的填充的红色斜线和当前鼠标与初始点的连线。。我觉得挡视线,经常容易把要画的遮挡了,我在polygon.py中113行,添加了设置透明度的代码:

self.color.setAlpha(70) # 设置红色的透明度为70  还能看得清的
self.setPen(QtGui.QPen(self.color, self.line_width))

self.setBrush(QtGui.QBrush(self.color, QtCore.Qt.BrushStyle.FDiagPattern))

3.我发现那个黑色的十字“辅助线”,在不连点的时候挺跟手(实时跟着鼠标),但是在连点打标的时候,就不跟手了,有延迟的跟着鼠标。将canvas.py的class Annotation的mouseMoveEvent方法 里面的if self.pressd:以及后面的代码移到方法最后面去、而不是像之前在最上面。就好了,就能跟随鼠标了。(还是有轻微延迟、可能是性能问题?)
以下是一整个方法:

    def mouseMoveEvent(self, event: 'QtWidgets.QGraphicsSceneMouseEvent'):


        # 辅助线
        if self.guide_line_x is not None and self.guide_line_y is not None:
            if self.guide_line_x in self.items():
                self.removeItem(self.guide_line_x)

            if self.guide_line_y in self.items():
                self.removeItem(self.guide_line_y)

            self.guide_line_x = None
            self.guide_line_y = None

        pos = event.scenePos()
        if pos.x() < 0: pos.setX(0)
        if pos.x() > self.width()-1: pos.setX(self.width()-1)
        if pos.y() < 0: pos.setY(0)
        if pos.y() > self.height()-1: pos.setY(self.height()-1)
        # 限制在图片范围内

        if self.mode == STATUSMode.CREATE:
            if self.draw_mode == DRAWMode.POLYGON:
                # 随鼠标位置实时更新多边形
                self.current_graph.movePoint(len(self.current_graph.points)-1, pos)

        # 辅助线
        if  self.width()>0 and self.height()>0:
        # if self.guide_line_x is None and self.width()>0 and self.height()>0:
            self.guide_line_x = QtWidgets.QGraphicsLineItem(QtCore.QLineF(pos.x(), 0, pos.x(), self.height()))
            self.guide_line_x.setZValue(1)
            self.addItem(self.guide_line_x)
        if  self.width()>0 and self.height()>0:
        # if self.guide_line_y is None and self.width()>0 and self.height()>0:
            self.guide_line_y = QtWidgets.QGraphicsLineItem(QtCore.QLineF(0, pos.y(), self.width(), pos.y()))
            self.guide_line_y.setZValue(1)
            self.addItem(self.guide_line_y)

        # 状态栏,显示当前坐标
        if self.image_data is not None:
            x, y = round(pos.x()), round(pos.y())
            self.mainwindow.labelCoord.setText('xy: ({:>4d},{:>4d})'.format(x, y))

            data = self.image_data[y][x]
            if self.image_data.ndim == 2:
                self.mainwindow.labelData.setText('pix: [{:^3d}]'.format(data))
            elif self.image_data.ndim == 3:
                if len(data) == 3:
                    self.mainwindow.labelData.setText('rgb: [{:>3d},{:>3d},{:>3d}]'.format(data[0], data[1], data[2]))
                else:
                    self.mainwindow.labelData.setText('pix: [{}]'.format(data))


        # 拖动鼠标描点  ####就是把这部分移到后面了
        if self.pressd: # 拖动鼠标
            current_time = time.time()
            if self.last_draw_time is not None and current_time - self.last_draw_time < self.draw_interval:
                return  # 时间小于给定值不画点
            self.last_draw_time = current_time
            pos = event.scenePos()
            sceneX, sceneY = event.scenePos().x(), event.scenePos().y()
            sceneX = 0 if sceneX < 0 else sceneX
            sceneX = self.width()-1 if sceneX > self.width()-1 else sceneX
            sceneY = 0 if sceneY < 0 else sceneY
            sceneY = self.height()-1 if sceneY > self.height()-1 else sceneY
            
            if self.current_graph is not None:
                if self.draw_mode == DRAWMode.POLYGON:
                    # 移除随鼠标移动的点
                    self.current_graph.removePoint(len(self.current_graph.points) - 1)
                    # 添加当前点
                    self.current_graph.addPoint(QtCore.QPointF(sceneX, sceneY))
                    # 添加随鼠标移动的点
                    self.current_graph.addPoint(QtCore.QPointF(sceneX, sceneY))

        super(AnnotationScene, self).mouseMoveEvent(event)


另外想要dalao添加新的功能~~

能不能对SAM后的多边形 再用连点模式编辑细节呢(应该是对有些犬牙交错的标注场景很好用)

设定要编辑的 起始的点 和 结束的点,
从起始的点开始拖动,覆盖起始的点和结束的点中间的点。
就类似cvat那个标注工具那样,
cvat不能连点的,isat要是有这个功能的话那不知道好用到哪里去了~~

我直接请神:
@Alias-z
有空的话麻烦看一下啦,提前感谢大佬~

@Alias-z
Copy link
Contributor

Alias-z commented May 4, 2024

分享连点模式的自用的修改,并且想要dalao添加新功能。

修改了三个地方:

1.创造模式、连点模式描点的时候,老是手型鼠标样式,这样不能精确的知道把点描到哪里了,但是QT鼠标的拖动事件的鼠标样式优先级太高。笨方法是,在main.py里加了一行,把全局都改成十字线样式了。。

app = QtWidgets.QApplication([''])
# 设置整个应用程序使用CrossCursor光标样式,优先级最高
app.setOverrideCursor(QCursor(Qt.CrossCursor))

mainwindow = MainWindow()

2.连点模式下,那些用作辅助的填充的红色斜线和当前鼠标与初始点的连线。。我觉得挡视线,经常容易把要画的遮挡了,我在polygon.py中113行,添加了设置透明度的代码:

self.color.setAlpha(70) # 设置红色的透明度为70  还能看得清的
self.setPen(QtGui.QPen(self.color, self.line_width))

self.setBrush(QtGui.QBrush(self.color, QtCore.Qt.BrushStyle.FDiagPattern))

3.我发现那个黑色的十字“辅助线”,在不连点的时候挺跟手(实时跟着鼠标),但是在连点打标的时候,就不跟手了,有延迟的跟着鼠标。将canvas.py的class Annotation的mouseMoveEvent方法 里面的if self.pressd:以及后面的代码移到方法最后面去、而不是像之前在最上面。就好了,就能跟随鼠标了。(还是有轻微延迟、可能是性能问题?) 以下是一整个方法:

    def mouseMoveEvent(self, event: 'QtWidgets.QGraphicsSceneMouseEvent'):


        # 辅助线
        if self.guide_line_x is not None and self.guide_line_y is not None:
            if self.guide_line_x in self.items():
                self.removeItem(self.guide_line_x)

            if self.guide_line_y in self.items():
                self.removeItem(self.guide_line_y)

            self.guide_line_x = None
            self.guide_line_y = None

        pos = event.scenePos()
        if pos.x() < 0: pos.setX(0)
        if pos.x() > self.width()-1: pos.setX(self.width()-1)
        if pos.y() < 0: pos.setY(0)
        if pos.y() > self.height()-1: pos.setY(self.height()-1)
        # 限制在图片范围内

        if self.mode == STATUSMode.CREATE:
            if self.draw_mode == DRAWMode.POLYGON:
                # 随鼠标位置实时更新多边形
                self.current_graph.movePoint(len(self.current_graph.points)-1, pos)

        # 辅助线
        if  self.width()>0 and self.height()>0:
        # if self.guide_line_x is None and self.width()>0 and self.height()>0:
            self.guide_line_x = QtWidgets.QGraphicsLineItem(QtCore.QLineF(pos.x(), 0, pos.x(), self.height()))
            self.guide_line_x.setZValue(1)
            self.addItem(self.guide_line_x)
        if  self.width()>0 and self.height()>0:
        # if self.guide_line_y is None and self.width()>0 and self.height()>0:
            self.guide_line_y = QtWidgets.QGraphicsLineItem(QtCore.QLineF(0, pos.y(), self.width(), pos.y()))
            self.guide_line_y.setZValue(1)
            self.addItem(self.guide_line_y)

        # 状态栏,显示当前坐标
        if self.image_data is not None:
            x, y = round(pos.x()), round(pos.y())
            self.mainwindow.labelCoord.setText('xy: ({:>4d},{:>4d})'.format(x, y))

            data = self.image_data[y][x]
            if self.image_data.ndim == 2:
                self.mainwindow.labelData.setText('pix: [{:^3d}]'.format(data))
            elif self.image_data.ndim == 3:
                if len(data) == 3:
                    self.mainwindow.labelData.setText('rgb: [{:>3d},{:>3d},{:>3d}]'.format(data[0], data[1], data[2]))
                else:
                    self.mainwindow.labelData.setText('pix: [{}]'.format(data))


        # 拖动鼠标描点  ####就是把这部分移到后面了
        if self.pressd: # 拖动鼠标
            current_time = time.time()
            if self.last_draw_time is not None and current_time - self.last_draw_time < self.draw_interval:
                return  # 时间小于给定值不画点
            self.last_draw_time = current_time
            pos = event.scenePos()
            sceneX, sceneY = event.scenePos().x(), event.scenePos().y()
            sceneX = 0 if sceneX < 0 else sceneX
            sceneX = self.width()-1 if sceneX > self.width()-1 else sceneX
            sceneY = 0 if sceneY < 0 else sceneY
            sceneY = self.height()-1 if sceneY > self.height()-1 else sceneY
            
            if self.current_graph is not None:
                if self.draw_mode == DRAWMode.POLYGON:
                    # 移除随鼠标移动的点
                    self.current_graph.removePoint(len(self.current_graph.points) - 1)
                    # 添加当前点
                    self.current_graph.addPoint(QtCore.QPointF(sceneX, sceneY))
                    # 添加随鼠标移动的点
                    self.current_graph.addPoint(QtCore.QPointF(sceneX, sceneY))

        super(AnnotationScene, self).mouseMoveEvent(event)

另外想要dalao添加新的功能~~

能不能对SAM后的多边形 再用连点模式编辑细节呢(应该是对有些犬牙交错的标注场景很好用)

设定要编辑的 起始的点 和 结束的点, 从起始的点开始拖动,覆盖起始的点和结束的点中间的点。 就类似cvat那个标注工具那样, cvat不能连点的,isat要是有这个功能的话那不知道好用到哪里去了~~

我直接请神: @Alias-z 有空的话麻烦看一下啦,提前感谢大佬~

谢谢建议 我最近看一下 ;)

@zhouyang986
Copy link
Author

好耶~ @Alias-z

Alias-z added a commit to Alias-z/ISAT_with_segment_anything that referenced this issue May 6, 2024
根据issue yatengLG#160 的建议,添加了新功能的第一步:按R选中同一个polygon的两点时可以自动选中中间所有点(最短路径)。大部分逻辑okay了,还有bug要查,不过不影响软件正常使用
@Alias-z
Copy link
Contributor

Alias-z commented May 6, 2024

好耶~ @Alias-z

你说的第三条好像确实有用,已经修改了

新功能第一步见 pull request #161 等LG 合并PR

有空可以提交PR 一起贡献呀 :)

yatengLG added a commit that referenced this issue May 7, 2024
[Experimental] batch vertexes modification (issue #160)
@yatengLG
Copy link
Owner

yatengLG commented May 7, 2024

cvat-min

效果实现了,R快捷键开启repaint模式,点击一个顶点开始重绘,再次点击同一多边形的另一个顶点完成绘制。

排查下bug,稍后上传。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants