From 1deb64dfa496a3d1007d9ac3d3fb0a636545618a Mon Sep 17 00:00:00 2001 From: Alex Pereira Date: Thu, 22 Jun 2023 15:32:20 -0400 Subject: [PATCH] Bumped version Bumped the version to 1.3.1 Removed the remap function from USBCamera USBCamera now only undistorts using cv.undistort() Signed-off-by: Alex Pereira --- frc_apriltags/apriltags.py | 14 +++++----- frc_apriltags/camera.py | 56 +++++++------------------------------- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 54 deletions(-) diff --git a/frc_apriltags/apriltags.py b/frc_apriltags/apriltags.py index deb2533..3c96070 100644 --- a/frc_apriltags/apriltags.py +++ b/frc_apriltags/apriltags.py @@ -27,7 +27,7 @@ def __init__(self, size: int = 6) -> None: self.comms = NetworkCommunications() # Creates a pupil apriltags detector - self.detector = pupil_apriltags.Detector(families = "tag16h5", nthreads = 10, quad_decimate = 1.0, quad_sigma = 0.0, refine_edges = 2.0, decode_sharpening = 1.00) + self.detector = pupil_apriltags.Detector(families = "tag16h5") # Variables self.tagSize = Units.inchesToMeters(size) @@ -38,9 +38,9 @@ def __init__(self, size: int = 6) -> None: def detectTags(self, stream, camera_matrix, vizualization: int = 0): """ - Detects AprilTags in a stream using pupil_apriltags. + Detects AprilTags in a stream using ``pupil_apriltags``. - :param stream: The images generated by reading a VideoCapture. + :param stream: The images generated by reading a ``VideoCapture``. :param camera_matrix: The camera's intrinsic calibration matrix. :param vizualization: 0 - Highlight, 1 - Highlight + Boxes, 2 - Highlight + Axes, 3 - Highlight + Boxes + Axes. :return: The detection result. @@ -55,14 +55,14 @@ def detectTags(self, stream, camera_matrix, vizualization: int = 0): # Define the intrinsic parameters of the camera intrinsic_properties = (camera_matrix[0, 0], camera_matrix[1, 1], camera_matrix[0, 2], camera_matrix[1, 2]) # fx, fy, cx, cy - # Detect the AprilTags in the image with Pupil Apriltags - detections = self.detector.detect(gray, estimate_tag_pose = True, camera_params = intrinsic_properties, tag_size = self.tagSize) + # Detect the AprilTags in the image with pupil_apriltags + detections = self.detector.detect(img = gray, estimate_tag_pose = True, camera_params = intrinsic_properties, tag_size = self.tagSize) # Variables to use in detections results = [] maxError = 1e-3 maxHamming = 1 - minConfidence = 30 + minConfidence = 50 # Variables to use in sorting the data best = None @@ -141,7 +141,7 @@ def getPose3D(self, poseMatrix = None): """ Calculates a WPILib ``Pose3d`` from the PupilApriltags matrix. - :param poseMatrix: A 3x4 ``numpy.ndarray()``. + :param poseMatrix: A 3x4 ``numpy.ndarray``. :return: A ``Pose3d`` object. """ # Variables diff --git a/frc_apriltags/camera.py b/frc_apriltags/camera.py index 56f008d..8a067bc 100644 --- a/frc_apriltags/camera.py +++ b/frc_apriltags/camera.py @@ -110,45 +110,6 @@ def calibrateCamera(self, dirPath: str): # Get results ret, self.camMatrix, self.camdistortion, rvecs, tvecs = self.calibrate.calibrateCamera() - def undistort(self): - """ - Undistorts an image using cv.undistort(). - - :return: The undistorted stream. - """ - # Creates a cameraMatrix - newCameraMatrix, roi = cv.getOptimalNewCameraMatrix(self.camMatrix, self.camdistortion, self.resolution, 1, self.resolution) - - # Undistorts the image - undistortedStream = cv.undistort(self.getStream(), self.camMatrix, self.camdistortion, None, newCameraMatrix) - - # Crops the image - x, y, w, h = roi - undistortedStream = undistortedStream[y:y+h, x:x+w] - - return undistortedStream - - def rectify(self): - """ - Undistorts an image using cv.remap(). - - :return: The undistorted stream. - """ - # Creates a cameraMatrix - newCameraMatrix, roi = cv.getOptimalNewCameraMatrix(self.camMatrix, self.camdistortion, self.resolution, 1, self.resolution) - - # Unpacks the ROI data - x, y, w, h = roi - - # Undistorts the image - mapx, mapy = cv.initUndistortRectifyMap(self.camMatrix, self.camdistortion, None, newCameraMatrix, (w,h), 5) - undistortedStream = cv.remap(self.getStream(), mapx, mapy, cv.INTER_LINEAR) - - # Crop the image - undistortedStream = undistortedStream[y:y+h, x:x+w] - - return undistortedStream - def getStream(self): """ Gets the stream from this camera's capture. @@ -160,18 +121,21 @@ def getStream(self): return self.stream - def getUndistortedStream(self, algorithm: int = 1): + def getUndistortedStream(self): """ Gets the undistorted stream from this camera's capture. - :param algorithm: 0 to use ``cv.undistort()``, 1 to use ``cv.remap()`` :return: The undistorted stream. """ - # Undistorts the stream - if (algorithm == 0): - self.stream = self.undistort() - elif (algorithm == 1): - self.stream = self.rectify() + # Creates a cameraMatrix + newCameraMatrix, roi = cv.getOptimalNewCameraMatrix(self.camMatrix, self.camdistortion, self.resolution, 1, self.resolution) + + # Undistorts the image + undistortedStream = cv.undistort(self.getStream(), self.camMatrix, self.camdistortion, None, newCameraMatrix) + + # Crops the image + x, y, w, h = roi + self.undistortedStream = undistortedStream[y:y+h, x:x+w] return self.stream diff --git a/pyproject.toml b/pyproject.toml index 9e49d52..54e588d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ name = "frc-apriltags" # Required # # For a discussion on single-sourcing the version, see # https://packaging.python.org/guides/single-sourcing-package-version/ -version = "1.3.0" # Required +version = "1.3.1" # Required # This is a one-line description or tagline of what your project does. This # corresponds to the "Summary" metadata field: