From bd00e4fbd6c6fd358b8744fac71cfb32a6be5676 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 11 Jul 2025 14:28:50 +0200 Subject: [PATCH] Calibration tweaks --- trap/laser_calibration.py | 33 ++++++++++++++++++++++++++------- trap/lines.py | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/trap/laser_calibration.py b/trap/laser_calibration.py index d5a36bb..1848f8b 100644 --- a/trap/laser_calibration.py +++ b/trap/laser_calibration.py @@ -1,19 +1,24 @@ from argparse import ArgumentParser +import enum import json from pathlib import Path +import time from typing import Optional import cv2 import numpy as np from trap.base import DataclassJSONEncoder, DistortedCamera, Frame -from trap.lines import CoordinateSpace, RenderableLines, SrgbaColor, cross_points +from trap.lines import CoordinateSpace, RenderableLine, RenderableLines, RenderablePoint, RenderablePosition, SrgbaColor, cross_points from trap.node import Node from trap.stage import Coordinate +class Modes(enum.Enum): + POINTS = 1 + TEST_LINE = 2 class LaserCalibration(Node): """ @@ -39,6 +44,7 @@ class LaserCalibration(Node): self._is_dragging = False self.laser_points = {} self.image_points = {} + self.mode = Modes.POINTS self.H = None self.img_size = (1920,1080) @@ -111,13 +117,22 @@ class LaserCalibration(Node): cv2.imshow('laser_calib', img) lines = [] - if self._selected_point: - point = self.laser_points[self._selected_point] - lines.extend(cross_points(point[0], point[1], 100, SrgbaColor(0,1,0,1))) + if self.mode == Modes.TEST_LINE: + lines.append(RenderableLine([ + RenderablePoint((i,time.time()%18), SrgbaColor(0,1,0,1)) for i in range(-15, 40) + + ])) + # render in laser space + rl = RenderableLines(lines, CoordinateSpace.WORLD) + self.laser_sock.send_json(rl, cls=DataclassJSONEncoder) + else: + if self._selected_point: + point = self.laser_points[self._selected_point] + lines.extend(cross_points(point[0], point[1], 100, SrgbaColor(0,1,0,1))) - # render in laser space - rl = RenderableLines(lines, CoordinateSpace.LASER) - self.laser_sock.send_json(rl, cls=DataclassJSONEncoder) + # render in laser space + rl = RenderableLines(lines, CoordinateSpace.LASER) + self.laser_sock.send_json(rl, cls=DataclassJSONEncoder) # print(json.dumps(rl, cls=DataclassJSONEncoder)) @@ -138,6 +153,10 @@ class LaserCalibration(Node): if key == ord('d') and self._selected_point: self.delete_point(self._selected_point) + + if key == ord('t'): + self.mode = Modes.TEST_LINE if self.mode == Modes.POINTS else Modes.POINTS + print(self.mode) # arrow up (82), down (84), arrow left(81) if self._selected_point and key in [81, 84, 82, 83, diff --git a/trap/lines.py b/trap/lines.py index 28ba645..e6de99c 100644 --- a/trap/lines.py +++ b/trap/lines.py @@ -77,7 +77,7 @@ class RenderableLines(): space: CoordinateSpace = CoordinateSpace.WORLD def as_simplified(self, method: SimplifyMethod = SimplifyMethod.RDP, factor = SIMPLIFY_FACTOR_RDP): - """Wraps RenderableLine simplification""" + """Wraps RenderableLine simplification, smaller factor is more detailed""" return RenderableLines( [line.as_simplified(method, factor) for line in self.lines] )