From 00f7a9d2b2b96b7a3a85a6d7d1fed3390a1412d8 Mon Sep 17 00:00:00 2001 From: Gabriel Van Zandycke Date: Mon, 27 Jan 2025 14:50:06 +0100 Subject: [PATCH] use k instead of kc and improve projects_in --- calib3d/calib.py | 6 +++++- tests/test_calib.py | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/calib3d/calib.py b/calib3d/calib.py index ea7ceba..be1ea78 100644 --- a/calib3d/calib.py +++ b/calib3d/calib.py @@ -2,6 +2,7 @@ import numpy as np import cv2 from .points import Point2D, Point3D, HomogeneousCoordinatesPoint +import warnings __doc__ = r""" @@ -164,6 +165,9 @@ def __init__(self, *, width: int, height: int, T: np.ndarray, R: np.ndarray, K: K (np.ndarray): camera matrix holding intrinsic parameters k (np.ndarray, optional): lens distortion coefficients. Defaults to None. """ + if 'kc' in _: + warnings.warn("The 'kc' argument is deprecated. Use 'k' instead.", Warning) + k = _['kc'] self.w = self.width = int(width) self.h = self.height = int(height) self.T = T @@ -400,7 +404,7 @@ def projects_in(self, point3D: Point3D) -> np.ndarray: Returns `True` where for points that projects in the image and `False` otherwise. """ point2D = self.project_3D_to_2D(point3D) - cond = np.stack((point2D.x >= 0, point2D.y >= 0, point2D.x <= self.width-1, point2D.y <= self.height-1, ~self.is_behind(point3D))) + cond = (point2D.x >= 0, point2D.y >= 0, point2D.x <= self.width-1, point2D.y <= self.height-1, np.squeeze(~self.is_behind(point3D))) return np.all(cond, axis=0) def dist_to_border(self, point3D: Point3D) -> np.ndarray: diff --git a/tests/test_calib.py b/tests/test_calib.py index 2ba862e..ce894b5 100644 --- a/tests/test_calib.py +++ b/tests/test_calib.py @@ -10,7 +10,7 @@ T = np.array([[-2360.16 ], [ -123.465], [ 2793.1 ]]) -kc = np.array([-0.00865297, -0.0148287, -0.00078693, 0.00025515, 0.]) +k = np.array([-0.00865297, -0.0148287, -0.00078693, 0.00025515, 0.]) width = 1936 height = 1458 @@ -68,7 +68,7 @@ def test_constructorlist(): assert np.all(points == Point3D([1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7])) def test_calib(): - calib = Calib(K=K, R=R, kc=kc, T=T, width=width, height=height) + calib = Calib(K=K, R=R, k=k, T=T, width=width, height=height) assert calib assert np.all(calib.P - np.array([[ 2.928916572117e+03, 5.164948427700e+01, 3.569704477840e+02, -3.809875516500e+06], @@ -86,7 +86,7 @@ def test_calib(): [-1180.57158572]]) < EPS) def test_projection(): - calib = Calib(K=K, R=R, kc=kc, T=T, width=width, height=height) + calib = Calib(K=K, R=R, k=k, T=T, width=width, height=height) # Single point point3D = Point3D(1400,750,0) @@ -101,7 +101,7 @@ def test_projection(): assert np.all(calib.project_2D_to_3D(points2D, Z=0) - points3D < 1.0e-2) # 0.01 cm error reprojection on image border def test_compute_length(): - calib = Calib(K=K, R=R, kc=kc, T=T, width=width, height=height) + calib = Calib(K=K, R=R, k=k, T=T, width=width, height=height) point3D = Point3D(1400,750,0) margin3D = 100 #cm margin2D = calib.compute_length2D(point3D, margin3D) @@ -109,6 +109,6 @@ def test_compute_length(): assert margin2D[0] - 107.87859964 < EPS def test_project_X(): - calib = Calib(K=K, R=R, kc=kc, T=T, width=width, height=height) + calib = Calib(K=K, R=R, k=k, T=T, width=width, height=height) point3D = Point3D(1400,750,0) assert np.all(calib.project_2D_to_3D(calib.project_3D_to_2D(point3D), X=1400) - point3D) < EPS