Skip to content

Commit

Permalink
catch errors with charuco config, expand max input value for charuco …
Browse files Browse the repository at this point in the history
…size but remove constraints on spin box size.
  • Loading branch information
mprib committed Oct 23, 2024
1 parent 92d85bc commit d928c91
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions caliscope/gui/charuco_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

from PySide6.QtCore import Qt
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import (
QApplication,
QCheckBox,
Expand Down Expand Up @@ -167,10 +168,25 @@ def build_charuco(self):
charuco_height = int(charuco_width * (board_height / board_width))

logger.info("Building charuco thumbnail...")
charuco_img = self.charuco.board_pixmap(charuco_width, charuco_height)
self.charuco_display.setPixmap(charuco_img)

self.controller.update_charuco(self.charuco)
try:
charuco_img = self.charuco.board_pixmap(charuco_width, charuco_height)
self.charuco_display.setPixmap(charuco_img)
# Clear any previous error message
self.charuco_display.setStyleSheet("")
self.charuco_display.setToolTip("")
except Exception as e:
logger.error(f"Failed to create charuco board: {str(e)}")
error_msg = "Unable to create board with current dimensions.\nThe aspect ratio may be too extreme."
self.charuco_display.setPixmap(QPixmap()) # Clear the pixmap
self.charuco_display.setText(error_msg)
# Optional: Add some styling to make the error message stand out
self.charuco_display.setStyleSheet("QLabel { color: red; }")
self.charuco_display.setToolTip("Try adjusting the width and height to have a less extreme ratio")

charuco_img = self.charuco.board_pixmap(charuco_width, charuco_height)
self.charuco_display.setPixmap(charuco_img)

self.controller.update_charuco(self.charuco)


class CharucoConfigGroup(QWidget):
Expand All @@ -182,27 +198,24 @@ def __init__(self, controller: Controller):
self.column_spin = QSpinBox()
self.column_spin.setMinimum(3)
self.column_spin.setValue(self.params["columns"])
# self.column_spin.setMaximumWidth(50)

self.row_spin = QSpinBox()
self.row_spin.setMinimum(4)
self.row_spin.setValue(self.params["rows"])
# self.row_spin.setMaximumWidth(50)

self.width_spin = QDoubleSpinBox()
self.width_spin.setMinimum(1)
self.width_spin.setMaximum(10000)
self.width_spin.setValue(self.params["board_width"])
self.width_spin.setMaximumWidth(50)

self.length_spin = QDoubleSpinBox()
self.length_spin.setMaximum(10000)
self.length_spin.setMinimum(1)
self.length_spin.setValue(self.params["board_height"])
self.length_spin.setMaximumWidth(50)

self.units = QComboBox()
self.units.addItems(["cm", "inch"])
self.units.setCurrentText(self.params["units"])
self.units.setMaximumWidth(100)

self.invert_checkbox = QCheckBox("&Invert")
self.invert_checkbox.setChecked(self.params["inverted"])
Expand Down Expand Up @@ -241,18 +254,16 @@ def __init__(self, controller: Controller):


if __name__ == "__main__":
app = QApplication(sys.argv)
from caliscope import __root__
from caliscope.helper import copy_contents
from caliscope.calibration.charuco import Charuco
app = QApplication(sys.argv)

# Define the input file path here.
original_workspace_dir = Path(__root__, "tests", "sessions", "prerecorded_calibration")
# workspace_dir = Path(
# __root__, "tests", "sessions_copy_delete", "prerecorded_calibration"
# )

# copy_contents(original_workspace_dir, workspace_dir)
workspace_dir = Path(r"C:\Users\Mac Prible\OneDrive\caliscope\prerecorded_workflow")
copy_contents(original_workspace_dir, workspace_dir)
controller = Controller(workspace_dir)
charuco_page = CharucoWidget(controller)

Expand Down

0 comments on commit d928c91

Please sign in to comment.