Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 1 | #include <fstream> |
| 2 | |
| 3 | #include "aos/logging/implementations.h" |
| 4 | #include "aos/logging/logging.h" |
| 5 | #include "aos/vision/blob/codec.h" |
| 6 | #include "aos/vision/blob/find_blob.h" |
| 7 | #include "aos/vision/events/socket_types.h" |
| 8 | #include "aos/vision/events/udp.h" |
| 9 | #include "aos/vision/image/image_dataset.h" |
| 10 | #include "aos/vision/image/image_stream.h" |
| 11 | #include "aos/vision/image/reader.h" |
| 12 | #include "y2019/vision/target_finder.h" |
| 13 | |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 14 | // CERES Clashes with logging symbols... |
| 15 | #include "ceres/ceres.h" |
| 16 | |
Austin Schuh | e623f9f | 2019-03-03 12:24:03 -0800 | [diff] [blame] | 17 | DEFINE_int32(camera_id, -1, "The camera ID to calibrate"); |
Austin Schuh | 3b815f1 | 2019-03-08 20:10:37 -0800 | [diff] [blame] | 18 | DEFINE_string(prefix, "", "The image filename prefix"); |
Austin Schuh | e623f9f | 2019-03-03 12:24:03 -0800 | [diff] [blame] | 19 | |
Austin Schuh | d6cc1e9 | 2019-03-08 21:01:51 -0800 | [diff] [blame] | 20 | DEFINE_string(constants, "y2019/vision/constants.cc", |
| 21 | "Path to the constants file to update"); |
| 22 | |
Austin Schuh | d2e48da | 2019-03-08 20:52:32 -0800 | [diff] [blame] | 23 | DEFINE_double(beginning_tape_measure_reading, 11, |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 24 | "The tape measure measurement (in inches) of the first image."); |
Austin Schuh | d2e48da | 2019-03-08 20:52:32 -0800 | [diff] [blame] | 25 | DEFINE_int32(image_count, 75, "The number of images to capture"); |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 26 | DEFINE_double(tape_start_x, -12.5, |
| 27 | "The starting location of the tape measure in x relative to the " |
| 28 | "CG in inches."); |
| 29 | DEFINE_double(tape_start_y, -0.5, |
| 30 | "The starting location of the tape measure in y relative to the " |
| 31 | "CG in inches."); |
Austin Schuh | d2e48da | 2019-03-08 20:52:32 -0800 | [diff] [blame] | 32 | |
| 33 | DEFINE_double( |
| 34 | tape_direction_x, -1.0, |
| 35 | "The x component of \"1\" inch along the tape measure in meters."); |
| 36 | DEFINE_double( |
| 37 | tape_direction_y, 0.0, |
| 38 | "The y component of \"1\" inch along the tape measure in meters."); |
| 39 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 40 | using ::aos::monotonic_clock; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 41 | using ::aos::events::DataSocket; |
| 42 | using ::aos::events::RXUdpSocket; |
| 43 | using ::aos::events::TCPServer; |
| 44 | using ::aos::vision::DataRef; |
| 45 | using ::aos::vision::Int32Codec; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 46 | using aos::vision::Segment; |
| 47 | |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 48 | using ceres::CENTRAL; |
| 49 | using ceres::CostFunction; |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 50 | using ceres::NumericDiffCostFunction; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 51 | using ceres::Problem; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 52 | using ceres::Solve; |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 53 | using ceres::Solver; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 54 | |
| 55 | namespace y2019 { |
| 56 | namespace vision { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 57 | namespace { |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 58 | |
| 59 | constexpr double kInchesToMeters = 0.0254; |
| 60 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 61 | } // namespace |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 62 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 63 | ::std::array<double, 3> GetError(const DatasetInfo &info, |
| 64 | const double *const extrinsics, |
| 65 | const double *const geometry, int i) { |
| 66 | const ExtrinsicParams extrinsic_params = ExtrinsicParams::get(extrinsics); |
| 67 | const CameraGeometry geo = CameraGeometry::get(geometry); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 68 | |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 69 | const double s = sin(geo.heading + extrinsic_params.r2); |
| 70 | const double c = cos(geo.heading + extrinsic_params.r2); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 71 | |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 72 | // Take the tape measure starting point (this will be at the perimeter of the |
| 73 | // robot), add the offset to the first sample, and then add the per sample |
| 74 | // offset. |
Austin Schuh | 6cac52c | 2019-03-08 20:03:33 -0800 | [diff] [blame] | 75 | const double dx = (info.to_tape_measure_start[0] + |
| 76 | (info.beginning_tape_measure_reading + i) * |
| 77 | info.tape_measure_direction[0]) - |
| 78 | (geo.location[0] + c * extrinsic_params.z); |
| 79 | const double dy = (info.to_tape_measure_start[1] + |
| 80 | (info.beginning_tape_measure_reading + i) * |
| 81 | info.tape_measure_direction[1]) - |
| 82 | (geo.location[1] + s * extrinsic_params.z); |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 83 | |
Austin Schuh | 6cac52c | 2019-03-08 20:03:33 -0800 | [diff] [blame] | 84 | constexpr double kCalibrationTargetHeight = 28.5 * kInchesToMeters; |
| 85 | const double dz = |
| 86 | kCalibrationTargetHeight - (geo.location[2] + extrinsic_params.y); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 87 | return {{dx, dy, dz}}; |
| 88 | } |
| 89 | |
| 90 | void main(int argc, char **argv) { |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 91 | using namespace y2019::vision; |
Austin Schuh | 3b815f1 | 2019-03-08 20:10:37 -0800 | [diff] [blame] | 92 | ::gflags::ParseCommandLineFlags(&argc, &argv, false); |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 93 | |
| 94 | DatasetInfo info = { |
Austin Schuh | e623f9f | 2019-03-03 12:24:03 -0800 | [diff] [blame] | 95 | FLAGS_camera_id, |
Austin Schuh | d2e48da | 2019-03-08 20:52:32 -0800 | [diff] [blame] | 96 | {{FLAGS_tape_start_x * kInchesToMeters, |
| 97 | FLAGS_tape_start_y * kInchesToMeters}}, |
| 98 | {{FLAGS_tape_direction_x * kInchesToMeters, |
| 99 | FLAGS_tape_direction_y * kInchesToMeters}}, |
| 100 | FLAGS_beginning_tape_measure_reading, |
Austin Schuh | 3b815f1 | 2019-03-08 20:10:37 -0800 | [diff] [blame] | 101 | FLAGS_prefix.c_str(), |
Austin Schuh | d2e48da | 2019-03-08 20:52:32 -0800 | [diff] [blame] | 102 | FLAGS_image_count, |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 105 | TargetFinder target_finder; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 106 | |
| 107 | ceres::Problem problem; |
| 108 | |
| 109 | struct Sample { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 110 | ::std::unique_ptr<double[]> extrinsics; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 111 | int i; |
| 112 | }; |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 113 | ::std::vector<Sample> all_extrinsics; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 114 | double intrinsics[IntrinsicParams::kNumParams]; |
| 115 | IntrinsicParams().set(&intrinsics[0]); |
| 116 | |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 117 | double geometry[CameraGeometry::kNumParams]; |
Austin Schuh | 9bb57fe | 2019-03-08 20:23:47 -0800 | [diff] [blame] | 118 | { |
| 119 | // Assume the camera is near the center of the robot, and start by pointing |
| 120 | // it from the center of the robot to the location of the first target. |
| 121 | CameraGeometry camera_geometry; |
| 122 | const double x = |
| 123 | info.to_tape_measure_start[0] + |
| 124 | info.beginning_tape_measure_reading * info.tape_measure_direction[0]; |
| 125 | const double y = |
| 126 | info.to_tape_measure_start[1] + |
| 127 | info.beginning_tape_measure_reading * info.tape_measure_direction[1]; |
| 128 | camera_geometry.heading = ::std::atan2(y, x); |
| 129 | printf("Inital heading is %f\n", camera_geometry.heading); |
| 130 | camera_geometry.set(&geometry[0]); |
| 131 | } |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 132 | |
| 133 | Solver::Options options; |
| 134 | options.minimizer_progress_to_stdout = false; |
| 135 | Solver::Summary summary; |
| 136 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 137 | ::std::cout << summary.BriefReport() << "\n"; |
Austin Schuh | cacc692 | 2019-03-06 20:44:30 -0800 | [diff] [blame] | 138 | IntrinsicParams intrinsics_ = IntrinsicParams::get(&intrinsics[0]); |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 139 | ::std::cout << "rup = " << intrinsics_.mount_angle * 180 / M_PI << ";\n"; |
| 140 | ::std::cout << "fl = " << intrinsics_.focal_length << ";\n"; |
| 141 | ::std::cout << "error = " << summary.final_cost << ";\n"; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 142 | |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 143 | for (int i = 0; i < info.num_images; ++i) { |
Austin Schuh | 3b815f1 | 2019-03-08 20:10:37 -0800 | [diff] [blame] | 144 | ::aos::vision::DatasetFrame frame = |
| 145 | aos::vision::LoadFile(FLAGS_prefix + std::to_string(i) + ".yuyv"); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 146 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 147 | const ::aos::vision::ImageFormat fmt{640, 480}; |
| 148 | ::aos::vision::BlobList imgs = |
Brian Silverman | 37b15b3 | 2019-03-10 13:30:18 -0700 | [diff] [blame] | 149 | ::aos::vision::FindBlobs(aos::vision::SlowYuyvYThreshold( |
Austin Schuh | 2851e7f | 2019-03-06 20:45:19 -0800 | [diff] [blame] | 150 | fmt, frame.data.data(), TargetFinder::GetThresholdValue())); |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 151 | target_finder.PreFilter(&imgs); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 152 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 153 | constexpr bool verbose = false; |
Austin Schuh | 6e56faf | 2019-03-10 14:04:57 -0700 | [diff] [blame] | 154 | ::std::vector<Polygon> raw_polys; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 155 | for (const RangeImage &blob : imgs) { |
Ben Fredrickson | f7b6852 | 2019-03-02 21:19:42 -0800 | [diff] [blame] | 156 | // Convert blobs to contours in the corrected space. |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 157 | ContourNode *contour = target_finder.GetContour(blob); |
Austin Schuh | 6e56faf | 2019-03-10 14:04:57 -0700 | [diff] [blame] | 158 | ::std::vector<::Eigen::Vector2f> unwarped_contour = |
Austin Schuh | e501597 | 2019-03-09 17:47:34 -0800 | [diff] [blame] | 159 | target_finder.UnWarpContour(contour); |
Austin Schuh | 6e56faf | 2019-03-10 14:04:57 -0700 | [diff] [blame] | 160 | const Polygon polygon = |
| 161 | target_finder.FindPolygon(::std::move(unwarped_contour), verbose); |
| 162 | if (!polygon.segments.empty()) { |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 163 | raw_polys.push_back(polygon); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Calculate each component side of a possible target. |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 168 | const ::std::vector<TargetComponent> target_component_list = |
Austin Schuh | 32ffac2 | 2019-03-09 22:42:02 -0800 | [diff] [blame] | 169 | target_finder.FillTargetComponentList(raw_polys, verbose); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 170 | |
| 171 | // Put the compenents together into targets. |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 172 | const ::std::vector<Target> target_list = |
| 173 | target_finder.FindTargetsFromComponents(target_component_list, verbose); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 174 | |
Austin Schuh | 0fd1cef | 2019-03-08 20:05:14 -0800 | [diff] [blame] | 175 | // Now, iterate over the targets (in pixel space). Generate a residual |
| 176 | // block for each valid target which compares the actual pixel locations |
| 177 | // with the expected pixel locations given the intrinsics and extrinsics. |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 178 | for (const Target &target : target_list) { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 179 | const ::std::array<::aos::vision::Vector<2>, 8> target_value = |
Austin Schuh | 2894e90 | 2019-03-03 21:12:46 -0800 | [diff] [blame] | 180 | target.ToPointList(); |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 181 | const ::std::array<::aos::vision::Vector<2>, 8> template_value = |
| 182 | target_finder.GetTemplateTarget().ToPointList(); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 183 | |
Austin Schuh | 0fd1cef | 2019-03-08 20:05:14 -0800 | [diff] [blame] | 184 | all_extrinsics.push_back( |
| 185 | {::std::unique_ptr<double[]>(new double[ExtrinsicParams::kNumParams]), |
| 186 | i}); |
| 187 | double *extrinsics = all_extrinsics.back().extrinsics.get(); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 188 | ExtrinsicParams().set(extrinsics); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 189 | |
| 190 | for (size_t j = 0; j < 8; ++j) { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 191 | // Template target in target space as documented by GetTemplateTarget() |
| 192 | const ::aos::vision::Vector<2> template_point = template_value[j]; |
| 193 | // Target in pixel space. |
| 194 | const ::aos::vision::Vector<2> target_point = target_value[j]; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 195 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 196 | // Now build up the residual block. |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 197 | auto ftor = [template_point, target_point]( |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 198 | const double *const intrinsics, |
| 199 | const double *const extrinsics, double *residual) { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 200 | const IntrinsicParams intrinsic_params = |
| 201 | IntrinsicParams::get(intrinsics); |
| 202 | const ExtrinsicParams extrinsic_params = |
| 203 | ExtrinsicParams::get(extrinsics); |
| 204 | // Project the target location into pixel coordinates. |
| 205 | const ::aos::vision::Vector<2> projected_point = |
| 206 | Project(template_point, intrinsic_params, extrinsic_params); |
| 207 | const ::aos::vision::Vector<2> residual_point = |
| 208 | target_point - projected_point; |
| 209 | residual[0] = residual_point.x(); |
| 210 | residual[1] = residual_point.y(); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 211 | return true; |
| 212 | }; |
| 213 | problem.AddResidualBlock( |
| 214 | new NumericDiffCostFunction<decltype(ftor), CENTRAL, 2, |
| 215 | IntrinsicParams::kNumParams, |
| 216 | ExtrinsicParams::kNumParams>( |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 217 | new decltype(ftor)(::std::move(ftor))), |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 218 | NULL, &intrinsics[0], extrinsics); |
| 219 | } |
| 220 | |
Austin Schuh | 6cac52c | 2019-03-08 20:03:33 -0800 | [diff] [blame] | 221 | // Now, compare the estimated location of the target that we just solved |
| 222 | // for with the extrinsic params above with the known location of the |
| 223 | // target. |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 224 | auto ftor = [&info, i](const double *const extrinsics, |
| 225 | const double *const geometry, double *residual) { |
Austin Schuh | 6cac52c | 2019-03-08 20:03:33 -0800 | [diff] [blame] | 226 | const ::std::array<double, 3> err = |
| 227 | GetError(info, extrinsics, geometry, i); |
| 228 | // We care a lot more about geometry than pixels. Especially since |
| 229 | // pixels are small and meters are big, so there's a small penalty to |
| 230 | // being off by meters. |
| 231 | residual[0] = err[0] * 1259.0; |
| 232 | residual[1] = err[1] * 1259.0; |
| 233 | residual[2] = err[2] * 1259.0; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 234 | return true; |
| 235 | }; |
| 236 | |
| 237 | problem.AddResidualBlock( |
| 238 | new NumericDiffCostFunction<decltype(ftor), CENTRAL, 3, |
| 239 | ExtrinsicParams::kNumParams, |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 240 | CameraGeometry::kNumParams>( |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 241 | new decltype(ftor)(::std::move(ftor))), |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 242 | NULL, extrinsics, &geometry[0]); |
| 243 | } |
| 244 | } |
| 245 | // TODO: Debug solver convergence? |
| 246 | Solve(options, &problem, &summary); |
| 247 | Solve(options, &problem, &summary); |
| 248 | Solve(options, &problem, &summary); |
| 249 | |
| 250 | { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 251 | ::std::cout << summary.BriefReport() << ::std::endl; |
Austin Schuh | cacc692 | 2019-03-06 20:44:30 -0800 | [diff] [blame] | 252 | IntrinsicParams intrinsics_ = IntrinsicParams::get(&intrinsics[0]); |
| 253 | CameraGeometry geometry_ = CameraGeometry::get(&geometry[0]); |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 254 | ::std::cout << "rup = " << intrinsics_.mount_angle * 180 / M_PI << ";" |
| 255 | << ::std::endl; |
| 256 | ::std::cout << "fl = " << intrinsics_.focal_length << ";" << ::std::endl; |
| 257 | ::std::cout << "error = " << summary.final_cost << ";" << ::std::endl; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 258 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 259 | ::std::cout << "camera_angle = " << geometry_.heading * 180 / M_PI |
| 260 | << ::std::endl; |
| 261 | ::std::cout << "camera_x = " << geometry_.location[0] << ::std::endl; |
| 262 | ::std::cout << "camera_y = " << geometry_.location[1] << ::std::endl; |
| 263 | ::std::cout << "camera_z = " << geometry_.location[2] << ::std::endl; |
| 264 | ::std::cout << "camera_barrel = " << intrinsics_.barrel_mount * 180.0 / M_PI |
| 265 | << ::std::endl; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 266 | |
Austin Schuh | cacc692 | 2019-03-06 20:44:30 -0800 | [diff] [blame] | 267 | for (const Sample &sample : all_extrinsics) { |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 268 | const int i = sample.i; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 269 | double *data = sample.extrinsics.get(); |
| 270 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 271 | const ExtrinsicParams extrinsic_params = ExtrinsicParams::get(data); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 272 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 273 | const ::std::array<double, 3> error = |
| 274 | GetError(info, data, &geometry[0], i); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 275 | |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 276 | ::std::cout << i << ", "; |
| 277 | ::std::cout << extrinsic_params.z << "m, "; |
| 278 | ::std::cout << extrinsic_params.y << "m, "; |
| 279 | ::std::cout << extrinsic_params.r1 * 180 / M_PI << ", "; |
| 280 | ::std::cout << extrinsic_params.r2 * 180 / M_PI << ", "; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 281 | // TODO: Methodology problem: This should really have a separate solve for |
| 282 | // extrinsics... |
Austin Schuh | 6cac52c | 2019-03-08 20:03:33 -0800 | [diff] [blame] | 283 | ::std::cout << error[0] << "m, "; |
| 284 | ::std::cout << error[1] << "m, "; |
| 285 | ::std::cout << error[2] << "m" << ::std::endl; |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 286 | } |
| 287 | } |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 288 | |
| 289 | CameraCalibration results; |
| 290 | results.dataset = info; |
| 291 | results.intrinsics = IntrinsicParams::get(&intrinsics[0]); |
| 292 | results.geometry = CameraGeometry::get(&geometry[0]); |
Austin Schuh | d6cc1e9 | 2019-03-08 21:01:51 -0800 | [diff] [blame] | 293 | DumpCameraConstants(FLAGS_constants.c_str(), info.camera_id, results); |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 296 | } // namespace vision |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 297 | } // namespace y2019 |
Parker Schuh | 9e1d169 | 2019-02-24 14:34:04 -0800 | [diff] [blame] | 298 | |
| 299 | int main(int argc, char **argv) { y2019::vision::main(argc, argv); } |