00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <ctime>
00020 #include <string>
00021
00022 #include <osg/PositionAttitudeTransform>
00023 #include <osgGA/TrackballManipulator>
00024 #include <osg/Geode>
00025 #include <osg/ShapeDrawable>
00026 #include <osg/Geometry>
00027 #include <osg/PointSprite>
00028 #include <osg/Point>
00029
00030 #include "uvsim/visualization/PointCloud.h"
00031 #include "uvsim/visualization/SimpleViewer.h"
00032 #include "uvsim/sensing/StereoEngine.h"
00033 #include "uvsim/sensing/Camera.h"
00034 #include "uvsim/navigation/Ins.h"
00035 #include "uvsim/navigation/GeoMag.h"
00036 #include "uvsim/utilities/utilities.h"
00037
00038 using namespace boost::numeric::ublas;
00039 int main (int argc, char const* argv[])
00040 {
00041
00042
00043
00044
00045 uvsim::StereoEngine *stereo = new uvsim::StereoEngine(cvLoadImage("data/01L.jpg"),cvLoadImage("data/01R.jpg"));
00046 cvNamedWindow("leftVideo", CV_WINDOW_AUTOSIZE);
00047 cvNamedWindow("rightVideo", CV_WINDOW_AUTOSIZE);
00048
00049
00050 const static double refreshRate = 0.05;
00051 const static double depthRate = 2.0;
00052 const static int freq = 500;
00053
00054
00055 vector<double> freqCutMb(3), freqCutFb(3), freqCutWb(3);
00056
00057
00058 freqCutMb(0) = 1;
00059 freqCutMb(1) = 1;
00060 freqCutMb(2) = 1;
00061
00062
00063 freqCutFb(0) = 350;
00064 freqCutFb(1) = 350;
00065 freqCutFb(2) = 150;
00066
00067
00068 freqCutWb(0) = 120;
00069 freqCutWb(1) = 120;
00070 freqCutWb(2) = 120;
00071
00072
00073 float dec, dip, ti, gv;
00074
00075
00076 float alt, glat, glon, time;
00077 alt = 184.7;
00078 glat = 40.41194444;
00079 glon = -86.93361111;
00080 time = 2009.7;
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 vector<double> pos(3);
00091
00092 osg::Vec3Array *points = new osg::Vec3Array;
00093 osg::Vec4Array *colors = new osg::Vec4Array;
00094 osg::Vec4 ini(1,1,0,1);
00095 osg::Vec4 fin(0,0,1,1);
00096 uvsim::PointCloud *pointCloud = new uvsim::PointCloud(1,points,colors);
00097 osg::Group *root = new osg::Group;
00098 root->addChild((pointCloud->root).get());
00099
00100
00101 int fps = 20;
00102 osg::Vec3d manipCenter(0,0,0);
00103 double manipDistance = 10;
00104 float frameSize = 1;
00105 double fogStart=0, fogEnd=1000;
00106 uvsim::SimpleViewer simpleViewer(0,fps,root,manipDistance,manipCenter,frameSize,fogStart,fogEnd);
00107 simpleViewer.start();
00108
00109 vector<double> bodyCoord(3), worldCoord(3);
00110
00111 for (int i=0; !simpleViewer.viewer->done(); i++)
00112 {
00113 if ((i % int(freq*depthRate)) == 0)
00114 {
00115
00116
00117
00118 stereo->findDisparity();
00119 stereo->reprojectTo3d();
00120 std::cout<<"Depth Update"<<std::endl;
00121 points->clear();
00122 colors->clear();
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 for ( int y=0; y<stereo->threeD->height; y++)
00139 {
00140 float* ptr = (float*) (stereo->threeD->imageData + y * stereo->threeD->widthStep);
00141 uint8_t* color_ptr = (uint8_t*) (stereo->leftImageR->imageData + y * stereo->leftGreyR->widthStep);
00142
00143 for (int x=0; x<stereo->threeD->width; x++)
00144 {
00145
00146 if ((CV_MAT_ELEM(*stereo->disp, signed short,y,x) != (stereo->BMState->minDisparity - 1) * 16) && (abs(ptr[3*x+2])< 20))
00147 {
00148
00149 bodyCoord(0) = -ptr[stereo->threeD->nChannels*x+2];
00150 bodyCoord(1) = -ptr[stereo->threeD->nChannels*x+0];
00151 bodyCoord(2) = -ptr[stereo->threeD->nChannels*x+1];
00152
00153 std::cout<<"bodyCoord- "<<bodyCoord<<std::endl;
00154 vector<double> quat = zero_vector<double>(4);
00155 quat(0) = 1;
00156 quat(2) = 1;
00157 worldCoord = uvsim::quatRotate(quat,bodyCoord);
00158
00159
00160
00161
00162 points->push_back(osg::Vec3(worldCoord(0), worldCoord(1), worldCoord(2) ));
00163 colors->push_back(osg::Vec4(color_ptr[3*x+0], color_ptr[3*x+1], color_ptr[3*x+2],1));
00164
00165 }
00166
00167
00168 }
00169 }
00170 pointCloud->updateSize();
00171 }
00172
00173 }
00174
00175 simpleViewer.join();
00176 return(0);
00177
00178 }
00179