35 #include <opencv2/imgproc/imgproc.hpp> 36 #include <opencv2/calib3d/calib3d.hpp> 44 void RandomColor(int32_t seed,
double& r,
double& g,
double& b)
48 r =
static_cast<double>(std::rand()) / RAND_MAX;
49 g =
static_cast<double>(std::rand()) / RAND_MAX;
50 b =
static_cast<double>(std::rand()) / RAND_MAX;
61 float max4 = (max - min) / 4.0;
64 if (value == HUGE_VAL)
72 else if (value < max4)
74 unsigned char c1 = 144;
78 b = c1 + (
unsigned char) ((255 - c1) * value / max4);
80 else if (value < 2 * max4)
83 g = (
unsigned char) (255 * (value - max4) / max4);
86 else if (value < 3 * max4)
88 r = (
unsigned char) (255 * (value - 2 * max4) / max4);
95 g = (
unsigned char) (255 - 255 * (value - 3 * max4) / max4);
107 const std::string& title,
108 const cv::Mat& image1,
109 const cv::Mat& image2,
110 const cv::Mat& transform)
112 if (image1.rows == image2.rows && image1.cols == image2.cols)
114 cv::Mat image2_warped;
119 cv::Size(image2.cols, image2.rows));
121 cv::Mat sub = image1 - image2_warped;
129 const cv::Mat image1,
130 const cv::Mat image2,
131 const cv::Mat points1,
132 const cv::Mat points2,
133 const cv::Scalar& color,
134 bool draw_image_borders)
136 cv::Size size(image1.cols + image2.cols, std::max(image1.rows, image2.rows));
137 image_out.create(size, CV_MAKETYPE(image1.depth(), 3));
138 image_out.setTo(cv::Vec3b(0, 0, 0));
139 cv::Mat draw_image1 = image_out(cv::Rect(0, 0, image1.cols, image1.rows));
140 cv::Mat draw_image2 = image_out(cv::Rect(image1.cols, 0, image2.cols, image2.rows));
142 if (image1.type() == CV_8U)
144 cvtColor(image1, draw_image1, CV_GRAY2BGR);
148 image1.copyTo(draw_image1);
151 if (image2.type() == CV_8U)
153 cvtColor(image2, draw_image2, CV_GRAY2BGR);
157 image2.copyTo(draw_image2);
160 if (draw_image_borders)
162 cv::rectangle(draw_image1,
164 cv::Point(image1.cols, image1.rows),
168 cv::rectangle(draw_image2,
170 cv::Point(image2.cols, image2.rows),
175 cv::RNG rng = cv::theRNG();
176 bool rand_color = color == cv::Scalar::all(-1);
178 for (
int i = 0; i < points1.rows; i++)
180 cv::Scalar match_color = rand_color ? cv::Scalar(rng(256), rng(256), rng(256)) : color;
182 cvRound(points1.at<cv::Vec2f>(0, i)[0] * 16.0),
183 cvRound(points1.at<cv::Vec2f>(0, i)[1] * 16.0));
185 cvRound(points2.at<cv::Vec2f>(0, i)[0] * 16.0),
186 cvRound(points2.at<cv::Vec2f>(0, i)[1] * 16.0));
187 cv::Point2f dcenter2(
188 std::min(center2.x + draw_image1.cols * 16.0, (image_out.cols - 1) * 16.0),
190 circle(draw_image1, center1, 48, match_color, 1, CV_AA, 4);
191 circle(draw_image2, center2, 48, match_color, 1, CV_AA, 4);
192 line(image_out, center1, dcenter2, match_color, 1, CV_AA, 4);
197 const std::string& title,
198 const cv::Mat image1,
199 const cv::Mat image2,
200 const cv::Mat points1,
201 const cv::Mat points2,
202 const cv::Scalar& color,
203 bool draw_image_borders)
218 const std::string& title,
220 const cv::Mat points1,
221 const cv::Mat points2,
222 const cv::Scalar& color1,
223 const cv::Scalar& color2,
224 bool draw_image_borders)
227 if (image.type() == CV_8U)
229 cvtColor(image, draw_image, CV_GRAY2BGR);
233 draw_image = image.clone();
236 for (
int i = 0; i < points1.rows; i++)
239 cvRound(points1.at<cv::Vec2f>(0, i)[0] * 16.0),
240 cvRound(points1.at<cv::Vec2f>(0, i)[1] * 16.0));
241 cv::Point2f center2(cvRound(
242 points2.at<cv::Vec2f>(0, i)[0] * 16.0),
243 cvRound(points2.at<cv::Vec2f>(0, i)[1] * 16.0));
244 circle(draw_image, center1, 48, color1, 1, CV_AA, 4);
245 line(draw_image, center1, center2, color2, 1, CV_AA, 4);
void JetColorMap(unsigned char &r, unsigned char &g, unsigned char &b, float value, float min, float max)
Map a scalar value to a color gradient.
void DrawMatches(cv::Mat &image_out, const cv::Mat image1, const cv::Mat image2, const cv::Mat points1, const cv::Mat points2, const cv::Scalar &color=cv::Scalar::all(-1), bool draw_image_borders=false)
void ShowScaled(const std::string &name, const cv::Mat &mat, const cv::Mat &mask=cv::Mat(), double a=-1.0, double b=0.0)
void RandomColor(int32_t seed, double &r, double &g, double &b)
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
void DrawOverlap(const std::string &title, const cv::Mat &image1, const cv::Mat &image2, const cv::Mat &transform)