From 580bbb4a4da93757a17f4ec3d0f80f1d34b9d0d9 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 20 Jan 2024 20:04:15 -0500 Subject: [PATCH] Draw calibration rainbow and scale thickness based on image size (#1174) --- .../cameras/CameraCalibrationCard.vue | 4 +-- .../vision/pipe/impl/DrawCalibrationPipe.java | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/photon-client/src/components/cameras/CameraCalibrationCard.vue b/photon-client/src/components/cameras/CameraCalibrationCard.vue index 5f9e0b44b..ba6ca5470 100644 --- a/photon-client/src/components/cameras/CameraCalibrationCard.vue +++ b/photon-client/src/components/cameras/CameraCalibrationCard.vue @@ -311,7 +311,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { /> { /> >, DrawCalibrationPipe.DrawCalibrationPipeParams> { + Scalar[] chessboardColors = + new Scalar[] { + ColorHelper.colorToScalar(Color.RED, 0.4), + ColorHelper.colorToScalar(Color.ORANGE, 0.4), + ColorHelper.colorToScalar(Color.GREEN, 0.4), + ColorHelper.colorToScalar(Color.BLUE, 0.4), + ColorHelper.colorToScalar(Color.MAGENTA, 0.4), + }; + @Override protected Void process(Pair> in) { var image = in.getLeft(); + var imgSz = image.size(); + var diag = Math.hypot(imgSz.width, imgSz.height); + + // heuristic: about 4px at a diagonal of 750px, or .5%, 'looks good'. keep it at least 3px at + // worst tho + int r = (int) Math.max(diag * 4.0 / 750.0, 3); + int thickness = (int) Math.max(diag * 1.0 / 600.0, 1); + + int i = 0; for (var target : in.getRight()) { for (var c : target.getTargetCorners()) { c = new Point( c.x / params.divisor.value.doubleValue(), c.y / params.divisor.value.doubleValue()); - var r = 4; + var r2 = r / Math.sqrt(2); - var color = ColorHelper.colorToScalar(Color.RED, 0.4); - Imgproc.circle(image, c, r, color, 1); - Imgproc.line(image, new Point(c.x - r2, c.y - r2), new Point(c.x + r2, c.y + r2), color); - Imgproc.line(image, new Point(c.x + r2, c.y - r2), new Point(c.x - r2, c.y + r2), color); + var color = chessboardColors[i % chessboardColors.length]; + Imgproc.circle(image, c, r, color, thickness); + Imgproc.line( + image, new Point(c.x - r2, c.y - r2), new Point(c.x + r2, c.y + r2), color, thickness); + Imgproc.line( + image, new Point(c.x + r2, c.y - r2), new Point(c.x - r2, c.y + r2), color, thickness); } + + i++; } return null;