Skip to content

Commit 7385e15

Browse files
author
ycbiomtrics
committed
replace lsq fit with opencv
1 parent e7ee279 commit 7385e15

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/iris/nodes/eye_properties_estimation/circle_fit_for_eye_center_method.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Tuple
22

3+
import cv2
34
import numpy as np
45
from pydantic import Field
56

@@ -85,12 +86,15 @@ def _calculate_circle_fit_center(self, polygon: np.ndarray) -> Tuple[float, floa
8586
x = pts[:, 0]
8687
y = pts[:, 1]
8788

88-
A = np.column_stack([x, y, np.ones_like(x)])
89-
b = -(x * x + y * y)
89+
A = np.column_stack([x, y, np.ones_like(x)]).astype(np.float64)
90+
b = (-(x * x + y * y)).reshape(-1, 1).astype(np.float64)
9091

91-
coeffs, _, _, _ = np.linalg.lstsq(A, b, rcond=None)
92+
ok, coeffs = cv2.solve(A, b, flags=cv2.DECOMP_SVD)
93+
if not ok:
94+
raise EyeCentersEstimationError("Circle fit failed")
95+
96+
a, b_, c = coeffs.ravel()
9297

93-
a, b_, c = coeffs
9498
cx = -a / 2.0
9599
cy = -b_ / 2.0
96100

0 commit comments

Comments
 (0)