25 #include "ImageWarper.hh"
26 #include <OpenGLFramework/Base/glfBatch.hh>
27 #include <Base/Image/ImageIO.hh>
28 #include <Base/Debug/TimeMeasure.hh>
34 template <
class StorageType>
37 ignoreRadialDist_ = ignoreRadialDistortion;
41 template <
class StorageType>
48 template <
class StorageType>
int
52 float minZ,
float maxZ){
84 std::cout <<
"ImageWarper Init Error: " << e.
GetMessageString() << std::endl;
92 resultTexture.Create();
93 resultTexture.SetMagFilter(GL_NEAREST);
94 resultTexture.SetMinFilter(GL_NEAREST);
95 resultTexture.SetWrapS(GL_CLAMP);
96 resultTexture.SetWrapT(GL_CLAMP);
97 resultTexture.Allocate(width_, height_, GL_RGB);
99 std::cout <<
"ImageWarper resultTexture error: " << e.
GetMessageString() << std::endl;
103 depthTexture.Create();
104 depthTexture.SetMagFilter(GL_NEAREST);
105 depthTexture.SetMinFilter(GL_NEAREST);
106 depthTexture.SetWrapS(GL_CLAMP);
107 depthTexture.SetWrapT(GL_CLAMP);
108 depthTexture.Allocate(width_, height_, GL_DEPTH_COMPONENT);
110 std::cout <<
"ImageWarper depthTexture error: " << e.
GetMessageString() << std::endl;
114 depthWarpFBO_.Create();
115 depthWarpFBO_.AttachTexture(resultTexture,GL_COLOR_ATTACHMENT0_EXT);
116 depthWarpFBO_.AttachTexture(depthTexture,GL_DEPTH_ATTACHMENT_EXT);
117 depthWarpFBO_.CheckComplete();
119 std::cout <<
"ImageWarper depthWarpFBO error: " << e.
GetMessageString() << std::endl;
127 if(ignoreRadialDist_)
128 depthMeshing_.Init(source_,
false);
131 depthMeshing_.Init(source_,hasDist);
134 std::cout <<
"ImageWarper depthMeshing_.Init() error: " << e.
GetMessageString() << std::endl;
138 depthMeshing_.SetRenderTarget(&depthWarpFBO_);
139 depthMeshing_.SetTargetCameraParameters(target_, minZ, maxZ);
142 std::cout <<
"ImageWarper depthMeshing_.SetRenderTarget error: " << e.
GetMessageString() << std::endl;
151 template <
class StorageType>
int
154 float minZ,
float maxZ){
157 depthMeshing_.SetTargetCameraParameters(target_, minZ, maxZ);
163 template <
class StorageType>
int
169 float minZ,
float maxZ,
bool getdepth){
174 pBuffer_.MakeCurrent();
175 depthMeshing_.UploadProjectiveTexture(colorImage);
176 ret = Process(depthImage,warpedDepthImage,minZ,maxZ,getdepth);
177 resultTexture.CopyToImage(warpedColorImage,0);
181 template <
class StorageType>
int
185 float minZ,
float maxZ,
bool getdepth){
188 if(!inited_)
return -1;
191 pBuffer_.MakeCurrent();
192 glViewport(0,0, width_, height_);
193 depthWarpFBO_.ClearColorBuffer();
194 depthWarpFBO_.ClearDepthBuffer();
195 depthMeshing_.UploadDepthMap(depthImage);
202 depthMeshing_.Draw();
209 depthTexture.CopyToImage(warpedDepthImage,0);
221 for (
unsigned int y=0; y<warpedDepthImage.
GetHeight(); y++) {
222 for (
unsigned int x=0; x<warpedDepthImage.
GetWidth(); x++) {
223 if (z[y][x] >= 1.0) z[y][x] = 0.0;
224 else if(z[y][x] != 0.0){
225 z[y][x] = minZ*maxZ / (maxZ - (z[y][x])*(maxZ-minZ));
226 target_.UnProjectToRay(
HomgPoint2D(x,y,1.0), pos, ray);
227 ray = (z[y][x] / ray[2])*ray;
245 template <
class StorageType>
void
255 template <
class StorageType>
void
258 unsigned width,
unsigned height,
261 SetDefaultTextureParameters_(tex);
262 tex.
Allocate(width, height, intFormat);
void Allocate(int width, int height, GLenum internalFormat, int mipmap=0)
Creates a texture with undefined content.
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...
void SetWrapS(GLenum wrapS)
Sets the wrapping mode for the 1st texture coordinate.
this class warpes depth images from one persective to the perspective of another camera.
int Init(BIAS::ProjectionParametersPerspective &source, BIAS::ProjectionParametersPerspective &target, float minZ=500, float maxZ=7500.0)
Init the warping with projection parameters.
Exception class used for run-time errors in the OpenGLFramework.
unsigned int GetWidth() const
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.
ImageWarper(bool ignoreRadialDistortion=false)
void SetWrapT(GLenum wrapT)
Sets the wrapping mode for the 2nd texture coordinate.
unsigned int GetHeight() const
int ProcessWithColor(BIAS::Image< StorageType > &depthImage, BIAS::Image< unsigned char > &colorImage, BIAS::Image< StorageType > &warpedDepthImage, BIAS::Image< unsigned char > &warpedColorImage, float minZ, float maxZ, bool getdepth=false)
Process one warping from source to target parameters including color texture information which has to...
The image template class for specific storage types.
int Process(BIAS::Image< StorageType > &depthImage, BIAS::Image< StorageType > &warpedDepthImage, float minZ=500, float maxZ=7500.0, bool getdepth=false)
Process one warping from source to target parameters.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
int SetTargetCamera(BIAS::ProjectionParametersPerspective &target, float minZ=500, float maxZ=7500.0)
Configuration for a rendering context.
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
static void SetDefaultRenderStates()
Sets all render states possibly modified by Batch to the OpenGL defaults.
class BIASGeometryBase_EXPORT HomgPoint2D
void SetMagFilter(GLenum magFilter)
Sets the magnification function.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase