Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biasbayer2rgbDC1394.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT 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 ExampleConvertBayerPattern.cpp
27  @relates ConvertBayerPattern
28  @brief Example for converting Bayer Pattern to RGB images using BIAS::ConvertBayerPattern
29  @ingroup g_examples
30  @author bangerer
31 */
32 
33 
34 #ifndef WIN32
35 #include <Image/ConvertBayerPattern.hh>
36 #else
37 #error This tool requires LINUX
38 #endif
39 #include <Base/Image/ImageIO.hh>
40 #include <Base/Image/ImageBase.hh>
41 #include <Base/Image/ImageConvert.hh>
42 #include <dc1394/dc1394.h>
43 #include <dc1394/conversions.h>
44 
45 
46 #include <Utils/IOUtils.hh>
47 #include <Image/Camera.hh>
48 
49 using namespace BIAS;
50 using namespace std;
51 
52 int main(int argc, char *argv[])
53 {
54 
55  Param params(true);
56  vector<string> conversionMethod;
57  conversionMethod.push_back("NEAREST");
58  conversionMethod.push_back("SIMPLE");
59  conversionMethod.push_back("BILINEAR");
60  conversionMethod.push_back("HQLINEAR");
61  conversionMethod.push_back("VNG");
62  conversionMethod.push_back("AHD");
63  int* convMethod = params.AddParamEnum("conversionMethod",
64  "what method for conversion shall be used?"
65  " Default : AHD",
66  conversionMethod, 5, NULL, 'M');
67 
68  int fup = 0;
69  if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv, fup)){
70 
71  cout<<"Usage:\n"<<argv[0]<<" <srcImg> <targetImg> \n";
72  return 0;
73  }
74  if(argc<2) {
75  cout<<"Usage:\n"<<argv[0]<<" <srcImg> <targetImg> \n";
76  return 0;
77  }
78 
79  BayerDemosaicMethod method = (BayerDemosaicMethod)*convMethod;
80 
81  unsigned int width=0, height=0, channels=0;
82  Projection proj;
84 
85 
86  if(!IOUtils::LoadCamera(argv[fup], source, proj, width, height, channels)) {
87  cout<<"error loading "<<argv[fup]<<endl;
88  return -1;
89  }
90 
91  // read the image
92  // if (ImageIO::Load(argv[fup], source)!=0){
93  // BIASERR("error loading image "<<argv[1]);
94  // //return -2;
95  // return 0; // for Dart testing
96  // }
97 
98  // define an image with 3 channels
100  out.Init(width, height, 3);
101 
102  // instantiate ConvertBayerPattern class with correct storage type
104 
105  // demosaic image. you can choose the method for ConvertBayerPattern with the third parameter
106  converter.Convert(source,out, method,
107  //BAYER_DEMOSAIC_METHOD_AHD,
108  //ImageBase::CM_Bayer_BGGR);
109  //ImageBase::CM_Bayer_RGGB);
111 
112  if(source.IsProjValid()) {
113  out.SetProj(proj);
114  out.UpdateMetaData();
115  }
116  // write the image
117  cout<<"writing "<<argv[fup+1]<<endl;
118  if (ImageIO::Save(argv[fup+1], out)!=0){
119  cout<<"Error writing result!\n";
120  return -1; // for Dart testing
121  }
122 
123  return 0;
124 }
static bool LoadCamera(std::string *fileName, BIAS::Camera< dataType > &cam)
Definition: IOUtils.hh:315
int * AddParamEnum(const std::string &name, const std::string &help, const std::vector< std::string > &enums, const int deflt=0, const std::vector< int > *IDs=NULL, const char cmdshort=0, const int Group=GRP_NOSHOW)
Definition: Param.cpp:468
Wrapper class to dc1394 bayer conversion class.
BayerDemosaicMethod
methods for conversion from bayer to rgb
Definition: ImageConvert.hh:70
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
int SetProj(const Projection &Proj)
Definition: Camera.hh:106
static bool ParseCommandLineEvalHelp(Param &params, int argc, char *argv[])
parses the command line, adds parameter &quot;help&quot;
Definition: IOUtils.cpp:176
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.
Definition: ImageIO.cpp:725
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
Definition: Image.cpp:421
int UpdateMetaData()
copy P_ and co.
Definition: Camera.cpp:446
This class Param provides generic support for parameters.
Definition: Param.hh:231
bool IsProjValid() const
Definition: Camera.hh:221
invalid (not set) image format
Definition: ImageBase.hh:129
int Convert(Image< StorageType > &src, Image< StorageType > &dst, BayerDemosaicMethod method=BAYER_DEMOSAIC_METHOD_AHD, ImageBase::EColorModel bayer_pattern=ImageBase::CM_invalid)
converts image with bayerpattern to rgb.