Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 1 | namespace frc971.vision.sift; |
| 2 | |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 3 | // Represents the location of a keypoint in field coordinates. |
| 4 | struct KeypointFieldLocation { |
| 5 | x:float; |
| 6 | y:float; |
| 7 | z:float; |
| 8 | } |
| 9 | |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 10 | // Represents a single feature extracted from an image. |
| 11 | table Feature { |
| 12 | // Contains the descriptor data. |
| 13 | // |
| 14 | // TODO(Brian): These are scaled to be convertible to chars. Should we do |
| 15 | // that to minimize storage space? Or maybe int16? |
| 16 | // |
| 17 | // The size of this depends on the parameters. It is width*width*hist_bins. |
| 18 | // Currently we have width=4 and hist_bins=8, which results in a size of |
| 19 | // 4*4*8=128. |
| 20 | descriptor:[float]; |
| 21 | |
| 22 | // Location of the keypoint. |
| 23 | x:float; |
| 24 | y:float; |
| 25 | |
| 26 | // Size of the keypoint neighborhood. |
| 27 | size:float; |
| 28 | |
| 29 | // Angle of the keypoint. |
| 30 | // This is in [0,360) clockwise. |
| 31 | angle:float; |
| 32 | |
| 33 | // How good of a keypoint this is. |
| 34 | response:float; |
| 35 | |
| 36 | // Which octave this keypoint is from. |
| 37 | octave:int; |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 38 | |
| 39 | // Where this feature's keypoint is on the field. This will only be filled out |
| 40 | // for training features, not ones extracted from query images. |
| 41 | field_location:KeypointFieldLocation; |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // Represents a single match between a training image and a query image. |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 45 | struct Match { |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 46 | // The index of the feature for the query image. |
| 47 | query_feature:int; |
| 48 | // The index of the feature for the training image. |
| 49 | train_feature:int; |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 50 | // How "good" the match is. |
| 51 | distance:float; |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // Represents all the matches between a single training image and a query |
| 55 | // image. |
| 56 | table ImageMatch { |
| 57 | matches:[Match]; |
| 58 | // The index of the training image within all the training images. |
| 59 | train_image:int; |
| 60 | } |
| 61 | |
| 62 | table TransformationMatrix { |
Jim Ostrowski | ad5d8a7 | 2020-02-28 00:15:26 -0800 | [diff] [blame^] | 63 | // The matrix data for a row-major 4x4 homogeneous transformation matrix. |
| 64 | // This implies the bottom row is (0, 0, 0, 1). |
Brian Silverman | 4770c7d | 2020-02-17 20:34:42 -0800 | [diff] [blame] | 65 | data:[float]; |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 68 | // Calibration information for a given camera on a given robot. |
| 69 | table CameraCalibration { |
| 70 | // The name of the camera node which this calibration data applies to. |
| 71 | node_name:string; |
| 72 | // The team number of the robot which this calibration data applies to. |
| 73 | team_number:int; |
| 74 | |
| 75 | // Intrinsics for the camera. |
| 76 | // |
| 77 | // This is the standard OpenCV intrinsics matrix in row major order (3x3). |
| 78 | intrinsics:[float]; |
| 79 | |
| 80 | // Fixed extrinsics for the camera. This transforms from camera coordinates to |
| 81 | // robot coordinates. For example: multiplying (0, 0, 0, 1) by this results in |
| 82 | // the position of the camera aperature in robot coordinates. |
| 83 | fixed_extrinsics:TransformationMatrix; |
| 84 | |
| 85 | // Extrinsics for a camera on a turret. This will only be filled out for |
| 86 | // applicable cameras. For turret-mounted cameras, fixed_extrinsics defines |
| 87 | // a position for the center of rotation of the turret, and this field defines |
| 88 | // a position for the camera on the turret. |
| 89 | // |
| 90 | // The combination of the two transformations is underdefined, so nothing can |
| 91 | // distinguish between the two parts of the final extrinsics for a given |
| 92 | // turret position. |
| 93 | // |
| 94 | // To get the final extrinsics for a camera using this transformation, |
| 95 | // multiply (in order): |
| 96 | // fixed_extrinsics |
| 97 | // rotation around the Z axis by the turret angle |
| 98 | // turret_extrinsics |
| 99 | turret_extrinsics:TransformationMatrix; |
Jim Ostrowski | ad5d8a7 | 2020-02-28 00:15:26 -0800 | [diff] [blame^] | 100 | |
| 101 | // This is the standard OpenCV 5 parameter distortion coefficients |
| 102 | dist_coeffs:[float]; |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Contains the information the EKF wants from an image matched against a single |
| 106 | // training image. |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 107 | // |
| 108 | // This is represented as a transformation to a target in field coordinates. |
| 109 | table CameraPose { |
| 110 | // Transformation matrix from the target to the camera's origin. |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 111 | // (0, 0, 0) is the aperture of the camera (we pretend it's an ideal pinhole |
| 112 | // camera). Positive Z is out of the camera. Positive X and Y are right |
| 113 | // handed, but which way they face depends on the camera extrinsics. |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 114 | camera_to_target:TransformationMatrix; |
| 115 | |
| 116 | // Field coordinates of the target, represented as a transformation matrix |
| 117 | // from the target to the field. |
| 118 | // (0, 0, 0) is the center of the field, on the level of most of the field |
| 119 | // (not the region under the truss). Positive X is towards the red alliance's |
| 120 | // PLAYER STATION. Positive Z is up. The coordinate system is right-handed. |
| 121 | // |
| 122 | // Note that the red PLAYER STATION is where the red drive teams are. This is |
| 123 | // often where the blue robots are shooting towards. |
| 124 | // |
| 125 | // The value here will be selected from a small, static set of targets we |
| 126 | // train images on. |
| 127 | field_to_target:TransformationMatrix; |
| 128 | } |
| 129 | |
| 130 | table ImageMatchResult { |
| 131 | // The matches from this image to each of the training images which matched. |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 132 | // Each member is against the same captured image. |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 133 | image_matches:[ImageMatch]; |
Jim Ostrowski | ad5d8a7 | 2020-02-28 00:15:26 -0800 | [diff] [blame^] | 134 | |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 135 | // The transformations for this image for each of the training images which |
| 136 | // matched. |
| 137 | // TODO(Brian): Include some kind of covariance information for these. |
| 138 | camera_poses:[CameraPose]; |
| 139 | |
| 140 | // The features for this image. |
| 141 | features:[Feature]; |
Brian Silverman | 967e5df | 2020-02-09 16:43:34 -0800 | [diff] [blame] | 142 | |
| 143 | // Timestamp when the frame was captured. |
| 144 | image_monotonic_timestamp_ns:long; |
Brian Silverman | 4d4a70d | 2020-02-17 13:03:19 -0800 | [diff] [blame] | 145 | |
| 146 | // Information about the camera which took this image. |
| 147 | camera_calibration:CameraCalibration; |
Jim Ostrowski | ad5d8a7 | 2020-02-28 00:15:26 -0800 | [diff] [blame^] | 148 | |
| 149 | // 2D image coordinate representing target location on the matched image |
| 150 | target_point_x:float; |
| 151 | target_point_y:float; |
Brian Silverman | fac9b87 | 2020-02-05 20:07:38 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | root_type ImageMatchResult; |