Milind Upadhyay | e321586 | 2022-03-24 19:59:19 -0700 | [diff] [blame] | 1 | #include <algorithm> |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 2 | #include <map> |
| 3 | #include <opencv2/calib3d.hpp> |
| 4 | #include <opencv2/features2d.hpp> |
| 5 | #include <opencv2/highgui/highgui.hpp> |
| 6 | #include <opencv2/imgproc.hpp> |
| 7 | #include <random> |
| 8 | |
Milind Upadhyay | 1a293ea | 2022-03-27 17:41:24 -0700 | [diff] [blame] | 9 | #include "absl/strings/str_format.h" |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 10 | #include "aos/events/shm_event_loop.h" |
| 11 | #include "aos/init.h" |
| 12 | #include "aos/time/time.h" |
Jim Ostrowski | 977850f | 2022-01-22 21:04:22 -0800 | [diff] [blame] | 13 | #include "frc971/vision/vision_generated.h" |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 14 | #include "y2022/vision/blob_detector.h" |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 15 | #include "y2022/vision/calibration_data.h" |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 16 | #include "y2022/vision/target_estimate_generated.h" |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 17 | #include "y2022/vision/target_estimator.h" |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 18 | |
| 19 | DEFINE_string(capture, "", |
| 20 | "If set, capture a single image and save it to this filename."); |
| 21 | DEFINE_string(channel, "/camera", "Channel name for the image."); |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 22 | DEFINE_string(config, "aos_config.json", "Path to the config file to use."); |
Jim Ostrowski | 5caf81c | 2022-01-30 21:02:19 -0800 | [diff] [blame] | 23 | DEFINE_string(png_dir, "", "Path to a set of images to display."); |
Milind Upadhyay | 1a293ea | 2022-03-27 17:41:24 -0700 | [diff] [blame] | 24 | DEFINE_string(png_pattern, "*", R"(Pattern to match pngs using '*'/'?'.)"); |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 25 | DEFINE_string(calibration_node, "", |
| 26 | "If reading locally, use the calibration for this node"); |
| 27 | DEFINE_int32( |
| 28 | calibration_team_number, 971, |
| 29 | "If reading locally, use the calibration for a node with this team number"); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 30 | DEFINE_uint64(skip, 0, |
| 31 | "Number of images to skip if doing local reading (png_dir set)."); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 32 | DEFINE_bool(show_features, true, "Show the blobs."); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 33 | DEFINE_bool(display_estimation, false, |
| 34 | "If true, display the target estimation graphically"); |
Milind Upadhyay | e321586 | 2022-03-24 19:59:19 -0700 | [diff] [blame] | 35 | DEFINE_bool(sort_by_time, true, "If true, sort the images by time"); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 36 | |
| 37 | namespace y2022 { |
| 38 | namespace vision { |
| 39 | namespace { |
| 40 | |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 41 | using namespace frc971::vision; |
| 42 | |
| 43 | std::map<int64_t, BlobDetector::BlobResult> target_est_map; |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 44 | aos::Fetcher<frc971::vision::CameraImage> image_fetcher; |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 45 | aos::Fetcher<y2022::vision::TargetEstimate> target_estimate_fetcher; |
| 46 | |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 47 | std::vector<cv::Point> FbsToCvPoints( |
| 48 | const flatbuffers::Vector<const Point *> &points_fbs) { |
| 49 | std::vector<cv::Point> points; |
| 50 | for (const Point *point : points_fbs) { |
| 51 | points.emplace_back(point->x(), point->y()); |
| 52 | } |
| 53 | return points; |
| 54 | } |
| 55 | |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 56 | std::vector<std::vector<cv::Point>> FbsToCvBlobs( |
James Kuszmaul | d230d7a | 2022-03-06 15:00:43 -0800 | [diff] [blame] | 57 | const flatbuffers::Vector<flatbuffers::Offset<Blob>> *blobs_fbs) { |
| 58 | if (blobs_fbs == nullptr) { |
| 59 | return {}; |
| 60 | } |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 61 | std::vector<std::vector<cv::Point>> blobs; |
James Kuszmaul | d230d7a | 2022-03-06 15:00:43 -0800 | [diff] [blame] | 62 | for (const auto blob : *blobs_fbs) { |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 63 | blobs.emplace_back(FbsToCvPoints(*blob->points())); |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 64 | } |
| 65 | return blobs; |
| 66 | } |
| 67 | |
| 68 | std::vector<BlobDetector::BlobStats> FbsToBlobStats( |
| 69 | const flatbuffers::Vector<flatbuffers::Offset<BlobStatsFbs>> |
| 70 | &blob_stats_fbs) { |
| 71 | std::vector<BlobDetector::BlobStats> blob_stats; |
| 72 | for (const auto stats_fbs : blob_stats_fbs) { |
| 73 | cv::Point centroid{stats_fbs->centroid()->x(), stats_fbs->centroid()->y()}; |
Milind Upadhyay | 8f38ad8 | 2022-03-03 10:06:18 -0800 | [diff] [blame] | 74 | cv::Size size{stats_fbs->size()->width(), stats_fbs->size()->height()}; |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 75 | blob_stats.emplace_back(BlobDetector::BlobStats{ |
Milind Upadhyay | 8f38ad8 | 2022-03-03 10:06:18 -0800 | [diff] [blame] | 76 | centroid, size, stats_fbs->aspect_ratio(), stats_fbs->area(), |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 77 | static_cast<size_t>(stats_fbs->num_points())}); |
| 78 | } |
| 79 | return blob_stats; |
| 80 | } |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 81 | |
| 82 | bool DisplayLoop() { |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 83 | int64_t target_timestamp = 0; |
| 84 | if (target_estimate_fetcher.Fetch()) { |
| 85 | const TargetEstimate *target_est = target_estimate_fetcher.get(); |
| 86 | CHECK(target_est != nullptr) |
| 87 | << "Got null when trying to fetch target estimate"; |
| 88 | |
| 89 | target_timestamp = target_est->image_monotonic_timestamp_ns(); |
| 90 | if (target_est->blob_result()->filtered_blobs()->size() > 0) { |
| 91 | VLOG(2) << "Got blobs for timestamp " << target_est << "\n"; |
| 92 | } |
| 93 | // Store the TargetEstimate data so we can match timestamp with image |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 94 | target_est_map[target_timestamp] = BlobDetector::BlobResult{ |
| 95 | cv::Mat(), |
James Kuszmaul | d230d7a | 2022-03-06 15:00:43 -0800 | [diff] [blame] | 96 | FbsToCvBlobs(target_est->blob_result()->filtered_blobs()), |
| 97 | FbsToCvBlobs(target_est->blob_result()->unfiltered_blobs()), |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 98 | FbsToBlobStats(*target_est->blob_result()->blob_stats()), |
Milind Upadhyay | 8f38ad8 | 2022-03-03 10:06:18 -0800 | [diff] [blame] | 99 | FbsToBlobStats(*target_est->blob_result()->filtered_stats()), |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 100 | cv::Point{target_est->blob_result()->centroid()->x(), |
| 101 | target_est->blob_result()->centroid()->y()}}; |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 102 | // Only keep last 10 matches |
| 103 | while (target_est_map.size() > 10u) { |
| 104 | target_est_map.erase(target_est_map.begin()); |
| 105 | } |
| 106 | } |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 107 | int64_t image_timestamp = 0; |
Jim Ostrowski | 5caf81c | 2022-01-30 21:02:19 -0800 | [diff] [blame] | 108 | if (!image_fetcher.Fetch()) { |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 109 | VLOG(2) << "Couldn't fetch image"; |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 110 | return true; |
| 111 | } |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 112 | const CameraImage *image = image_fetcher.get(); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 113 | CHECK(image != nullptr) << "Couldn't read image"; |
| 114 | image_timestamp = image->monotonic_timestamp_ns(); |
| 115 | VLOG(2) << "Got image at timestamp: " << image_timestamp; |
| 116 | |
| 117 | // Create color image: |
| 118 | cv::Mat image_color_mat(cv::Size(image->cols(), image->rows()), CV_8UC2, |
| 119 | (void *)image->data()->data()); |
Milind Upadhyay | ec41e13 | 2022-02-05 17:14:05 -0800 | [diff] [blame] | 120 | cv::Mat bgr_image(cv::Size(image->cols(), image->rows()), CV_8UC3); |
Milind Upadhyay | 4052294 | 2022-02-19 15:30:31 -0800 | [diff] [blame] | 121 | cv::cvtColor(image_color_mat, bgr_image, cv::COLOR_YUV2BGR_YUYV); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 122 | |
| 123 | if (!FLAGS_capture.empty()) { |
Milind Upadhyay | ec41e13 | 2022-02-05 17:14:05 -0800 | [diff] [blame] | 124 | cv::imwrite(FLAGS_capture, bgr_image); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 125 | return false; |
| 126 | } |
| 127 | |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 128 | auto target_est_it = target_est_map.find(image_timestamp); |
| 129 | if (target_est_it != target_est_map.end()) { |
| 130 | LOG(INFO) << image->monotonic_timestamp_ns() << ": # unfiltered blobs: " |
| 131 | << target_est_it->second.unfiltered_blobs.size() |
| 132 | << "; # filtered blobs: " |
| 133 | << target_est_it->second.filtered_blobs.size(); |
Henry Speiser | e45e7a2 | 2022-02-04 23:17:01 -0800 | [diff] [blame] | 134 | |
Jim Ostrowski | 210765a | 2022-02-27 12:52:14 -0800 | [diff] [blame] | 135 | cv::Mat ret_image = |
| 136 | cv::Mat::zeros(cv::Size(image->cols(), image->rows()), CV_8UC3); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 137 | BlobDetector::DrawBlobs(target_est_it->second, ret_image); |
Jim Ostrowski | 46a7838 | 2022-02-06 14:05:58 -0800 | [diff] [blame] | 138 | cv::imshow("blobs", ret_image); |
| 139 | } |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 140 | |
Milind Upadhyay | ec41e13 | 2022-02-05 17:14:05 -0800 | [diff] [blame] | 141 | cv::imshow("image", bgr_image); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 142 | |
| 143 | int keystroke = cv::waitKey(1); |
| 144 | if ((keystroke & 0xFF) == static_cast<int>('c')) { |
| 145 | // Convert again, to get clean image |
Milind Upadhyay | ec41e13 | 2022-02-05 17:14:05 -0800 | [diff] [blame] | 146 | cv::cvtColor(image_color_mat, bgr_image, cv::COLOR_YUV2BGR_YUYV); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 147 | std::stringstream name; |
| 148 | name << "capture-" << aos::realtime_clock::now() << ".png"; |
Milind Upadhyay | ec41e13 | 2022-02-05 17:14:05 -0800 | [diff] [blame] | 149 | cv::imwrite(name.str(), bgr_image); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 150 | LOG(INFO) << "Saved image file: " << name.str(); |
| 151 | } else if ((keystroke & 0xFF) == static_cast<int>('q')) { |
| 152 | return false; |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | void ViewerMain() { |
| 158 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 159 | aos::configuration::ReadConfig(FLAGS_config); |
| 160 | |
| 161 | aos::ShmEventLoop event_loop(&config.message()); |
| 162 | |
| 163 | image_fetcher = |
| 164 | event_loop.MakeFetcher<frc971::vision::CameraImage>(FLAGS_channel); |
| 165 | |
Jim Ostrowski | 46a7838 | 2022-02-06 14:05:58 -0800 | [diff] [blame] | 166 | target_estimate_fetcher = |
| 167 | event_loop.MakeFetcher<y2022::vision::TargetEstimate>(FLAGS_channel); |
| 168 | |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 169 | // Run the display loop |
| 170 | event_loop.AddPhasedLoop( |
| 171 | [&event_loop](int) { |
| 172 | if (!DisplayLoop()) { |
| 173 | LOG(INFO) << "Calling event_loop Exit"; |
| 174 | event_loop.Exit(); |
| 175 | }; |
| 176 | }, |
| 177 | ::std::chrono::milliseconds(100)); |
| 178 | |
| 179 | event_loop.Run(); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 180 | } |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 181 | |
Milind Upadhyay | e321586 | 2022-03-24 19:59:19 -0700 | [diff] [blame] | 182 | size_t FindImageTimestamp(std::string_view filename) { |
| 183 | // Find the first number in the string |
| 184 | const auto timestamp_start = std::find_if( |
| 185 | filename.begin(), filename.end(), [](char c) { return std::isdigit(c); }); |
| 186 | CHECK_NE(timestamp_start, filename.end()) |
| 187 | << "Expected a number in image filename, got " << filename; |
| 188 | const auto timestamp_end = |
| 189 | std::find_if_not(timestamp_start + 1, filename.end(), |
| 190 | [](char c) { return std::isdigit(c); }); |
| 191 | |
| 192 | return static_cast<size_t>( |
| 193 | std::atoi(filename |
| 194 | .substr(timestamp_start - filename.begin(), |
| 195 | timestamp_end - timestamp_start) |
| 196 | .data())); |
| 197 | } |
| 198 | |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 199 | void ViewerLocal() { |
| 200 | std::vector<cv::String> file_list; |
Milind Upadhyay | 1a293ea | 2022-03-27 17:41:24 -0700 | [diff] [blame] | 201 | cv::glob(absl::StrFormat("%s/%s.png", FLAGS_png_dir, FLAGS_png_pattern), |
| 202 | file_list, false); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 203 | |
Milind Upadhyay | e321586 | 2022-03-24 19:59:19 -0700 | [diff] [blame] | 204 | // Sort the images by timestamp |
| 205 | if (FLAGS_sort_by_time) { |
| 206 | std::sort(file_list.begin(), file_list.end(), |
| 207 | [](std::string_view filename_1, std::string_view filename_2) { |
| 208 | return (FindImageTimestamp(filename_1) < |
| 209 | FindImageTimestamp(filename_2)); |
| 210 | }); |
| 211 | } |
| 212 | |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 213 | const aos::FlatbufferSpan<calibration::CalibrationData> calibration_data( |
| 214 | CalibrationData()); |
| 215 | |
| 216 | const calibration::CameraCalibration *calibration = nullptr; |
| 217 | for (const calibration::CameraCalibration *candidate : |
| 218 | *calibration_data.message().camera_calibrations()) { |
| 219 | if ((candidate->node_name()->string_view() == FLAGS_calibration_node) && |
| 220 | (candidate->team_number() == FLAGS_calibration_team_number)) { |
| 221 | calibration = candidate; |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | CHECK(calibration) << "No calibration data found for node \"" |
| 227 | << FLAGS_calibration_node << "\" with team number " |
| 228 | << FLAGS_calibration_team_number; |
| 229 | |
Milind Upadhyay | 3c1a5c0 | 2022-03-27 16:27:19 -0700 | [diff] [blame] | 230 | const auto intrinsics_float = cv::Mat( |
| 231 | 3, 3, CV_32F, |
| 232 | const_cast<void *>( |
| 233 | static_cast<const void *>(calibration->intrinsics()->data()))); |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 234 | cv::Mat intrinsics; |
| 235 | intrinsics_float.convertTo(intrinsics, CV_64F); |
| 236 | |
Milind Upadhyay | a4cce2f | 2022-03-13 21:50:13 -0700 | [diff] [blame] | 237 | const frc971::vision::calibration::TransformationMatrix *transform = |
| 238 | calibration->has_turret_extrinsics() ? calibration->turret_extrinsics() |
| 239 | : calibration->fixed_extrinsics(); |
| 240 | |
| 241 | const auto extrinsics_float = cv::Mat( |
| 242 | 4, 4, CV_32F, |
| 243 | const_cast<void *>(static_cast<const void *>(transform->data()->data()))); |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 244 | cv::Mat extrinsics; |
| 245 | extrinsics_float.convertTo(extrinsics, CV_64F); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 246 | |
Milind Upadhyay | 3c1a5c0 | 2022-03-27 16:27:19 -0700 | [diff] [blame] | 247 | const auto dist_coeffs_float = cv::Mat( |
| 248 | 5, 1, CV_32F, |
| 249 | const_cast<void *>( |
| 250 | static_cast<const void *>(calibration->dist_coeffs()->data()))); |
| 251 | cv::Mat dist_coeffs; |
| 252 | dist_coeffs_float.convertTo(dist_coeffs, CV_64F); |
| 253 | |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 254 | TargetEstimator estimator(intrinsics, extrinsics); |
| 255 | |
Milind Upadhyay | ae99872 | 2022-03-13 12:45:55 -0700 | [diff] [blame] | 256 | for (auto it = file_list.begin() + FLAGS_skip; it < file_list.end(); it++) { |
Milind Upadhyay | 07f6f9e | 2022-03-18 18:40:34 -0700 | [diff] [blame] | 257 | LOG(INFO) << "Reading file " << (it - file_list.begin()) << ": " << *it; |
Milind Upadhyay | 3c1a5c0 | 2022-03-27 16:27:19 -0700 | [diff] [blame] | 258 | cv::Mat image_mat_distorted = cv::imread(it->c_str()); |
| 259 | cv::Mat image_mat; |
| 260 | cv::undistort(image_mat_distorted, image_mat, intrinsics, dist_coeffs); |
| 261 | |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 262 | BlobDetector::BlobResult blob_result; |
| 263 | blob_result.binarized_image = |
| 264 | cv::Mat::zeros(cv::Size(image_mat.cols, image_mat.rows), CV_8UC1); |
| 265 | BlobDetector::ExtractBlobs(image_mat, &blob_result); |
| 266 | |
| 267 | cv::Mat ret_image = |
| 268 | cv::Mat::zeros(cv::Size(image_mat.cols, image_mat.rows), CV_8UC3); |
| 269 | BlobDetector::DrawBlobs(blob_result, ret_image); |
| 270 | |
| 271 | LOG(INFO) << ": # blobs: " << blob_result.filtered_blobs.size() |
| 272 | << " (# removed: " |
| 273 | << blob_result.unfiltered_blobs.size() - |
| 274 | blob_result.filtered_blobs.size() |
| 275 | << ")"; |
| 276 | |
Milind Upadhyay | e500310 | 2022-04-02 22:16:39 -0700 | [diff] [blame^] | 277 | estimator.Solve(blob_result.filtered_stats, |
| 278 | FLAGS_display_estimation ? std::make_optional(ret_image) |
| 279 | : std::nullopt); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 280 | if (blob_result.filtered_blobs.size() > 0) { |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 281 | estimator.DrawEstimate(ret_image); |
Austin Schuh | a685b5d | 2022-04-02 14:53:54 -0700 | [diff] [blame] | 282 | LOG(INFO) << "Read file " << (it - file_list.begin()) << ": " << *it; |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | cv::imshow("image", image_mat); |
| 286 | cv::imshow("mask", blob_result.binarized_image); |
| 287 | cv::imshow("blobs", ret_image); |
| 288 | |
Milind Upadhyay | e321586 | 2022-03-24 19:59:19 -0700 | [diff] [blame] | 289 | constexpr size_t kWaitKeyDelay = 0; // ms |
| 290 | int keystroke = cv::waitKey(kWaitKeyDelay) & 0xFF; |
| 291 | // Ignore alt key |
| 292 | while (keystroke == 233) { |
| 293 | keystroke = cv::waitKey(kWaitKeyDelay); |
| 294 | } |
| 295 | if (keystroke == static_cast<int>('q')) { |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | } |
| 299 | } |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 300 | } // namespace |
| 301 | } // namespace vision |
| 302 | } // namespace y2022 |
| 303 | |
| 304 | // Quick and lightweight viewer for images |
| 305 | int main(int argc, char **argv) { |
| 306 | aos::InitGoogle(&argc, &argv); |
Milind Upadhyay | f61e148 | 2022-02-11 20:42:55 -0800 | [diff] [blame] | 307 | if (FLAGS_png_dir != "") |
| 308 | y2022::vision::ViewerLocal(); |
| 309 | else |
| 310 | y2022::vision::ViewerMain(); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 311 | } |