- revised calibration
- cleaned up unused parameter - use CALIB_RATIONAL_MODEL for better wide angle matching
This commit is contained in:
@@ -37,22 +37,22 @@ class Calibration:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def save(self, filename: str):
|
def save(self, filename: str):
|
||||||
mtx, dist = self.get()
|
if self.mtx is not None and self.dist is not None:
|
||||||
np.savez(f"{filename}", mtx=mtx, dist=dist)
|
np.savez(f"{filename}", mtx=self.mtx, dist=self.dist)
|
||||||
calib = {'mtx': mtx.tolist(), 'dist': dist.tolist()}
|
print(f"Saved {filename} successfully!")
|
||||||
print(f"Saved {filename} successfully!")
|
|
||||||
|
|
||||||
def process(self, image: np.ndarray, thresh=3.0, r_vecs=None, t_vecs=None, flags=0):
|
def process(self, image: np.ndarray, thresh=3.0):
|
||||||
success = False
|
criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 3000, 0.001)
|
||||||
|
error = None
|
||||||
no = len(self.obj_points_list)
|
no = len(self.obj_points_list)
|
||||||
ni = len(self.img_points_list)
|
ni = len(self.img_points_list)
|
||||||
if no == ni and no > 0:
|
if no == ni and no > 0:
|
||||||
ret, mtx, dist, r_vecs, t_vecs = cv.calibrateCamera(self.obj_points_list, self.img_points_list, image.shape, self.mtx, self.dist,
|
ret, mtx, dist, r_vecs, t_vecs = cv.calibrateCamera(self.obj_points_list, self.img_points_list, image.shape, self.mtx, self.dist,
|
||||||
rvecs=r_vecs, tvecs=t_vecs, flags=flags)
|
rvecs=None, tvecs=None, flags=cv.CALIB_RATIONAL_MODEL, criteria=criteria)
|
||||||
|
|
||||||
if ret < thresh:
|
if ret < thresh:
|
||||||
success = True
|
error = ret
|
||||||
self.mtx = mtx
|
self.mtx = mtx
|
||||||
self.dist = dist
|
self.dist = dist
|
||||||
|
|
||||||
return success
|
return error
|
||||||
|
|||||||
@@ -186,9 +186,12 @@ class Detector(abc.ABC):
|
|||||||
print(f"{det}: Points matching success")
|
print(f"{det}: Points matching success")
|
||||||
elif k == ord('c'):
|
elif k == ord('c'):
|
||||||
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
|
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
|
||||||
if self.calibration.process(gray, thresh=3*len(self.detector)):
|
calib_err = self.calibration.process(gray, thresh=3*len(self.detector))
|
||||||
print(f"{self.camera_name}: Camera calibration success")
|
if calib_err is not None:
|
||||||
|
print(f"{self.camera_name}: Calibration success: Reprojection error={calib_err}")
|
||||||
self.calibration.save(f"{RESULTS_FOLDER}/{self.camera_name}_cal.npz")
|
self.calibration.save(f"{RESULTS_FOLDER}/{self.camera_name}_cal.npz")
|
||||||
|
else:
|
||||||
|
print(f"{self.camera_name}: Calibration failed")
|
||||||
elif k == ord('x'):
|
elif k == ord('x'):
|
||||||
self.calibration.calibration_clear()
|
self.calibration.calibration_clear()
|
||||||
elif k == ord('f'):
|
elif k == ord('f'):
|
||||||
|
|||||||
Reference in New Issue
Block a user