34 #include <Base/Image/ImageIO.hh>
35 #include <Image/Camera.hh>
36 #include <Image/PlanarRectification.hh>
37 #include <Image/CylindricalRectification.hh>
38 #include <Image/SphericalRectification.hh>
39 #include <Image/RectificationBase.hh>
40 #include <Utils/Param.hh>
41 #include <Utils/ThreeDOut.hh>
42 #include <Base/Image/ImageConvert.hh>
48 #define OutStorageType unsigned char
51 int main(
int argc,
char* argv[])
55 "Write out VRML with rectified geometry?",
60 "Do not use texture but colored vertices instead?",
63 bool* help = params.
AddParamBool(
"help",
"",
false,
'h');
65 enum {cylindrical = 0, spherical, planar};
67 vector<string> rectificationTypes;
68 rectificationTypes.push_back(
"cylindrical");
69 rectificationTypes.push_back(
"spherical");
70 rectificationTypes.push_back(
"planar");
73 "Specifies type of rectification to perform:"
74 " [cylindrical], spherical, planar",
78 vector<string> interpolationType;
79 interpolationType.push_back(
"Trilinear");
80 interpolationType.push_back(
"Bilinear");
83 "Specifies type interpolation to use:"
84 " [Trilinear], Bilinear",
89 "Scales the resolution of rectified images",
94 "Turn off usage of lookup tables",
true);
96 string* rectSetupName =
97 params.
AddParamString(
"rectSetup",
"File that contains or shall contain the"
98 " rectification setup",
"", 0, -1);
102 if(argc<3 || *help) {
103 cout<<
"Determines rectification and stores them in name."<<endl<<endl;
104 cout<<
"Usage: "<<argv[0]<<
" [options] <origImgA> <origImgB>"<<endl;
111 if(ImageIO::Load(argv[fup], camA)!=0) {
112 cerr<<
"[ERROR] Unable to load first camera!"<<endl;
116 if(ImageIO::Load(argv[fup+1], camB)!=0) {
117 cerr<<
"[ERROR] Unable to second first camera!"<<endl;
122 bool useSetup =
false;
123 bool generateSetup =
false;
124 if(rectSetupName->size()>0) {
126 if(ImageIO::Load(*rectSetupName, rectSetup)<0) {
127 cerr<<
"[ERROR] Could not open rectification setup file "
128 <<*rectSetupName<<endl;
129 cerr<<
" It will be created from given parameters."<<endl;
130 generateSetup =
true;
143 rectifier = rectifierPM =
147 rectifier = rectifierPM =
151 rectifier = rectifierPM =
155 cerr<<
"[ERROR] Unknown rectification type "
156 <<*rectType<<
" given!"<<endl;
169 cerr<<
"[ERROR] Unknown interpolation method "
170 <<*interType<<
" given!"<<endl;
177 cerr<<
"[ERROR] Invalid camera type for camera A!"<<endl;
183 cerr<<
"[ERROR] Invalid camera type for camera B!"<<endl;
191 cerr<<
"[ERROR] Failed to create rectification setup!"<<endl;
195 if(ImageIO::Save(*rectSetupName, rectSetup)<0) {
196 cerr<<
"[ERROR] Failed to write rectification setup to "
197 <<*rectSetupName<<endl;
202 cerr<<
"[ERROR] Failed to load rectification setup!"<<endl;
212 cerr<<
"[ERROR] Failed to retrieve rectification parameters!"<<endl;
217 cerr<<
"Found rectification parameters!"<<endl;
218 cerr<<
"- Camera A rectification state: "<<*rectPPA<<endl;
219 cerr<<
"- Camera B rectification state: "<<*rectPPB<<endl<<endl;
221 cerr<<
"Starting rectification... "<<flush;
223 cerr<<
" failed!"<<endl;
229 cerr<<
" done!"<<endl;
241 string path1, basename1, suffix1;
242 string path2, basename2, suffix2;
243 FileHandling::SplitName(argv[fup], path1, basename1, suffix1);
244 FileHandling::SplitName(argv[fup+1], path2, basename2, suffix2);
246 string firstName = basename1+
"_rect";
247 string secondName = basename2+
"_rect";
250 if(ImageIO::Save(firstName, rectA, ImageIO::FF_mip)!=0) {
251 cerr<<
"[ERROR] Failed to write first rectified image!"<<endl;
253 if(ImageIO::Save(secondName, rectB, ImageIO::FF_mip)!=0) {
254 cerr<<
"[ERROR] Failed to write second rectified image!"<<endl;
264 cerr<<
"Generating VRML models with rectification data:"<<endl;
265 cerr<<
"- First VRML containing coordinate systems only... "<<flush;
268 if(tdo.
VRMLOut(
"rectCoordinates.wrl")!=0) {
280 cerr<<
"- Generating VRML models containing projected images... "<<flush;
281 unsigned int width = 0, height = 0;
288 for (
unsigned int y=0; y<height; y++) {
289 for (
unsigned int x=0; x<width; x++) {
292 if (p3.
NormL2()<0.1)
continue;
294 RGBAuc theColor((
unsigned char)color,(
unsigned char)color,
295 (
unsigned char)color,255);
301 ImageConvert::ToRGB(rectA, RGBrectA);
304 ImageConvert::ConvertST(RGBrectA, tmp, ImageBase::ST_unsignedchar);
311 for (
unsigned int y=0; y<height; y++) {
312 for (
unsigned int x=0; x<width; x++) {
315 if (p3.
NormL2()<0.1)
continue;
316 unsigned char color =
318 RGBAuc theColor(color,color,color,255);
324 ImageConvert::ToRGB(rectB, RGBrectB);
327 ImageConvert::ConvertST(RGBrectB, tmp, ImageBase::ST_unsignedchar);
332 cerr<<
"done!"<<endl<<flush;
334 tdo.
VRMLOut(
"rectCoordinates_image.wrl");
335 cerr<<
"- Writing mipview3d animation file 'cylindersweep.anim'... "<<flush;
336 ofstream myanimfile(
"cylindersweep.anim");
337 myanimfile <<
"[0] :43 0 0 0 0 1 0 0 0"<<endl
338 <<
"[0] :43 1000 " <<c[0]<<
" "<<c[1]<<
" "<<c[2]
341 cerr<<
"- Generating VRML models with original cameras... "<<flush;
345 ImageConvert::ToRGB(camA, RGBcamA);
347 ImageConvert::ToRGB(camB, RGBcamB);
359 cerr<<
"done!"<<endl<<flush;
virtual BIAS::Vector3< double > GetC() const
Get projection center.
unsigned int AddTriangleMesh(const TriangleMesh &mesh, const std::string &name="", const std::string &textureOutputName="", bool writeOutTexture=true, bool calcNormals=false)
Adds triangle mesh as IndexedFaceSet to ThreeDOut mem.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Base class for rectification implementations that make use of projections to represent rectified stat...
int VRMLOut(const std::string &sFilename)
flush all 3d objects to a vrml file with name sFilename, this is the function most users would call ...
void GenerateTexturedCamera(const ProjectionParametersBase *PPB, Image< unsigned char > &rgbtexture, const double &scale=1.0, const double &opacity=1.0, const double &resolution=1.0)
generates the sensor plane / cylinder / sphere in 3D space
void GetRectifiedImageA(Image< OutputStorageType > &rectImg)
class RGBAuc is asynonym for a Vector4 of corerct type
Unified output of 3D entities via OpenGL or VRML.
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
base class for rectification implementations and wrappers
virtual int GetClonesOfRectificationParameters(ProjectionParametersBase *&rectPPA, ProjectionParametersBase *&rectPPB)
Tries to calculate the rectification parameters and returns clones of internal members.
int SetRectificationSetup(Camera< float > &rectSetup)
Loads rectification setup from Camera data.
int * AddParamEnum(const std::string &name, const std::string &help, const std::vector< std::string > &enums, const int deflt=0, const std::vector< int > *IDs=NULL, const char cmdshort=0, const int Group=GRP_NOSHOW)
Class implements rectification by image projection onto a cylinder.
void SetScale(const double &scale)
Scale factor for isotropically scaling the rectified images (and rectified intrinsic parameters)...
unsigned int GetWidth() const
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
double NormL2() const
Return the L2 norm: sqrt(a^2 + b^2 + c^2 + d^2)
unsigned int AddProjection(const Projection &p, const RGBAuc &colorSelection=RGBAuc_WHITE_OPAQUE, const double radius=0.1, const double scale=1.0, const std::string &identifier="", const int camera_type=-1)
Add a projection object to ThreeDOut mem.
int GetRectificationSetup(Camera< float > &rectSetup)
Method returns the current rectification setup.
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
void SetInterpolationMethod(InterpolationMethod interpolationType)
Determines the type of interpolation used when rectifying.
Create and represent a 3D triangle mesh.
int SetProj(const Projection &Proj)
unsigned int GetHeight() const
Class implements rectification by image projection onto a sphere.
void UseLookUpTables(bool use)
Method allows to turn on or off the use of look up tables.
Rectification via perspective cameras, removes distortions.
unsigned int AddLine(const BIAS::Vector3< double > &Start, const BIAS::Vector3< double > &End, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
void SetSecondFill(OutputStorageType d)
fill color for second image (first is black)
virtual int SetCameraB(BIAS::Camera< InputStorageType > &cam)
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
virtual int Rectify()=0
Fundamental method which contains the rectification implementation.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
int UpdateMetaData()
copy P_ and co.
This class Param provides generic support for parameters.
void GetRectifiedImageB(Image< OutputStorageType > &rectImg)
virtual int SetCameraA(BIAS::Camera< InputStorageType > &cam)
unsigned int AddPoint(const BIAS::Vector3< double > &v, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
const BIAS::Projection & GetProj() const
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
virtual HomgPoint3D UnProjectToImagePlane(const HomgPoint2D &pos, const double &depth=1.0, bool IgnoreDistortion=false) const =0
map points from image onto unit diameter image plane in 3D.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase