Berkeley SfM
Functions
bsfm::drawing Namespace Reference

Functions

void AnnotateFeatures (const FeatureList &features, Image &image, unsigned int radius, unsigned int line_thickness)
 
void DrawImageFeatures (const FeatureList &features, const Image &image, const std::string &window_name, unsigned int radius, unsigned int line_thickness)
 
void DrawImageFeatureMatches (const Image &image1, const Image &image2, const FeatureMatchList &feature_matches, const std::string &window_name, unsigned int line_thickness)
 

Function Documentation

void bsfm::drawing::AnnotateFeatures ( const FeatureList features,
Image image,
unsigned int  radius,
unsigned int  line_thickness 
)

Definition at line 49 of file drawing_utils.cpp.

50  {
51  // Create a random number generator for random colors.
52  math::RandomGenerator rng(math::RandomGenerator::Seed());
53 
54  // Get OpenCV mat from the input image.
55  cv::Mat cv_image;
56  image.ToCV(cv_image);
57 
58  for (const auto& feature : features) {
59  cv::Point cv_feature;
60  cv_feature.x = feature.u_;
61  cv_feature.y = feature.v_;
62 
63  const cv::Scalar color(rng.Double(), rng.Double(), rng.Double());
64  cv::circle(cv_image, cv_feature, radius, color, line_thickness);
65  }
66 
67  // Store the OpenCV mat in the image.
68  image.FromCV(cv_image);
69 }
void bsfm::drawing::DrawImageFeatureMatches ( const Image image1,
const Image image2,
const FeatureMatchList feature_matches,
const std::string &  window_name,
unsigned int  line_thickness 
)

Definition at line 88 of file drawing_utils.cpp.

91  {
92  // Create a random number generator for random colors.
93  math::RandomGenerator rng(math::RandomGenerator::Seed());
94 
95  // Get OpenCV mats from the input images.
96  cv::Mat cv_image1, cv_image2;
97  image1.ToCV(cv_image1);
98  image2.ToCV(cv_image2);
99 
100  // Create an OpenCV mat of the two images side by side.
101  cv::Mat combined_image;
102  cv::hconcat(cv_image1, cv_image2, combined_image);
103 
104  // Draw lines between feature locations in the combined image.
105  for (const auto& feature_match : feature_matches) {
106  cv::Point feature1;
107  feature1.x = feature_match.feature1_.u_;
108  feature1.y = feature_match.feature1_.v_;
109 
110  cv::Point feature2;
111  feature2.x = feature_match.feature2_.u_;
112  feature2.y = feature_match.feature2_.v_;
113  feature2 += cv::Point(image2.Width(), 0);
114 
115  // Color channel values between [0, 1).
116  const cv::Scalar color(rng.Double(), rng.Double(), rng.Double());
117  cv::line(combined_image, feature1, feature2, color, line_thickness);
118 
119  // Draw circles around each feature.
120  cv::circle(combined_image, feature1, line_thickness * 3 /*radius*/, color,
121  line_thickness * 2);
122  cv::circle(combined_image, feature2, line_thickness * 3 /*radius*/, color,
123  line_thickness * 2);
124  }
125 
126  // Draw the new image in a named window.
127  cv::namedWindow(window_name.c_str(), CV_WINDOW_AUTOSIZE);
128  cv::imshow(window_name.c_str(), combined_image);
129  cv::waitKey(0);
130 }
void bsfm::drawing::DrawImageFeatures ( const FeatureList features,
const Image image,
const std::string &  window_name,
unsigned int  radius,
unsigned int  line_thickness 
)

Definition at line 71 of file drawing_utils.cpp.

73  {
74  // Annotate features on a copy of the image.
75  Image copy(image);
76  AnnotateFeatures(features, copy, radius, line_thickness);
77 
78  // Convert the copied image to OpenCV format.
79  cv::Mat cv_copy;
80  copy.ToCV(cv_copy);
81 
82  // Draw the copied and annotated image in a named window.
83  cv::namedWindow(window_name.c_str(), CV_WINDOW_AUTOSIZE);
84  cv::imshow(window_name.c_str(), cv_copy);
85  cv::waitKey(0);
86 }
void AnnotateFeatures(const FeatureList &features, Image &image, unsigned int radius, unsigned int line_thickness)