From 287fc032678fe61ad2d9318be0bc6eabfb5129b5 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Tue, 25 Apr 2023 19:51:04 +0200 Subject: Adding a method to show K and D camera parameters. --- src/argaze/ArUcoMarkers/ArUcoCamera.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/argaze/ArUcoMarkers/ArUcoCamera.py b/src/argaze/ArUcoMarkers/ArUcoCamera.py index 97436e9..c3c03bd 100644 --- a/src/argaze/ArUcoMarkers/ArUcoCamera.py +++ b/src/argaze/ArUcoMarkers/ArUcoCamera.py @@ -6,6 +6,7 @@ from argaze import DataStructures import json import numpy +import cv2 import cv2.aruco as aruco K0 = numpy.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 0.]]) @@ -55,6 +56,27 @@ class CalibrationData(): return output + def draw(self, frame, width:float, height:float, z:float, color=(0, 0, 255)): + """Draw grid to display K and D""" + + # Edit 3D grid + grid_3D = [] + for x in range(-int(width/2), int(width/2)): + for y in range(-int(height/2), int(height/2)): + grid_3D.append([x, y, z]) + + # Project 3d grid + grid_2D, _ = cv2.projectPoints(numpy.array(grid_3D).astype(float), numpy.array([0., 0., 0.]), numpy.array([0., 0., 0.]), numpy.array(self.K), -numpy.array(self.D)) + + # Draw projection + for point in grid_2D: + + # Ignore point out out field + try: + cv2.circle(frame, point.astype(int)[0], 1, color, -1) + except: + pass + class ArUcoCamera(CalibrationData): """Handle camera calibration process.""" -- cgit v1.1