Updating polyline saving and drawing
This commit is contained in:
@@ -262,9 +262,9 @@ class AnnotationTab(QWidget):
|
||||
)
|
||||
return
|
||||
|
||||
# Compute bounding box and polyline from annotations
|
||||
bounds = self.annotation_canvas.compute_annotation_bounds()
|
||||
if not bounds:
|
||||
# Compute annotation parameters asbounding boxes and polylines from annotations
|
||||
parameters = self.annotation_canvas.get_annotation_parameters()
|
||||
if not parameters:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
"No Annotations",
|
||||
@@ -272,48 +272,56 @@ class AnnotationTab(QWidget):
|
||||
)
|
||||
return
|
||||
|
||||
polyline = self.annotation_canvas.get_annotation_polyline()
|
||||
# polyline = self.annotation_canvas.get_annotation_polyline()
|
||||
|
||||
try:
|
||||
# Save annotation to database
|
||||
annotation_id = self.db_manager.add_annotation(
|
||||
image_id=self.current_image_id,
|
||||
class_id=current_class["id"],
|
||||
bbox=bounds,
|
||||
annotator="manual",
|
||||
segmentation_mask=polyline,
|
||||
verified=False,
|
||||
)
|
||||
for param in parameters:
|
||||
bounds = param["bbox"]
|
||||
polyline = param["polyline"]
|
||||
|
||||
logger.info(
|
||||
f"Saved annotation (ID: {annotation_id}) for class '{current_class['class_name']}' "
|
||||
f"with {len(polyline)} polyline points"
|
||||
)
|
||||
try:
|
||||
# Save annotation to database
|
||||
annotation_id = self.db_manager.add_annotation(
|
||||
image_id=self.current_image_id,
|
||||
class_id=current_class["id"],
|
||||
bbox=bounds,
|
||||
annotator="manual",
|
||||
segmentation_mask=polyline,
|
||||
verified=False,
|
||||
)
|
||||
|
||||
QMessageBox.information(
|
||||
self,
|
||||
"Success",
|
||||
f"Annotation saved successfully!\n\n"
|
||||
f"Class: {current_class['class_name']}\n"
|
||||
f"Bounding box: ({bounds[0]:.3f}, {bounds[1]:.3f}) to ({bounds[2]:.3f}, {bounds[3]:.3f})\n"
|
||||
f"Polyline points: {len(polyline)}",
|
||||
)
|
||||
logger.info(
|
||||
f"Saved annotation (ID: {annotation_id}) for class '{current_class['class_name']}' "
|
||||
f"Bounding box: ({bounds[0]:.3f}, {bounds[1]:.3f}) to ({bounds[2]:.3f}, {bounds[3]:.3f})\n"
|
||||
f"with {len(polyline)} polyline points"
|
||||
)
|
||||
|
||||
# Optionally clear annotations after saving
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Clear Annotations",
|
||||
"Do you want to clear the annotations to start a new one?",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.Yes,
|
||||
)
|
||||
# QMessageBox.information(
|
||||
# self,
|
||||
# "Success",
|
||||
# f"Annotation saved successfully!\n\n"
|
||||
# f"Class: {current_class['class_name']}\n"
|
||||
# f"Bounding box: ({bounds[0]:.3f}, {bounds[1]:.3f}) to ({bounds[2]:.3f}, {bounds[3]:.3f})\n"
|
||||
# f"Polyline points: {len(polyline)}",
|
||||
# )
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
self.annotation_canvas.clear_annotations()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save annotation: {e}")
|
||||
QMessageBox.critical(
|
||||
self, "Error", f"Failed to save annotation:\n{str(e)}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save annotation: {e}")
|
||||
QMessageBox.critical(self, "Error", f"Failed to save annotation:\n{str(e)}")
|
||||
# Optionally clear annotations after saving
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Clear Annotations",
|
||||
"Do you want to clear the annotations to start a new one?",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.Yes,
|
||||
)
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
self.annotation_canvas.clear_annotations()
|
||||
logger.info("Cleared annotations after saving")
|
||||
|
||||
def _on_show_annotations(self):
|
||||
"""Load and display saved annotations from database."""
|
||||
@@ -348,6 +356,11 @@ class AnnotationTab(QWidget):
|
||||
|
||||
# Draw the polyline
|
||||
self.annotation_canvas.draw_saved_polyline(polyline, color, width=3)
|
||||
self.annotation_canvas.draw_saved_bbox(
|
||||
[ann["x_min"], ann["y_min"], ann["x_max"], ann["y_max"]],
|
||||
color,
|
||||
width=3,
|
||||
)
|
||||
drawn_count += 1
|
||||
|
||||
logger.info(f"Displayed {drawn_count} saved annotations from database")
|
||||
|
||||
Reference in New Issue
Block a user