1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/PTdecode/CImg-1.3.0/examples/use_cimgIPL.cpp Mon Aug 03 14:09:20 2009 +0100 1.3 @@ -0,0 +1,154 @@ 1.4 +/* 1.5 +# 1.6 +# File : use_cimgIPL.cpp 1.7 +# ( C++ source file ) 1.8 +# 1.9 +# Description : Example of use for the CImg plugin 'plugins/cimgIPL.h'. 1.10 +# This file is a part of the CImg Library project. 1.11 +# ( http://cimg.sourceforge.net ) 1.12 +# 1.13 +# Copyright : newleft (haibo.zheng@gmail.com) 1.14 +# newleftist@hotmail.com 1.15 +# 1.16 +# License : CeCILL v2.0 1.17 +# ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.18 +# 1.19 +# This software is governed by the CeCILL license under French law and 1.20 +# abiding by the rules of distribution of free software. You can use, 1.21 +# modify and/ or redistribute the software under the terms of the CeCILL 1.22 +# license as circulated by CEA, CNRS and INRIA at the following URL 1.23 +# "http://www.cecill.info". 1.24 +# 1.25 +# As a counterpart to the access to the source code and rights to copy, 1.26 +# modify and redistribute granted by the license, users are provided only 1.27 +# with a limited warranty and the software's author, the holder of the 1.28 +# economic rights, and the successive licensors have only limited 1.29 +# liability. 1.30 +# 1.31 +# In this respect, the user's attention is drawn to the risks associated 1.32 +# with loading, using, modifying and/or developing or reproducing the 1.33 +# software by the user in light of its specific status of free software, 1.34 +# that may mean that it is complicated to manipulate, and that also 1.35 +# therefore means that it is reserved for developers and experienced 1.36 +# professionals having in-depth computer knowledge. Users are therefore 1.37 +# encouraged to load and test the software's suitability as regards their 1.38 +# requirements in conditions enabling the security of their systems and/or 1.39 +# data to be ensured and, more generally, to use and operate it in the 1.40 +# same conditions as regards security. 1.41 +# 1.42 +# The fact that you are presently reading this means that you have had 1.43 +# knowledge of the CeCILL license and that you accept its terms. 1.44 +# 1.45 +*/ 1.46 + 1.47 +#include <cv.h> 1.48 +#include <highgui.h> 1.49 +#include <math.h> 1.50 + 1.51 +#pragma comment(lib, "cv.lib") 1.52 +#pragma comment(lib, "cvaux.lib") 1.53 +#pragma comment(lib, "cxcore.lib") 1.54 +#pragma comment(lib, "highgui.lib") 1.55 + 1.56 +#define cimg_plugin1 "plugins\cimgIPL.h" 1.57 +#include "CImg.h" 1.58 +using namespace cimg_library; 1.59 + 1.60 +int main(int argc, char* argv[]) { 1.61 + int wid = 0; 1.62 + CImg<> cImg(argv[1]); 1.63 + cImg.display("cImg"); 1.64 + IplImage* ipl; 1.65 + //ipl = cvLoadImage(argv[1], -1); 1.66 + ipl = cImg.get_IPL(); 1.67 + 1.68 + IplImage *ipl8; 1.69 + IplImage *ipl16, *ipl32, *ipl64; 1.70 + IplImage *ipl16to8, *ipl32to8, *ipl64to8; 1.71 + cvNamedWindow("origin", wid++); 1.72 + cvNamedWindow("8bit_OK", wid++); 1.73 + cvNamedWindow("16bit", wid++); 1.74 + cvNamedWindow("32bit", wid++); 1.75 + cvNamedWindow("64bit", wid++); 1.76 + cvNamedWindow("16bitto8", wid++); 1.77 + cvNamedWindow("32bitto8", wid++); 1.78 + cvNamedWindow("64bitto8", wid++); 1.79 + 1.80 + cvShowImage("origin", ipl); 1.81 + 1.82 + ipl8 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_8U, ipl->nChannels); 1.83 + cvConvert(ipl, ipl8); 1.84 + 1.85 + ipl16 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_16U, ipl->nChannels); 1.86 + cvConvert(ipl, ipl16); 1.87 + 1.88 + ipl32 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_32F, ipl->nChannels); 1.89 + cvConvert(ipl, ipl32); 1.90 + 1.91 + ipl64 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_64F, ipl->nChannels); 1.92 + cvConvert(ipl, ipl64); 1.93 + 1.94 + cvShowImage("8bit_OK", ipl8);// this canbe show properly 1.95 + cvShowImage("16bit", ipl16);// maynot display properly, that's bug of cvShowImage 1.96 + cvShowImage("32bit", ipl32);// maynot display properly, that's bug of cvShowImage 1.97 + cvShowImage("64bit", ipl64);// maynot display properly, that's bug of cvShowImage 1.98 + 1.99 + // cvShowImage can only display IplImage with IPL_DEPTH_8X, proved by the following codes 1.100 + ipl16to8 = cvCreateImage(cvGetSize(ipl16), IPL_DEPTH_8U, ipl16->nChannels); 1.101 + cvConvert(ipl16, ipl16to8); 1.102 + ipl32to8 = cvCreateImage(cvGetSize(ipl32), IPL_DEPTH_8U, ipl32->nChannels); 1.103 + cvConvert(ipl32, ipl32to8); 1.104 + ipl64to8 = cvCreateImage(cvGetSize(ipl64), IPL_DEPTH_8U, ipl64->nChannels); 1.105 + cvConvert(ipl64, ipl64to8); 1.106 + cvShowImage("16bitto8", ipl16to8); // diplay ok 1.107 + cvShowImage("32bitto8", ipl32to8); // diplay ok 1.108 + cvShowImage("64bitto8", ipl64to8); // diplay ok 1.109 + 1.110 + 1.111 + // now, we test ipl8->cImg, ipl16->cImg, ipl32->cImg, ipl64->cImg 1.112 + cImg.assign(ipl8); 1.113 + cImg.display("ipl8->cimg"); 1.114 + cImg.assign(ipl16); 1.115 + cImg.display("ipl16->cimg"); 1.116 + cImg.assign(ipl32); 1.117 + cImg.display("ipl32->cimg"); 1.118 + cImg.assign(ipl64); 1.119 + cImg.display("ipl64->cimg"); 1.120 + 1.121 + cvWaitKey(0); 1.122 + 1.123 + // test another construct 1.124 + CImg<unsigned char> testCImg1(ipl16); 1.125 + testCImg1.display("testCImg1"); 1.126 + CImg<unsigned char> testCImg2(ipl32); 1.127 + testCImg2.display("testCImg2"); 1.128 + CImg<unsigned char> testCImg3(ipl64); 1.129 + testCImg3.display("testCImg3"); 1.130 + 1.131 + CImg<double> testCImg4(ipl16); 1.132 + testCImg4.display("testCImg4"); 1.133 + CImg<double> testCImg5(ipl32); 1.134 + testCImg5.display("testCImg5"); 1.135 + CImg<double> testCImg6(ipl64); 1.136 + testCImg6.display("testCImg6"); 1.137 + 1.138 + cvReleaseImage(&ipl); 1.139 + cvReleaseImage(&ipl8); 1.140 + cvReleaseImage(&ipl16); 1.141 + cvReleaseImage(&ipl32); 1.142 + cvReleaseImage(&ipl64); 1.143 + cvReleaseImage(&ipl16to8); 1.144 + cvReleaseImage(&ipl32to8); 1.145 + cvReleaseImage(&ipl64to8); 1.146 + 1.147 + cvDestroyWindow("origin"); 1.148 + cvDestroyWindow("8bit_OK"); 1.149 + cvDestroyWindow("16bit"); 1.150 + cvDestroyWindow("32bit"); 1.151 + cvDestroyWindow("64bit"); 1.152 + cvDestroyWindow("16bitto8"); 1.153 + cvDestroyWindow("32bitto8"); 1.154 + cvDestroyWindow("64bitto8"); 1.155 + 1.156 + return 0; 1.157 +}