Calibration tweaks
This commit is contained in:
parent
0e29371e94
commit
bd00e4fbd6
2 changed files with 27 additions and 8 deletions
|
@ -1,19 +1,24 @@
|
||||||
|
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
import enum
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from trap.base import DataclassJSONEncoder, DistortedCamera, Frame
|
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.node import Node
|
||||||
from trap.stage import Coordinate
|
from trap.stage import Coordinate
|
||||||
|
|
||||||
|
|
||||||
|
class Modes(enum.Enum):
|
||||||
|
POINTS = 1
|
||||||
|
TEST_LINE = 2
|
||||||
|
|
||||||
class LaserCalibration(Node):
|
class LaserCalibration(Node):
|
||||||
"""
|
"""
|
||||||
|
@ -39,6 +44,7 @@ class LaserCalibration(Node):
|
||||||
self._is_dragging = False
|
self._is_dragging = False
|
||||||
self.laser_points = {}
|
self.laser_points = {}
|
||||||
self.image_points = {}
|
self.image_points = {}
|
||||||
|
self.mode = Modes.POINTS
|
||||||
self.H = None
|
self.H = None
|
||||||
|
|
||||||
self.img_size = (1920,1080)
|
self.img_size = (1920,1080)
|
||||||
|
@ -111,6 +117,15 @@ class LaserCalibration(Node):
|
||||||
cv2.imshow('laser_calib', img)
|
cv2.imshow('laser_calib', img)
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
|
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:
|
if self._selected_point:
|
||||||
point = self.laser_points[self._selected_point]
|
point = self.laser_points[self._selected_point]
|
||||||
lines.extend(cross_points(point[0], point[1], 100, SrgbaColor(0,1,0,1)))
|
lines.extend(cross_points(point[0], point[1], 100, SrgbaColor(0,1,0,1)))
|
||||||
|
@ -139,6 +154,10 @@ class LaserCalibration(Node):
|
||||||
if key == ord('d') and self._selected_point:
|
if key == ord('d') and self._selected_point:
|
||||||
self.delete_point(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)
|
# arrow up (82), down (84), arrow left(81)
|
||||||
if self._selected_point and key in [81, 84, 82, 83,
|
if self._selected_point and key in [81, 84, 82, 83,
|
||||||
ord('h'), ord('j'), ord('k'), ord('l'),
|
ord('h'), ord('j'), ord('k'), ord('l'),
|
||||||
|
|
|
@ -77,7 +77,7 @@ class RenderableLines():
|
||||||
space: CoordinateSpace = CoordinateSpace.WORLD
|
space: CoordinateSpace = CoordinateSpace.WORLD
|
||||||
|
|
||||||
def as_simplified(self, method: SimplifyMethod = SimplifyMethod.RDP, factor = SIMPLIFY_FACTOR_RDP):
|
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(
|
return RenderableLines(
|
||||||
[line.as_simplified(method, factor) for line in self.lines]
|
[line.as_simplified(method, factor) for line in self.lines]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue