Fawkes API  Fawkes Development Version
tricalcdisp.cpp
1 
2 /***************************************************************************
3  * calcdisp.cpp - Calculate disparities for the given images
4  *
5  * Created: Mon Oct 08 13:42:01 2007
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program 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 Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <fvutils/writers/jpeg.h>
24 #include <fvutils/readers/fvraw.h>
25 #include <fvutils/color/conversions.h>
26 
27 #include <fvstereo/triclops.h>
28 
29 #include <list>
30 #include <string>
31 
32 #include <sys/stat.h>
33 #include <sys/types.h>
34 #include <dirent.h>
35 #include <unistd.h>
36 #include <cstdlib>
37 
38 using namespace std;
39 using namespace fawkes;
40 using namespace firevision;
41 
42 int
43 main(int argc, char **argv)
44 {
45 
46  if ( argc < 3 ) {
47  printf("Usage: %s <image> <triclops_context>\n", argv[0]);
48  exit(-1);
49  }
50 
51  const char *file = argv[1];
52  const char *context_file = argv[2];
53 
54  char *outfile;
55  asprintf(&outfile, "%s.jpg", file);
56 
57  JpegWriter *jpeg = new JpegWriter(outfile);
58 
59  try {
60  FvRawReader *fvraw = new FvRawReader(file);
61 
62  unsigned int width = fvraw->pixel_width();
63  unsigned int height = fvraw->pixel_height();
64 
65  if ( fvraw->colorspace() != RAW16 ) {
66  printf("Can only operate on RAW16 images!\n");
67  delete jpeg;
68  delete fvraw;
69  return -1;
70  }
71 
72  printf("Calculating disparity for %s to %s\n", file, outfile);
73  printf("Using Triclops context file %s\n", context_file);
74 
75  unsigned char *raw16 = malloc_buffer(RAW16, width, height);
76  unsigned char *yuv422_planar = malloc_buffer(YUV422_PLANAR, width, height);
77 
78  TriclopsStereoProcessor *tsp = new TriclopsStereoProcessor(width, height, context_file);
79 
80  fvraw->set_buffer(raw16);
81  fvraw->read();
82 
83  tsp->set_raw_buffer(raw16);
84 
85  tsp->preprocess_stereo();
86  tsp->calculate_disparity();
87 
88  memcpy(yuv422_planar, tsp->disparity_buffer(), width * height);
89  memset(yuv422_planar + width * height, 128, width * height);
90 
91  jpeg->set_buffer(YUV422_PLANAR, yuv422_planar);
92  jpeg->set_dimensions(width, height);
93  jpeg->write();
94 
95  delete jpeg;
96  delete fvraw;
97  free(raw16);
98  free(yuv422_planar);
99  delete tsp;
100  free(outfile);
101 
102  } catch (Exception &e) {
103  e.print_trace();
104  throw;
105  }
106 }
virtual void set_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer.
Definition: jpeg.cpp:82
virtual void set_buffer(unsigned char *yuv422planar_buffer)
Set buffer that the read image should be written to.
Definition: fvraw.cpp:81
Fawkes library namespace.
STL namespace.
virtual void read()
Read data from file.
Definition: fvraw.cpp:121
virtual unsigned char * disparity_buffer()
Get the disparity image buffer.
Definition: triclops.cpp:664
virtual void write()
Write to file.
Definition: jpeg.cpp:93
Base class for exceptions in Fawkes.
Definition: exception.h:36
JPEG file writer.
Definition: jpeg.h:36
virtual unsigned int pixel_width()
Get width of read image in pixels.
Definition: fvraw.cpp:99
Stereo processing using PGR Triclops SDK.
Definition: triclops.h:40
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:619
virtual colorspace_t colorspace()
Get colorspace from the just read image.
Definition: fvraw.cpp:88
virtual void calculate_disparity(ROI *roi=0)
Caculate disparity images.
Definition: triclops.cpp:583
virtual void set_raw_buffer(unsigned char *raw16_buffer)
Set raw buffer.
Definition: triclops.cpp:265
virtual unsigned int pixel_height()
Get height of read image in pixels.
Definition: fvraw.cpp:110
virtual void set_dimensions(unsigned int width, unsigned int height)
Set dimensions of image in pixels.
Definition: writer.cpp:132
virtual void preprocess_stereo()
Do any pre-processing needed.
Definition: triclops.cpp:558
FvRaw image reader implementation.
Definition: fvraw.h:37