-
-
Save papr/98636456fd4b4d0621835ac0d3cffc77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import cv2 | |
from camera_intrinsics_estimation import Camera_Intrinsics_Estimation | |
logger = logging.getLogger(__name__) | |
class Camera_Intrinsics_Estimation_Debug(Camera_Intrinsics_Estimation): | |
def recent_events(self, events): | |
frame = events.get("frame") | |
if not frame: | |
return | |
if self.collect_new: | |
img = frame.img | |
try: | |
status, grid_points = cv2.findCirclesGrid( | |
img, (4, 11), flags=cv2.CALIB_CB_ASYMMETRIC_GRID | |
) | |
except cv2.error: | |
logger.exception( | |
f"Exception in cv2.findCirclesGrid() using shape={img.shape!r} " | |
f"dtype={img.dtype!r}" | |
) | |
return | |
if status: | |
self.img_points.append(grid_points) | |
self.obj_points.append(self.obj_grid) | |
self.collect_new = False | |
self.count -= 1 | |
self.button.status_text = "{:d} to go".format(self.count) | |
if self.count <= 0 and not self.calculated: | |
self.calculate() | |
self.button.status_text = "" | |
if self.window_should_close: | |
self.close_window() | |
if self.show_undistortion: | |
assert self.g_pool.capture.intrinsics | |
# This function is not yet compatible with the fisheye camera model and would have to be manually implemented. | |
# adjusted_k,roi = cv2.getOptimalNewCameraMatrix(cameraMatrix= np.array(self.camera_intrinsics[0]), distCoeffs=np.array(self.camera_intrinsics[1]), imageSize=self.camera_intrinsics[2], alpha=0.5,newImgSize=self.camera_intrinsics[2],centerPrincipalPoint=1) | |
self.undist_img = self.g_pool.capture.intrinsics.undistort(frame.img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment