1 #include <Image/CylindricDepthPanorama.hh>
2 #include <Base/Image/ImageConvert.hh>
3 #include <Base/Image/ImageIO.hh>
4 #include <Utils/ThreeDOut.hh>
5 #include <Image/ForwardMappingNearestNeighbour.hh>
6 #include <Base/Common/FileHandling.hh>
11 static int imageCount=0;
17 bCostImageCreated_=
false;
23 unsigned int channels)
27 bCostImageCreated_=
false;
28 Init(initialProjection,channels);
33 unsigned int channels)
37 bCostImageCreated_=
false;
43 unsigned int channels)
46 return Init(p,channels);
51 if((dynamic_cast<const ProjectionParametersCylindric*>(iP.
GetParameters()))== NULL){
52 BIASERR(
"Not a cylindric projection.");
56 bTextureFilled_ =
false;
57 bFirstPoseSet_ =
false;
58 dTexChannels_ = channels;
59 initialProjection_ = iP;
61 pCylinderProj_->GetImageSize(panoramaWidth_,panoramaHeight_);
63 panorama_.Init(panoramaWidth_,panoramaHeight_,1);
64 panoramaHitCount_.Init(panoramaWidth_,panoramaHeight_,1);
65 panoramaHitCount_.FillImageWithConstValue(0.0);
66 panoramaTexture_.Init(panoramaWidth_,panoramaHeight_,dTexChannels_);
70 bFirstPoseSet_ =
true;
95 pCylinderProj_->SetQC(initialProjection_.GetQ(),initialProjection_.GetC());
96 bFirstPoseSet_ =
true;
99 if(!bCostImageCreated_){
102 float wh =(float)(w/2.0);
103 float hh =(float)(h/2.0);
105 costIm_.Init((
unsigned)rint(w),(
unsigned)rint(h),3);
106 float ** ida = costIm_.GetImageDataArray();
108 double maxradius = sqrt((wh)*(wh) + (hh)*(hh));
110 for(
unsigned x=0;x<(unsigned)w;x++){
111 for(
unsigned y=0;y<(unsigned)h;y++){
112 radius=sqrt((x-wh)*(x-wh) + (y-hh)*(y-hh));
114 if(radius <=0) radius=1e-10;
115 ida[y][x*3]= float((maxradius-radius)/maxradius)*255.0f;
116 ida[y][x*3+1]= float((maxradius-radius)/maxradius)*255.0f;
117 ida[y][x*3+2]= float((maxradius-radius)/maxradius)*255.0f;
120 bCostImageCreated_=
true;
127 stringstream file,file1,file2;
133 fm.
Map(&depthMap,destDepth_,&textureImage,tmpTex);
136 fm.
Map(&depthMap,destDepth_,&costIm_,tmpCost);
154 float **ida = destDepth_.GetImageDataArray();
155 unsigned char **idaDestTex = destTex_.GetImageDataArray();
156 float **idaP = panorama_.GetImageDataArray();
157 float **idaPHC = panoramaHitCount_.GetImageDataArray();
158 unsigned char** idaTex = panoramaTexture_.GetImageDataArray();
160 int width = destDepth_.GetWidth();
161 int height = destDepth_.GetHeight();
163 float depthValue=0.0;
167 unsigned channels = destTex_.GetChannelCount();
169 if (!useProjection) {
170 for(
int x=0;x<width;x++){
171 for(
int y=0;y<height;y++){
172 depthValue = ida[y][x];
173 if (depthValue > 0.0) {
176 for (
unsigned int i=0;i<channels;i++) {
177 unsigned char val = idaDestTex[y][x*channels+i];
179 idaTex[y][x*channels+i] = val;
182 bTextureFilled_ =
true;
184 if(idaPHC[y][x] == 0.0){
185 idaP[y][x]=depthValue;
190 (idaP[y][x] * idaPHC[y][x]+depthValue)/(idaPHC[y][x]+1);
198 for(
int x=0;x<width;x++){
199 for(
int y=0;y<height;y++){
203 depthValue = ida[y][x];
204 if (depthValue != 0.0) {
207 cylPoint = pCylinderProj_->Project(point3D);
209 x1 = (
unsigned int)cylPoint[0];
210 y1 = (
unsigned int)cylPoint[1];
214 if(x1>=0.0 && x1<panoramaWidth_ &&
215 y1>=0.0 && y1<panoramaHeight_ ) {
218 for (
unsigned int c=0;c<dTexChannels_;c++)
219 idaTex[y1][x1*dTexChannels_+c] = texture->
GetImageDataArray()[y][x*dTexChannels_+c];
220 bTextureFilled_ =
true;
222 if(idaPHC[y1][x1] == 0.0){
223 idaP[y1][x1]=depthValue;
228 (idaP[y1][x1] * idaPHC[y1][x1]+depthValue)/(idaPHC[y1][x1]+1);
244 if(!inited_)
return -1;
253 if(!inited_)
return -1;
257 texture = panoramaTexture_;
270 if(!inited_)
return -1;
277 outProj.
Rescale((
float)factor);
278 BIAS::Image<float> depthDownSampled_(panoramaWidth_ / factor, panoramaHeight_ / factor);
282 pRescaleFilter_.
SetFactor((
float)factor);
284 pRescaleFilter_.
Filter(panorama_, depthDownSampled_);
285 pRescaleFilterUC_.
SetFactor((
float)factor);
287 pRescaleFilterUC_.
Filter(panoramaTexture_, textureDownSampled_);
289 int width = depthDownSampled_.
GetWidth();
290 int height = depthDownSampled_.
GetHeight();
298 for (
int x=0;x<width;x++) {
299 for (
int y=0;y<height;y++) {
300 if (idaD[y][x] < 10.0)
302 float minDepth_ = idaD[y][x];
303 float maxDepth_ = idaD[y][x];
304 for (
int xw=x-1;xw<=x+1;xw+=1) {
305 for (
int yw=y-1;yw<=y+1;yw+=1) {
306 if (xw >= 0 && yw >= 0 && xw < width && yw < height) {
307 if (idaD[yw][xw] > maxDepth_)
308 maxDepth_ = idaD[yw][xw];
309 if (idaD[yw][xw] < minDepth_)
310 minDepth_ = idaD[yw][xw];
314 if (maxDepth_ - minDepth_ < 1000.0)
315 idaF[y][x] = idaD[y][x];
318 depthDownSampled_ = filteredDepthMap_;
341 if(pCylinderProj_ != NULL){
344 panoramaWidth_,panoramaHeight_);
void SetFillAreaWindowSize(unsigned int size)
void SetFillArea(int area)
void SetSourceCam(const Projection &P)
int GenerateDenseMesh(const BIAS::Image< float > &DenseDepthMap, const BIAS::Image< unsigned char > &Texture)
Calculate a triangle mesh from dense depth map without PMatrix.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
int ScaleShiftBetween(double Min, double Max)
scales and shifts image so afterwards every pixel has a value between Min and Max ...
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
int ProcessCylindricProjection(BIAS::Image< float > &depthMap, BIAS::Projection &p, BIAS::Image< unsigned char > *texture=NULL, bool useProjection=true)
Call Process to update the measurement.
void SetLowPassType(int lpt)
Sets the lowpass filter by a lowpass filter type.
int GetMappedImages(BIAS::Image< float > &image, BIAS::Image< unsigned char > &texture)
void Rescale(float ratio, unsigned int cam=0)
adapt internal params to resampled image
Down-, Upsampling routines and Resize.
unsigned int GetWidth() const
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
Create and represent a 3D triangle mesh.
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
scales the src to dst using the downsampling factor from SetFactor()
static std::string LeadingZeroString(const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
Create a string with leading zeroes from number.
unsigned int GetHeight() const
void FillImageWithConstValue(StorageType Value)
fill grey images
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.
int Map(const BIAS::Image< InputStorageType > *in, BIAS::Image< OutputStorageType > &out, const BIAS::Image< InputStorageType > *texin, BIAS::Image< OutputStorageType > &texout)
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Vector3< double > UnProjectToPoint(const HomgPoint2D &pos, double depth, unsigned int cam=0, bool IgnoreDistortion=false) const
calculates a 3D point in the global (not the rig) coordinate system, which belongs to the image posit...
int GetPanorama(BIAS::Image< float > &image, BIAS::Image< unsigned char > &texture)
(8bit) unsigned char image storage type
int GetTriangleMesh(BIAS::TriangleMesh &mesh)
void SetSinkCam(const Projection &P, const unsigned int dTexChannels=1)
int Init(const Projection &iP, unsigned int channels)
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
void SetFactor(double factor)
the downsampling factor
~CylindricDepthPanorama()
Destructor.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase