1 #include <Image/CylindricDepthTrackingPanorama.hh>
2 #include <Base/Image/ImageIO.hh>
3 #include <Image/MixtureOfGaussians.hh>
4 #include <Base/ImageUtils/ImageDraw.hh>
5 #include <Image/CylindricDepthPanorama.hh>
6 #include <Base/Common/FileHandling.hh>
13 CylindricDepthTrackingPanorama::
14 CylindricDepthTrackingPanorama(
const Projection& initialProjection,
15 unsigned int channels,
47 unsigned int width = depthMap.
GetWidth();
48 unsigned int height = depthMap.
GetHeight();
52 normalizedDepthMap_ = depthMap;
60 min[0] = width; min[1] = height;
61 max[0] = 0; max[1] = 0;
63 for(
unsigned int y=0;y<height;y++){
64 for(
unsigned int x=0;x<width;x++){
65 if (ida[y][x] != 0.0 && ida[y][x] != 1.0) {
76 for(
unsigned int y=height-1;y>min[1];y--){
77 for(
unsigned int x=width-1;x>0;x--){
78 if (ida[y][x] != 0.0 && ida[y][x] != 1.0) {
88 for(
unsigned int y=(
unsigned int)min[1];y<(
unsigned int)max[1];y++){
89 for(
unsigned int x=(
unsigned int)min[0];x>0;x--){
90 if (ida[y][x] != 0.0 && ida[y][x] != 1.0) {
98 for(
unsigned int y=(
unsigned int)min[1];y<(
unsigned int)max[1];y++){
99 for(
unsigned int x=(
unsigned int)max[0];x<width;x++){
100 if (ida[y][x] != 0.0 && ida[y][x] != 1.0) {
110 unsigned int xdiff = (
unsigned int)rint(max[0]-min[0]) / 6;
111 unsigned int ydiff = (
unsigned int)rint(max[1]-min[1]) / 6;
121 for(
unsigned int x=(
unsigned int)min[0];x<(
unsigned int)max[0];x++){
122 for(
unsigned int y=(
unsigned int)min[1];y<(
unsigned int)max[1];y++){
123 if (ida[y][x] == 1.0) {
131 cout<<
"determined roi:"<<min[0]<<
","<< min[1]<<
","<< max[0]<<
","<< max[1]<<endl;
133 depthMap.
SetROICorners((
unsigned int)min[0], (
unsigned int)min[1],
134 (
unsigned int)max[0], (
unsigned int)max[1]);
135 normalizedDepthMap_.
SetROICorners((
unsigned int)min[0], (
unsigned int)min[1],
136 (
unsigned int)max[0],(
unsigned int) max[1]);
137 ret = doTrack(depthMap, p, texture);
153 cout <<
" LOADING PANORAMA" << endl;
154 for (
int i=0;i<50;i++) {
185 pRescaledProjection_.
Rescale((
float)factor);
188 pRescaleFilter_.
SetFactor((
float)factor);
191 int width = depthDownSampled_.
GetWidth();
192 int height = depthDownSampled_.
GetHeight();
200 for (
int x=0;x<width;x++) {
201 for (
int y=0;y<height;y++) {
202 if (idaD[y][x] < 10.0)
204 float minDepth_ = idaD[y][x];
205 float maxDepth_ = idaD[y][x];
206 for (
int xw=x-1;xw<=x+1;xw+=1) {
207 for (
int yw=y-1;yw<=y+1;yw+=1) {
208 if (xw >= 0 && yw >= 0 && xw < width && yw < height) {
209 if (idaD[yw][xw] > maxDepth_)
210 maxDepth_ = idaD[yw][xw];
211 if (idaD[yw][xw] < minDepth_)
212 minDepth_ = idaD[yw][xw];
216 if (maxDepth_ - minDepth_ < 1000.0)
217 idaF[y][x] = idaD[y][x];
220 depthDownSampled_ = filteredDepthMap_;
223 cout << pRescaledProjection_ << endl;
238 int CylindricDepthTrackingPanorama::
245 depthMap.
GetROICorners(tmpCorners[0],tmpCorners[1],tmpCorners[2],tmpCorners[3]);
247 bb_.
UL[0] = (unsigned)tmpCorners[0];
248 bb_.
UL[1] = (unsigned)tmpCorners[1];
249 bb_.
LR[0] = (unsigned)tmpCorners[2];
250 bb_.
LR[1] = (unsigned)tmpCorners[3];
252 cout <<
" DO PANORAMA" << endl;
261 float depthValue=0.0;
263 for (
unsigned int y=(
unsigned)bb_.
UL[1];y<(
unsigned)bb_.
LR[1]-1;y++) {
264 for (
unsigned int x=(
unsigned)bb_.
UL[0];x<(
unsigned)bb_.
LR[0]-1;x++) {
265 depthValue = ida[y][x];
266 if (depthValue > 0.0) {
270 idaTex[y][x*dTexChannels_+i] = texture->
GetImageDataArray()[y][x*dTexChannels_+i];
273 if(idaPHC[y][x] == 0.0){
274 idaP[y][x]=depthValue;
279 (idaP[y][x] * idaPHC[y][x]+depthValue)/(idaPHC[y][x]+1);
289 int CylindricDepthTrackingPanorama::
298 cout <<
"TRACK!" << endl;
300 depthMap.
GetROICorners(tmpCorners[0],tmpCorners[1],tmpCorners[2],tmpCorners[3]);
302 bb_.
UL[0] = (unsigned)tmpCorners[0];
303 bb_.
UL[1] = (unsigned)tmpCorners[1];
304 bb_.
LR[0] = (unsigned)tmpCorners[2];
305 bb_.
LR[1] = (unsigned)tmpCorners[3];
316 for (
unsigned int y=(
unsigned)bb_.
UL[1];y<(
unsigned)bb_.
LR[1]-1;y++) {
317 for (
unsigned int x=(
unsigned)bb_.
UL[0];x<(
unsigned)bb_.
LR[0]-1;x++) {
318 float depthValue = ida[y][x];
320 if (depthValue > 0.0) {
324 idaTex[y][x*dTexChannels_+i] = idaT[y][x*dTexChannels_+i];
327 if(idaPHC[y][x] == 0.0){
328 idaD[y][x]=depthValue;
333 (idaD[y][x] * idaPHC[y][x]+depthValue)/(idaPHC[y][x]+1);
338 if (idaDif[y][x] > 64) {
339 if (abs(depthValue - idaD[y][x]) > 400.0) {
340 idaNsDep[y][x] = depthValue;
342 idaNsTex[y][x*dTexChannels_+i] = idaT[y][x*dTexChannels_+i];
346 idaTex[y][x*dTexChannels_+i] = idaT[y][x*dTexChannels_+i];
347 idaNsTex[y][x*dTexChannels_+i] = 0;
351 (idaD[y][x] * idaPHC[y][x]+depthValue)/(idaPHC[y][x]+1);
359 idaNsTex[y][x*dTexChannels_+i] = 0;
361 (idaD[y][x] * idaPHC[y][x]+depthValue)/(idaPHC[y][x]+1);
387 for (
unsigned int y=(
unsigned)bb_.
UL[1];y<(
unsigned)bb_.
LR[1]-1;y++) {
388 for (
unsigned int x=(
unsigned)bb_.
UL[0];x<(
unsigned)bb_.
LR[0]-1;x++) {
389 if (idaNsDep[y][x] != 0) {
406 if (x < rectangle.
UL[0])
408 if (y < rectangle.
UL[1])
410 if (x > rectangle.
LR[0])
412 if (y > rectangle.
LR[1])
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.
unsigned int panoramaHeight_
BIAS::ProjectionParametersCylindric * pCylinderProj_
void SetSmoothing(const bool smooth)
BIAS::Projection initialProjection_
BIAS::Image< unsigned char > difference_
BIAS::MixtureOfGaussians< float > * mog_
void SetLowPassType(int lpt)
Sets the lowpass filter by a lowpass filter type.
BIAS::Vector2< double > LR
void Rescale(float ratio, unsigned int cam=0)
adapt internal params to resampled image
Down-, Upsampling routines and Resize.
unsigned int GetWidth() const
int GetPanorama(BIAS::Image< float > &image, BIAS::Image< unsigned char > &texture)
int InitWeights(const int maxWeight, const int minWeight, const float errorMargin)
init weights for background/object distinction
void GetROICorners(unsigned int &UpperLeftX, unsigned int &UpperLeftY, unsigned int &LowerRightX, unsigned int &LowerRightY) const
access region of interest rectangle JW
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
BIAS::Image< unsigned char > panoramaTexture_
class Vector4 contains a Vector of dim.
Helper class to store blob corners.
BIAS::Image< float > panoramaHitCount_
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
create and represent cylindric depth panorama
BIAS::Image< unsigned char > panoramaNonStaticTexture_
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()
BIAS::Image< float > panorama_
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
BIAS::Image< float > panoramaNonStatic_
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.
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
virtual ~CylindricDepthTrackingPanorama()
BIAS::Vector2< double > UL
int GetDifferenceImage(BIAS::Image< unsigned char > &diff)
get image of detected scene changes.
int GetTriangleMesh(BIAS::TriangleMesh &mesh)
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...
int GetPanorama(BIAS::Image< float > &image, BIAS::Image< unsigned char > &texture)
unsigned int dTexChannels_
unsigned int panoramaWidth_
int ProcessCylindricProjection(BIAS::Image< float > &depthMap, BIAS::Projection &p, BIAS::Image< unsigned char > *texture=NULL)
Call Process to update the measurement.
int SetROICorners(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
int Apply(BIAS::Image< StorageType > &in)
update calculations with new image the image has to be formatted correctly, e.g for MoG on HSL images...
void SetFactor(double factor)
the downsampling factor
int LoadPanorama(const std::string filename)
int SavePanorama(const std::string filename)
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase