00001 /*!@file Ice/IceImageUtils.H A set of utilities for using iNVT Images 00002 with Ice*/ 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Randolph Voorhies <voorhies@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Ice/IceImageUtils.H $ 00035 // $Id: IceImageUtils.H$ 00036 // 00037 #ifdef HAVE_OPENCV_CV_H 00038 #include "Image/OpenCVUtil.H" 00039 #endif 00040 00041 #ifndef ICEOPENCVUTILS_H 00042 #define ICEOPENCVUTILS_H 00043 00044 #include <Ice/Ice.h> 00045 #include "Ice/ImageIce.ice.H" 00046 #include <jpeglib.h> 00047 #include "Util/log.H" //For LFATAL 00048 00049 using namespace std; 00050 using namespace ImageIceMod; 00051 00052 00053 00054 #ifdef HAVE_OPENCV_CV_H 00055 //Convert an OpenCV Image to a datatype acceptable by Ice 00056 ImageIce Ipl2Ice(const IplImage* img) 00057 { 00058 00059 if (img->depth != IPL_DEPTH_8U) 00060 LFATAL("IplImage must have depth==IPL_DEPTH_8U" 00061 "for conversion to IceImage/Image<PixRGB<byte>>"); 00062 00063 if (img->nChannels != 3) 00064 LFATAL("IplImage must have nChannels==3" 00065 "for conversion to IceImage/Image<PixRGB<byte>>"); 00066 00067 if (img->dataOrder != 0) 00068 LFATAL("IplImage must have dataOrder==0 (interleaved)" 00069 "for conversion to IceImage/Image<PixRGB<byte>>"); 00070 00071 int size = (img->nChannels) * (img->width)* (img->height); 00072 ImageIce output; 00073 output.width = img->width; 00074 output.height= img->height; 00075 output.pixSize = img->nChannels; 00076 LINFO("ipl width %d ipl height %d size %d",output.width,output.height,size); 00077 unsigned char* arrayPtr = (unsigned char*)img->imageData; 00078 output.data.resize(size); 00079 00080 std::copy(arrayPtr, arrayPtr+size,output.data.begin()); 00081 00082 return output; 00083 00084 00085 } 00086 //Convert an Ice image to an OpenCV Image 00087 //-- Warning: there is some nasy and potentially dangerous manual marshalling going on here -- 00088 //-- We should look for a better solution in the future. -- 00089 template <class T> 00090 IplImage* Ice2Ipl(const ImageIce &input) { 00091 IplImage* ret_img = cvCreateImageHeader(cvSize(input.width,input.height),IPL_DEPTH_8U, 3); 00092 ret_img->imageData = (char*) input.data; 00093 return ret_img; 00094 } 00095 #endif 00096 00097 #endif