20 unsigned char color_table[12][3] =
22 { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 },
23 { 255, 255, 0 }, { 255, 0, 255 }, { 0, 255, 255 },
24 { 127, 255, 0 }, { 255, 127, 0 }, { 127, 0, 255 },
25 { 255, 0, 127 }, { 0, 127, 255 }, { 0, 255, 127 }
30 float size,
float orientation, uint8_t
const* color)
32 float const sin_ori = std::sin(orientation);
33 float const cos_ori = std::cos(orientation);
35 float const x0 = (cos_ori * -size - sin_ori * -size);
36 float const y0 = (sin_ori * -size + cos_ori * -size);
37 float const x1 = (cos_ori * +size - sin_ori * -size);
38 float const y1 = (sin_ori * +size + cos_ori * -size);
39 float const x2 = (cos_ori * +size - sin_ori * +size);
40 float const y2 = (sin_ori * +size + cos_ori * +size);
41 float const x3 = (cos_ori * -size - sin_ori * +size);
42 float const y3 = (sin_ori * -size + cos_ori * +size);
45 static_cast<int>(y + y0 + 0.5f),
static_cast<int>(x + x1 + 0.5f),
46 static_cast<int>(y + y1 + 0.5f), color);
48 static_cast<int>(y + y1 + 0.5f),
static_cast<int>(x + x2 + 0.5f),
49 static_cast<int>(y + y2 + 0.5f), color);
51 static_cast<int>(y + y2 + 0.5f),
static_cast<int>(x + x3 + 0.5f),
52 static_cast<int>(y + y3 + 0.5f), color);
54 static_cast<int>(y + y3 + 0.5f),
static_cast<int>(x + x0 + 0.5f),
55 static_cast<int>(y + y0 + 0.5f), color);
67 int const x =
static_cast<int>(keypoint.
x + 0.5);
68 int const y =
static_cast<int>(keypoint.
y + 0.5);
69 int const width = image.
width();
70 int const height = image.
height();
71 int const channels = image.
channels();
73 if (x < 0 || x >= width || y < 0 || y >= height)
76 int required_space = 0;
77 bool draw_orientation =
false;
81 case SMALL_DOT_STATIC:
83 draw_orientation =
false;
85 case SMALL_CIRCLE_STATIC:
87 draw_orientation =
false;
89 case RADIUS_BOX_ORIENTATION:
90 required_space =
static_cast<int>(std::sqrt
92 draw_orientation =
true;
94 case RADIUS_CIRCLE_ORIENTATION:
95 required_space =
static_cast<int>(keypoint.
radius);
96 draw_orientation =
true;
100 if (x < required_space || x >= width - required_space
101 || y < required_space || y >= height - required_space)
103 style = SMALL_DOT_STATIC;
105 draw_orientation =
false;
111 case SMALL_DOT_STATIC:
112 std::copy(color, color + channels, &image.
at(x, y, 0));
114 case SMALL_CIRCLE_STATIC:
117 case RADIUS_BOX_ORIENTATION:
118 draw_box(image, keypoint.
x, keypoint.
y,
121 case RADIUS_CIRCLE_ORIENTATION:
126 if (draw_orientation)
128 float const sin_ori = std::sin(keypoint.
orientation);
129 float const cos_ori = std::cos(keypoint.
orientation);
130 float const x1 = (cos_ori * keypoint.
radius);
131 float const y1 = (sin_ori * keypoint.
radius);
133 static_cast<int>(keypoint.
y + 0.5f),
134 static_cast<int>(keypoint.
x + x1 + 0.5f),
135 static_cast<int>(keypoint.
y + y1 + 0.5f), color);
143 std::vector<Visualizer::Keypoint>
const& matches,
147 if (image->channels() == 3)
150 ret = mve::image::expand_grayscale<unsigned char>(ret);
152 else if (image->channels() == 1)
154 ret = mve::image::expand_grayscale<unsigned char>(image);
157 uint8_t* color = color_table[3];
158 for (std::size_t i = 0; i < matches.size(); ++i)
160 Visualizer::draw_keypoint(*ret, matches[i], style, color);
173 if (image1->channels() != 3 || image2->channels() != 3)
174 throw std::invalid_argument(
"Only 3-channel images allowed");
176 int const img1_width = image1->width();
177 int const img1_height = image1->height();
178 int const img2_width = image2->width();
179 int const img2_height = image2->height();
180 int const out_width = img1_width + img2_width;
181 int const out_height = std::max(img1_height, img2_height);
187 unsigned char* out_ptr = ret->begin();
188 unsigned char const* img1_ptr = image1->begin();
189 unsigned char const* img2_ptr = image2->begin();
190 for (
int y = 0; y < out_height; ++y)
194 std::copy(img1_ptr, img1_ptr + img1_width * 3, out_ptr);
195 img1_ptr += img1_width * 3;
197 out_ptr += img1_width * 3;
200 std::copy(img2_ptr, img2_ptr + img2_width * 3, out_ptr);
201 img2_ptr += img2_width * 3;
203 out_ptr += img2_width * 3;
207 for (std::size_t i = 0; i < matches.size(); ++i)
210 matches[i].p2[0] + img1_width, matches[i].p2[1],
211 color_table[i % 12]);
int64_t height(void) const
Returns the height of the image.
int64_t channels(void) const
Returns the amount of channels in the image.
int64_t width(void) const
Returns the width of the image.
Multi-channel image class of arbitrary but homogenous data type.
std::shared_ptr< Image< T > > Ptr
std::shared_ptr< Image< T > const > ConstPtr
T const & at(int64_t index) const
Linear indexing of image data.
static Ptr create(void)
Smart pointer image constructor.
void draw_line(Image< T > &image, int64_t x1, int64_t y1, int64_t x2, int64_t y2, T const *color)
Draws a line from (x0,y0) to (x1,y1) with given color on the image.
void draw_circle(Image< T > &image, int64_t x, int64_t y, int64_t radius, T const *color)
Draws a circle with midpoint (x,y) and given 'radius' on the image.
@ DESATURATE_AVERAGE
(R + G + B) * 1/3
std::vector< Correspondence2D2D > Correspondences2D2D
#define SFM_NAMESPACE_END
#define SFM_NAMESPACE_BEGIN