00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <frame_common/frame.h>
00041 #include <frame_common/frame_extended.h>
00042
00043 using namespace std;
00044
00045 namespace frame_common {
00046
00047 static void drawSmallKeypoints(const cv::Mat& image, const std::vector<cv::KeyPoint>& keypoints,
00048 cv::Mat& display, cv::Scalar color)
00049 {
00050 int shift_bits = 4;
00051 int multiplier = 1 << shift_bits;
00052 for (std::vector<cv::KeyPoint>::const_iterator i = keypoints.begin(), ie = keypoints.end();
00053 i != ie; ++i) {
00054 cv::Point center(i->pt.x * multiplier, i->pt.y * multiplier);
00055 int radius = 1*multiplier;
00056 cv::circle(display, center, radius, color, 1, CV_AA, shift_bits);
00058 }
00059 }
00060
00061 void drawVOtracks(const cv::Mat &image,
00062 const vector<Frame, Eigen::aligned_allocator<Frame> > &frames,
00063 cv::Mat &display)
00064 {
00065
00066 display = cv::Mat::zeros(image.rows, image.cols, CV_8UC3);
00067 int shift_bits = 4;
00068 int multiplier = 1 << shift_bits;
00069
00070
00071 const Frame &f0 = frames.back();
00072
00073
00074 cv::cvtColor(image, display, CV_GRAY2BGR);
00075 drawSmallKeypoints(image, f0.kpts, display, CV_RGB(255, 0, 0));
00076 drawSmallKeypoints(image, f0.tkpts, display, CV_RGB(0, 255, 0));
00077
00078 return;
00079
00080 if (frames.size() < 2) return;
00081
00082
00083 const vector<int> &ipts = f0.ipts;
00084 map<int,int> pmap;
00085 for (int i=0; i<(int)ipts.size(); i++)
00086 if (ipts[i] >= 0)
00087 pmap.insert(pair<int,int>(ipts[i],i));
00088
00089
00090 for (int fi=0; fi<(int)frames.size(); fi++)
00091 {
00092 int c = ((frames.size()-1-fi)*255*2)/(frames.size()-1);
00093 if (c > 255) c=255;
00094 cv::Scalar color(255,c,0);
00095
00096 const Frame &f1 = frames[fi];
00097 const vector<int> &iipts = f1.ipts;
00098 map<int,int>::iterator it;
00099 for (int i=0; i<(int)iipts.size(); i++)
00100 {
00101 int k1 = iipts[i];
00102 it = pmap.find(k1);
00103 if (it != pmap.end())
00104 {
00105 int k0 = it->second;
00106 const cv::KeyPoint& kpt0 = f0.kpts[k0];
00107 const cv::KeyPoint& kpt1 = f1.kpts[i];
00108 cv::Point center1(kpt0.pt.x * multiplier, kpt0.pt.y * multiplier);
00109 cv::Point center2(kpt1.pt.x * multiplier, kpt1.pt.y * multiplier);
00110 cv::line(display, center1, center2, color, 1, CV_AA, shift_bits);
00111 pmap.erase(it);
00112 }
00113 }
00114 }
00115
00116 }
00117
00118 void drawVOtracks(const cv::Mat &image,
00119 const vector<FrameExtended, Eigen::aligned_allocator<FrameExtended> > &frames,
00120 cv::Mat &display)
00121 {
00122
00123 display = cv::Mat::zeros(image.rows, image.cols, CV_8UC3);
00124 int shift_bits = 4;
00125 int multiplier = 1 << shift_bits;
00126
00127
00128 const Frame &f0 = frames.back();
00129
00130
00131 cv::cvtColor(image, display, CV_GRAY2BGR);
00132 drawSmallKeypoints(image, f0.kpts, display, CV_RGB(255, 0, 0));
00133
00134 if (frames.size() < 2) return;
00135
00136
00137 const vector<int> &ipts = f0.ipts;
00138 map<int,int> pmap;
00139 for (int i=0; i<(int)ipts.size(); i++)
00140 if (ipts[i] >= 0)
00141 pmap.insert(pair<int,int>(ipts[i],i));
00142
00143
00144 for (int fi=0; fi<(int)frames.size(); fi++)
00145 {
00146 int c = ((frames.size()-1-fi)*255*2)/(frames.size()-1);
00147 if (c > 255) c=255;
00148 cv::Scalar color(255,c,0);
00149
00150 const Frame &f1 = frames[fi];
00151 const vector<int> &iipts = f1.ipts;
00152 map<int,int>::iterator it;
00153 for (int i=0; i<(int)iipts.size(); i++)
00154 {
00155 int k1 = iipts[i];
00156 it = pmap.find(k1);
00157 if (it != pmap.end())
00158 {
00159 int k0 = it->second;
00160 const cv::KeyPoint& kpt0 = f0.kpts[k0];
00161 const cv::KeyPoint& kpt1 = f1.kpts[i];
00162 cv::Point center1(kpt0.pt.x * multiplier, kpt0.pt.y * multiplier);
00163 cv::Point center2(kpt1.pt.x * multiplier, kpt1.pt.y * multiplier);
00164 cv::line(display, center1, center2, color, 1, CV_AA, shift_bits);
00165 pmap.erase(it);
00166 }
00167 }
00168 }
00169
00170 }
00171
00172
00173
00174 }