Alida-C++ 0.1

demo/providers/OpenCVImageDataIO.cc

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Alida-C++ library, an
00003  *
00004  * Advanced Library for Integrated Development of Data Analysis Applications.
00005  *
00006  * Copyright (C) 2012 - @YEAR@
00007  *
00008  * This program is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  *
00021  * Fore more information on Alida, visit
00022  *
00023  *    http://www.informatik.uni-halle.de/alida/
00024  *
00025  */
00026 
00027 /*
00028  * Most recent change(s):
00029  *
00030  * $Rev: 111 $
00031  * $Date: 2012-03-12 16:00:37 +0100 (Mo, 12 Mrz 2012) $
00032  * $Author: posch $
00033  *
00034  */
00035 
00036 #ifdef OPENCV_SUPPORT
00037 
00038 #include <math.h>
00039 #include <stdio.h>
00040 
00041 #include <fstream>
00042 #include <iostream>
00043 #include <string>
00044 
00045 #include <opencv/cv.h>
00046 #include <opencv/highgui.h>
00047 
00048 #include "dataio/ALDDataIOManagerCmdline.h"
00049 #include "demo/providers/OpenCVImageDataIO.h"
00050 
00051 using namespace std;
00052 
00053 using namespace Alida;
00054 
00059 REGISTER_PROVIDER(OpenCVImageDataIO,IplImage,Cmdline);
00060 
00069 void* OpenCVImageDataIO::readData(string input, string type) const
00070 {
00071     IplImage *img = cvLoadImage(input.c_str(),-1);
00072     return img;
00073 }
00074 
00086 string
00087 OpenCVImageDataIO::writeData(
00088                     std::string format, std::string type, void *data) const
00089 {
00090     string outString;
00091     if (data == NULL) {
00092         cerr << "Image is NULL, nothing to write..." << endl;
00093         return outString;
00094     }
00095     IplImage *img = (IplImage*)(data);
00096 
00097     if (format == "-") {
00098         // display the image on screen
00099         cvNamedWindow("Result Window",1);
00100         cvShowImage("Result Window",img);
00101         while(1) {
00102             if (cvWaitKey( 100) == 27)
00103                 break;
00104         }
00105         cvDestroyWindow("Result Window");
00106     }
00107     else {
00108         // save to file
00109         cvSaveImage(format.c_str(),img);
00110     }
00111     return outString;
00112 }
00113 
00114 #endif /* OPENCV_SUPPORT */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines