26 #include <bias_config.h>
27 #include <Base/Image/Image.hh>
28 #include <Base/Image/ImageConvert.hh>
29 #include <Image/Camera.hh>
30 #include <Image/PMDImageProc.hh>
31 #include <Utils/Param.hh>
32 #include <Utils/IOUtils.hh>
33 #include <Base/Image/ImageIO.hh>
34 #include <Filter/Median.hh>
35 #include <Filter/Bilateral.hh>
36 #ifdef BIAS_HAVE_OPENGL
37 #include <OpenGLFramework/RenderingContext/glfPBuffer.hh>
38 #include <OpenGLFramework/SpecializedBatches/PMDWarp.hh>
39 #include <OpenGLFramework/Base/glfException.hh>
40 #include <OpenGLFramework/Base/glfFramebufferObject.hh>
41 #include <Gui/biasgl.h>
58 int main(
int argc,
char* argv[])
62 string* tofImageName =
64 string* ampImageName =
65 params.
AddParamString(
"ampImage",
"amplitude image of tof camera [optional]",
"",
'a');
67 string* targetImageName =
68 params.
AddParamString(
"targetImage",
"target image name",
"result.mip",
'o');
70 string* sourceProjName =
71 params.
AddParamString(
"sourceProj",
"projection with params of source tof cam, ATTENTION Distortion parameters are NOT IGNORED",
"",
's');
72 string* targetProjName =
73 params.
AddParamString(
"targetProj",
"projection with params of target perspective cam, ATTENTION Distortion parameters are IGNORED",
"",
't');
74 bool* translateToDepth =
75 params.
AddParamBool(
"depth",
"output depth instead of z image",
false,
'd');
77 params.
AddParamBool(
"undistort",
"undistort depth",
false,
'u');
79 params.
AddParamBool(
"filterBilateral",
"filter image with bilateral filter",
false,
'b');
81 params.
AddParamBool(
"filterMedian",
"filter image with median filter",
false,
'm');
83 params.
AddParamBool(
"simpleProjectAndFill",
"use simple point projection and dilation instead of GPU warping",
false,
'S');
85 int *kernelsize = params.
AddParamInt(
"kernelsize",
"optional kernelsize for dilation in simple projection case",10,1,1000,
'k');
89 if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv) )
102 bool tofIsPersp =
false;
103 bool hasTexture =
false;
106 BIASERR(
"Could not load tof image:"<<*tofImageName);
117 if(*ampImageName !=
""){
119 BIASERR(
"Could not load tof image:"<<*ampImageName);
129 if(tofProj.
Load(*sourceProjName)!=0) {
130 BIASERR(
"Could not load source tof projection: "<<*sourceProjName);
133 if(targetProj.
Load(*targetProjName)!=0) {
134 BIASERR(
"Could not load target tof projection:"<<*targetProjName);
144 BIASERR(
"wrong type dynamic cast failed!");
153 BIASERR(
"wrong type dynamic cast failed!");
161 cout<<
"Setting all values below 500 to 10 000\n";
166 cout<<
"Undistorting depth image\n";
172 cout<<
"Bilateral filtering image\n";
182 for (
unsigned int i = 0; i < 5; i++) {
183 if(*ampImageName !=
"")
184 bilateral.
Filter(tofImage, ampImage, filterTmp);
186 bilateral.
Filter(tofImage, filterTmp);
191 cout<<
"Median filtering image\n";
195 median.
Filter(tofImage, filterTmp);
196 tofImage = filterTmp;
202 for (
unsigned int y=0; y<tofImage.
GetHeight(); y++) {
203 for (
unsigned int x=0; x<tofImage.
GetWidth(); x++) {
204 if (ida[y][x] < *zNear || ida[y][x] > *zFar) {
215 PMDImageProc::FitDepthTo2DImage(tofImage,targetProj,tofProj,*kernelsize);
216 resultImg = tofImage;
220 #ifdef BIAS_HAVE_OPENGL
228 targetParam->
SetPose(relativePose);
230 unsigned int width, height;
256 resultTexture.
Allocate(width, height, GL_RGB);
264 depthTexture.
Allocate(width, height, GL_DEPTH_COMPONENT);
272 dispTexture.
Allocate(width, height, GL_LUMINANCE32F_ARB);
280 vector<GLenum> drawbuffers(2);
281 drawbuffers[0] = GL_COLOR_ATTACHMENT0_EXT;
282 drawbuffers[1] = GL_COLOR_ATTACHMENT1_EXT;
285 bool useDists =
true;
287 gpuDepthWarp.
Init(*tofParam, useDists);
289 gpuDepthWarp.
Init(*tofParamPersp, useDists);
298 else if(tofParamPersp != NULL)
314 if (*translateToDepth) {
317 double zNear_ = *zNear;
318 double zFar_ = *zFar;
319 for (
unsigned int y=0; y<resultImg.
GetHeight(); y++) {
320 for (
unsigned int x=0; x<resultImg.
GetWidth(); x++) {
321 if (z[y][x] >= 1.0) z[y][x] = 0.0;
322 else if(z[y][x] != 0.0){
323 z[y][x] = zNear_*zFar_ / (zFar_ - (z[y][x])*(zFar_-zNear_));
325 ray = (z[y][x] / ray[2])*ray;
346 BIASERR(
"Recompile BIAS with OpenGL to use GPU warping!");
350 ImageIO::Save(*targetImageName, resultImg);
void Allocate(int width, int height, GLenum internalFormat, int mipmap=0)
Creates a texture with undefined content.
void AttachTexture(const glfTexture &texture, GLenum attachmentPoint, int attachedMipMapLevel=0, int zSlice=0, GLenum cubeMapSide=0)
Attaches a texture to an attachment point which can be.
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
void SetSize(int newsize, int secondsize=-1)
additional depth calibration parameters for a perspective depth camera to be used for ToF-(PMD) camer...
void SetRenderTarget(const BIAS::glfRenderTarget *renderTarget)
void Create()
Creates the texture but does not upload any data yet.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
int BelowThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values below Threshold to Value
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)
void SetWrapS(GLenum wrapS)
Sets the wrapping mode for the 1st texture coordinate.
void SetSigma(const double si)
void SetDrawBuffers(const std::vector< GLenum > &drawbuffers)
void UploadProjectiveTexture(const BIAS::Image< unsigned char > &projectiveTexture)
Upload the color image to the graphics card.
void CopyToImage(ImageBase &image, int mipmap=0)
Copies the pixels of a mipmap of the texture to a BIAS::ImageBase.
Exception class used for run-time errors in the OpenGLFramework.
unsigned int GetWidth() const
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Bilateral filtering with given filter size (5x5 as standard)
virtual void Destroy()
Uninitializes the rendering context.
const std::string & GetMessageString() const
Returns the description of the error including the file name and line number where the error occured...
void SetMinFilter(GLenum minFilter)
Sets the minifying function.
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
void UnProjectToRayLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &rayDir, unsigned int camSystem=0, unsigned int cam=0, bool IgnoreDistortion=false) const
calculates a 3D ray in a local camera coordinate system specified by camSystem, which belongs to the ...
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
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 CheckComplete() const
Checks whether the framebuffer object is supported in its current state.
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
void Init(const BIAS::ProjectionParametersPerspective &pppd, bool targetParametersHaveDistortion=false)
Initializes all neccessary data in order to render using a batch.
void SetWrapT(GLenum wrapT)
Sets the wrapping mode for the 2nd texture coordinate.
unsigned int GetHeight() const
GLX pbuffer rendering context.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
virtual void Init(const glfRenderingContextConfig &config)
Initializes the rendering context with the given configuration.
This class Param provides generic support for parameters.
void SetIgnoreValue(InputStorageType ignore)
void SetBilateralSigma(const double si)
int UnDistortDepthMapIP(BIAS::Image< float > &depthMap, bool bIsInCartesianCoords=false)
Undistorts the passed depth map in place.
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...
void SetTargetCameraParameters(const BIAS::ProjectionParametersPerspective &relativePpp, double zNear, double zFar)
is also used to determine viewport
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
void UseProjectiveTexturing(const BIAS::ProjectionParametersPerspective &ppp)
ppp extrinsicis have to be in global coordinates of pppd of Init call! projective texturing cannot d...
int Flip()
flips the image vertically (row order is inverted) In place function return 0 in case of success...
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
void UploadDepthMap(const BIAS::Image< float > &pmdDepthImage)
Upload the pmd depth image to the graphics card.
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Configuration for a rendering context.
class can be used to warp sequences of pmd depth images into a second view with different parameters...
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
void Create()
Creates the framebuffer object.
void SetMagFilter(GLenum magFilter)
Sets the magnification function.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase