tricalcdisp.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <fvutils/writers/jpeg.h>
00024 #include <fvutils/readers/fvraw.h>
00025 #include <fvutils/color/conversions.h>
00026
00027 #include <stereo/triclops.h>
00028
00029 #include <list>
00030 #include <string>
00031
00032 #include <sys/stat.h>
00033 #include <sys/types.h>
00034 #include <dirent.h>
00035 #include <unistd.h>
00036 #include <cstdlib>
00037
00038 using namespace std;
00039 using namespace fawkes;
00040
00041 int
00042 main(int argc, char **argv)
00043 {
00044
00045 if ( argc < 3 ) {
00046 printf("Usage: %s <image> <triclops_context>\n", argv[0]);
00047 exit(-1);
00048 }
00049
00050 const char *file = argv[1];
00051 const char *context_file = argv[2];
00052
00053 char *outfile;
00054 asprintf(&outfile, "%s.jpg", file);
00055
00056 JpegWriter *jpeg = new JpegWriter(outfile);
00057
00058 try {
00059 FvRawReader *fvraw = new FvRawReader(file);
00060
00061 unsigned int width = fvraw->pixel_width();
00062 unsigned int height = fvraw->pixel_height();
00063
00064 if ( fvraw->colorspace() != RAW16 ) {
00065 printf("Can only operate on RAW16 images!\n");
00066 delete jpeg;
00067 delete fvraw;
00068 return -1;
00069 }
00070
00071 printf("Calculating disparity for %s to %s\n", file, outfile);
00072 printf("Using Triclops context file %s\n", context_file);
00073
00074 unsigned char *raw16 = malloc_buffer(RAW16, width, height);
00075 unsigned char *yuv422_planar = malloc_buffer(YUV422_PLANAR, width, height);
00076
00077 TriclopsStereoProcessor *tsp = new TriclopsStereoProcessor(width, height, context_file);
00078
00079 fvraw->set_buffer(raw16);
00080 fvraw->read();
00081
00082 tsp->set_raw_buffer(raw16);
00083
00084 tsp->preprocess_stereo();
00085 tsp->calculate_disparity();
00086
00087 memcpy(yuv422_planar, tsp->disparity_buffer(), width * height);
00088 memset(yuv422_planar + width * height, 128, width * height);
00089
00090 jpeg->set_buffer(YUV422_PLANAR, yuv422_planar);
00091 jpeg->set_dimensions(width, height);
00092 jpeg->write();
00093
00094 delete jpeg;
00095 delete fvraw;
00096 free(raw16);
00097 free(yuv422_planar);
00098 delete tsp;
00099 free(outfile);
00100
00101 } catch (Exception &e) {
00102 e.print_trace();
00103 throw;
00104 }
00105 }