1 #include <Base/Image/Image.hh>
2 #include <Base/Image/ImageIO.hh>
3 #include <Geometry/Projection.hh>
4 #include <Geometry/ProjectionParametersFactory.hh>
5 #include <Geometry/ProjectionParametersPerspective.hh>
6 #include <Geometry/ProjectionParametersSpherical.hh>
7 #include <Geometry/ProjectionParametersCylindric.hh>
8 #include <Utils/Param.hh>
21 int main(
int argc,
char *argv[])
24 cout <<
"Usage: " << argv[0] <<
" <input image file> [<output image>] "
25 <<
"<source projection> <output projection>" << endl;
32 cerr <<
"Failed to load image \"" << argv[1] <<
"\"!" << endl;
40 const std::string srcFile = argv[argc > 4 ? 3 : 2];
42 if (srcProj == NULL) {
45 if (proj.
Load(srcFile) != 0) {
46 cerr <<
"Failed to load source projection from \"" << srcFile <<
"\"!" << endl;
48 }
else if (proj.
Size() != 1) {
49 cerr <<
"Source projection contains " << proj.
Size() <<
" parameters!" << endl;
58 unsigned int srcWidth, srcHeight;
62 cerr <<
"Source image and source projection have different dimensions!" << endl;
67 const std::string outFile = argv[argc > 4 ? 4 : 3];
69 if (outProj == NULL) {
72 if (proj.
Load(outFile) != 0) {
73 cerr <<
"Failed to load output projection from \"" << outFile <<
"\"!" << endl;
75 }
else if (proj.
Size() != 1) {
76 cerr <<
"Output projection contains " << proj.
Size() <<
" parameters!" << endl;
85 unsigned int outWidth, outHeight;
86 const unsigned int outChannels = srcChannels;
98 for (
unsigned int u = 0; u < outWidth; u++) {
99 for (
unsigned int v = 0; v < outHeight; v++) {
103 if (ray.
NormL2() == 0.0)
continue;
108 if ((
int)srcPos[0] >= 0 && (int)srcPos[0] < (
int)srcWidth &&
109 (int)srcPos[1] >= 0 && (
int)srcPos[1] < (
int)srcHeight) {
110 for (
unsigned int c = 0; c < outChannels; c++)
111 outImage.SetPixel(srcImage.
PixelValue((
int)srcPos[0] % srcWidth, (
int)srcPos[1], (
unsigned short)c),
112 u, v, (
unsigned short)c);
119 const std::string outFilename = (argc > 4 ? argv[2] :
"output.png");
121 cerr <<
"Failed to save output image to \"" << outFilename <<
"\"!" << endl;
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
unsigned int GetWidth() const
virtual void UnProjectToRay(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const
Calculates the view ray, which belongs to the given position on the image plane, in global coordinate...
StorageType PixelValue(const unsigned int x, const unsigned int y, const unsigned short int channel=0) const
Returns value of pixel at specific position, using specific channel as offset.
virtual HomgPoint2D Project(const HomgPoint3D &X, bool IgnoreDistortion=false) const
calculates the projection of a point in the world coordinate system to a pixel in the image plane of ...
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
ProjectionParametersBase * Load(const std::string &fileName)
Loads a projection parameters object from a file.
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
This class hides the underlying projection model, like projection matrix, spherical camera...
bool IsAtInfinity() const
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
unsigned int Size() const
Determine number of ProjectionParameterBase pointers in Projection.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
ProjectionParametersBase * GetParameterCloneWithAbsolutePose(unsigned int cam=0) const
Allocates memory for parameters base type and returns pointer to it!
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)