00001
00009 #include "utils.h"
00010 #include "vis.h"
00011 #include "model_estimation.h"
00012 #include <iostream>
00013
00018
00019 double getInPlaneThetaByPhi(const Eigen::Hyperplane<double, 3> & epipolar_plane, double x){
00020 Eigen::Vector4d c = epipolar_plane.coeffs();
00021 Vector3d h = PanoImCoord::fromPixel(Vector2d(x, 0.0)).getHomogenous();
00022 assert(c(3) == 0);
00023 double y = (-c(0)*h(0) - c(2)*h(2)) / c(1);
00024 return PanoImCoord::fromHomogenous(Vector3d(h(0), y, h(2))).getPixel()(1);
00025 }
00026
00027
00028 typedef list<std::pair<std::pair<double, double>, std::pair<double, double> > > LineList;
00029
00030 void tmpname(const Eigen::Hyperplane<double,3>& plane,
00031 double max_len, double x1, double x2, LineList& lines ){
00032 double y1, y2;
00033 y1=getInPlaneThetaByPhi(plane, x1);
00034 y2=getInPlaneThetaByPhi(plane, x2);
00035 double length = std::sqrt(std::pow(x1-x2, 2) + std::pow(y2-y1, 2));
00036 if(length > max_len){
00037 tmpname(plane, max_len, x1, x1+(x2-x1)/2.0, lines);
00038 tmpname(plane, max_len, x1+(x2-x1)/2.0, x2, lines);
00039 } else{
00040 lines.push_back(make_pair(make_pair(x1, y1), make_pair(x2, y2)));
00041 }
00042 }
00043
00044
00045
00046 void tmpname(const Eigen::Hyperplane<double,3>& plane,
00047 double max_len, double x1, double x2, bool left_side, LineList& lines ){
00048 double y1, y2;
00049 y1=getInPlaneThetaByPhi(plane, x1);
00050 y2=getInPlaneThetaByPhi(plane, x2);
00051 double length = std::sqrt(std::pow(x1-x2, 2) + std::pow(y2-y1, 2));
00052 if(length > max_len){
00053 if(left_side){
00054 tmpname(plane, max_len, x1+(x2-x1)/2.0, x2, left_side, lines);
00055 } else{
00056 tmpname(plane, max_len, x1, x1+(x2-x1)/2.0, left_side, lines);
00057 }
00058 } else{
00059 lines.push_back(make_pair(make_pair(x1, y1), make_pair(x2, y2)));
00060 }
00061 }
00062
00063 void drawLineSegments(LineList& lines, cv::Mat& image){
00064 LineList::const_iterator it;
00065 it=lines.begin();
00066 while(it != lines.end()){
00067 cv::Point2d pt1 = cv::Point2d(it->first.first, it->first.second);
00068 cv::Point2d pt2 = cv::Point2d(it->second.first, it->second.second);
00069 cv::line(image, pt1, pt2, CV_RGB(255,0,0), 1, 4);
00070 ++it;
00071 }
00072 }
00073
00074 void drawPixelsOnPlaneThroughProjCentre(Eigen::Hyperplane<double,3> plane, double step,
00075 cv::Mat & image){
00076 double a,b;
00077 a=0;
00078 b=PanoramaParams::width - 1;
00079 LineList lines;
00080 tmpname(plane, step, a, b, lines);
00081 drawLineSegments(lines, image);
00082 }
00083
00084 void drawPixelsOnPlaneThroughProjCentre(Eigen::Hyperplane<double,3> plane, double step,
00085 const Vector2d& ic, cv::Mat & image){
00086 double a,b;
00087 a=0;
00088 b=PanoramaParams::width - 1;
00089 LineList lines;
00090 tmpname(plane, step, a, ic(0), true, lines);
00091 tmpname(plane, step, ic(0), b, false, lines);
00092 drawLineSegments(lines, image);
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 void drawRaySegment(const Vector3d& line, const Vector3d& point_hom, cv::Mat& img){
00123 Eigen::Hyperplane<double,3> plane=Eigen::Hyperplane<double,3>(line, 0);
00124 Vector2d point_pixel = PanoImCoord::fromHomogenous(point_hom).getPixel();
00125 Vector2d pt_on_plane_pixel = PanoImCoord::fromHomogenous(
00126 closestPointOnEpipolarPlane(line, point_hom)).getPixel();
00127 cv::Point2d pt1 = cv::Point2d(point_pixel(0), point_pixel(1));
00128 cv::Point2d pt2 = cv::Point2d(pt_on_plane_pixel(0), pt_on_plane_pixel(1));
00129 cv::line(img, pt1, pt2, CV_RGB(255,0,255), 1, 4);
00130 drawPixelsOnPlaneThroughProjCentre(
00131 plane, (double)PanoramaParams::width / 100.0, pt_on_plane_pixel, img);
00132 }
00133
00134
00135 void drawRaysOnEpipolarPlane(
00136 const Matrix3d & E,
00137 const ImageMatchVec & matches,
00138 cv::Mat & img1,
00139 cv::Mat & img2){
00140 Eigen::Hyperplane<double,3> plane;
00141 for(ImageMatchVec::const_iterator it=matches.begin(); it!=matches.end(); it++){
00142 Vector3d c2_line = E * it->first;
00143 plane=Eigen::Hyperplane<double,3>(c2_line, 0);
00144 drawRaySegment(c2_line, it->second, img2);
00145
00146 Vector3d c1_line = (it->second).transpose() * E;
00147 plane=Eigen::Hyperplane<double,3>(c1_line, 0);
00148 drawRaySegment(c1_line, it->first, img1);
00149 }
00150 Points3dSTL im1points;
00151 list<double> elevations;
00152 double deg_in_rad=((M_PI / 2.0) / 90.0);
00153 elevations.push_back(0);
00154 elevations.push_back(40*deg_in_rad);
00155 elevations.push_back(-40*deg_in_rad);
00156 elevations.push_back(80*deg_in_rad);
00157 elevations.push_back(-80*deg_in_rad);
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 }
00170
00171 void drawKeypoints(const vector<cv::KeyPoint> & keypoints, cv::Mat & image){
00172 for(unsigned int i = 0; i< keypoints.size(); i++){
00173 float x = keypoints[i].pt.x;
00174 float y = keypoints[i].pt.y;
00175 cv::circle(image,cv::Point(x,y),3,cv::Scalar(255,255,255),3);
00176 }
00177 }
00178
00179 void drawKeypoints(const ImageCoordinateVec & keypoints, cv::Mat & image){
00180 for(unsigned int i = 0; i< keypoints.size(); i++){
00181 Vector2d c = keypoints[i].getPixel();
00182 cv::circle(image,cv::Point(c(0), c(1)),3,cv::Scalar(255,255,255),3);
00183 }
00184 }
00185
00186
00187