Skip to content

Commit

Permalink
use k instead of kc and improve projects_in
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-vanzandycke committed Jan 27, 2025
1 parent e6b4318 commit 00f7a9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion calib3d/calib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import cv2
from .points import Point2D, Point3D, HomogeneousCoordinatesPoint
import warnings

__doc__ = r"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_calib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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],
Expand All @@ -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)
Expand All @@ -101,14 +101,14 @@ 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)
assert len(margin2D.shape) == 1
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

0 comments on commit 00f7a9d

Please sign in to comment.