Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCalibratedPyramid.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example ExampleCalibratedPyramid.cpp
27  @relates CalibratedPyramid
28  @brief Example for creating a calibrated pyramid object with
29  automatic adaption of BIAS::Projection to pyramid layers
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include <Base/Image/ImageIO.hh>
35 #include <Base/Image/ImageConvert.hh>
36 #include <Image/CalibratedPyramid.hh>
37 #include <Image/Camera.hh>
38 
39 using namespace BIAS;
40 using namespace std;
41 
42 int main(int argc, char *argv[])
43 {
44  if (argc<2){
45  cerr << argv[0] << " <image>"<<endl;
46  return -1;
47  }
48 
51  Camera<unsigned char> cam, tmp;
52 
53  if (ImageIO::Load(argv[1], cam)!=0){
54  cerr << "error loading image \""<<argv[1]<<"\"\n";
55  return -2;
56  }
57 
58  // extract projections
59  cam.ParseMetaData();
60  BIASASSERT(cam.IsProjValid());
62  BIASASSERT(ci.projection);
63  if (cam.GetChannelCount()!=1){
64  if (ImageConvert::ToGrey(cam, tmp)!=0){
65  return -3;
66  }
67  cam = tmp;
68  }
70  // this does not Work!!! SharedPtr is destructing object and it ends in a double free
71  // ci.image = SharedPtr<Image<unsigned char> >(&cam);
72 
73  double rescale = 4.0;
74  unsigned size = 2;
75  cp.Init(ci, size, rescale);
76 
77  cout<<"Size:"<<cp.Size()<<endl;
78  cout<<"RefCount image:"<<RefCount(ci.image)<<endl;
79  cout<<"RefCount projection:"<<RefCount(ci.projection)<<endl;
80  return 0;
81 }
This class takes care of consisiten re-sampling of images and associated ProjectionParameters.
unsigned Size() const
returns the number of images stored in the pyramid
virtual ProjectionParametersBase * Clone() const =0
Covariant virtual copy constructor used in BIAS::Projection.
pointer with reference count and automatic deletion
Definition: SharedPtr.hh:50
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
Definition: Projection.hh:194
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
unsigned RefCount(const SharedPtr< T > &t)
SharedPtr< Image< StorageType > > image
helper class holding image and associated calibration
SharedPtr< ProjectionParametersBase > projection
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...
Definition: ImageIO.cpp:141
bool IsProjValid() const
Definition: Camera.hh:221
void Init(const CalibratedImage< StorageType > &image, const unsigned pyramid_size=2, const double rescale_factor=4.0)
initialization with original image, total number of images in the pyramid and a rescale factor...
const BIAS::Projection & GetProj() const
Definition: Camera.hh:109
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
Definition: Camera.cpp:154
static int ToGrey(const ImageBase &source, ImageBase &dest)
wrapper for the templated function ToGrey