Files
x06da/script/imgproc/CoverCalibration.py
alexgobbo 93844b103e V2
2024-10-30 11:23:40 +01:00

60 lines
1.8 KiB
Python

import ch.psi.pshell.imaging.RendererMode as RendererMode
TIMEOUT = 20000
#center_x=1044
#center_y=1019
#diameter_cover=1800
#rotation_degrees=0.0
#scale_x=0.3
#scale_y=0.3
renderer = show_panel(img)
w = SwingUtils.getWindow(renderer)
try:
renderer.setMode(RendererMode.Fit)
renderer.clearOverlays()
w.setSize(800,800)
w.setLocationRelativeTo(App.getInstance().getMainFrame())
overlay = Overlays.Text(renderer.getPenErrorText(), "", Font("Verdana", Font.PLAIN, 24), Point(20, 20))
overlay.setFixed(True)
overlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT)
renderer.addOverlay(overlay)
overlay.update("Click on the upper marker...")
upper = renderer.waitClick(TIMEOUT)
overlay.update("Click on the bottom marker...")
bottom = renderer.waitClick(TIMEOUT)
overlay.update("Click on the left marker...")
left = renderer.waitClick(TIMEOUT)
overlay.update("Click on the right marker...")
right = renderer.waitClick(TIMEOUT)
center_x = int((upper.x+ bottom.x)/2)
center_y = int((left.y + right.y)/2)
diam_x = abs (left.x - right.x)
diam_y = abs (upper.y - bottom.y)
diameter_cover = int (diam_x + diam_y)/2
cover_detection.config.center_x = center_x
cover_detection.config.center_y = center_y
cover_detection.config.diameter_cover = diameter_cover
scale_x = COVER_SIZE_MM / diam_x
scale_y = COVER_SIZE_MM / diam_y
#r = math.atan(-float(right.y-center_y) / (right.x - center_x))
#rotation_degrees = math.degrees(r)
rotation_degrees = 0.0 #Rotating image instead
cover_detection.config.scale_x = scale_x
cover_detection.config.scale_y = scale_y
cover_detection.config.rotation_degrees = rotation_degrees
cover_detection.config.save()
show_message("Success calibrating the camera")
finally:
w.dispose()