Wed, 05 Aug 2009 15:00:54 +0100
small changes to hexdump code to stop a gcc warning on platforms where sizeof(int) != sizeof(int*) e.g. x86_64
philpem@5 | 1 | /* |
philpem@5 | 2 | # |
philpem@5 | 3 | # File : use_cimgIPL.cpp |
philpem@5 | 4 | # ( C++ source file ) |
philpem@5 | 5 | # |
philpem@5 | 6 | # Description : Example of use for the CImg plugin 'plugins/cimgIPL.h'. |
philpem@5 | 7 | # This file is a part of the CImg Library project. |
philpem@5 | 8 | # ( http://cimg.sourceforge.net ) |
philpem@5 | 9 | # |
philpem@5 | 10 | # Copyright : newleft (haibo.zheng@gmail.com) |
philpem@5 | 11 | # newleftist@hotmail.com |
philpem@5 | 12 | # |
philpem@5 | 13 | # License : CeCILL v2.0 |
philpem@5 | 14 | # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) |
philpem@5 | 15 | # |
philpem@5 | 16 | # This software is governed by the CeCILL license under French law and |
philpem@5 | 17 | # abiding by the rules of distribution of free software. You can use, |
philpem@5 | 18 | # modify and/ or redistribute the software under the terms of the CeCILL |
philpem@5 | 19 | # license as circulated by CEA, CNRS and INRIA at the following URL |
philpem@5 | 20 | # "http://www.cecill.info". |
philpem@5 | 21 | # |
philpem@5 | 22 | # As a counterpart to the access to the source code and rights to copy, |
philpem@5 | 23 | # modify and redistribute granted by the license, users are provided only |
philpem@5 | 24 | # with a limited warranty and the software's author, the holder of the |
philpem@5 | 25 | # economic rights, and the successive licensors have only limited |
philpem@5 | 26 | # liability. |
philpem@5 | 27 | # |
philpem@5 | 28 | # In this respect, the user's attention is drawn to the risks associated |
philpem@5 | 29 | # with loading, using, modifying and/or developing or reproducing the |
philpem@5 | 30 | # software by the user in light of its specific status of free software, |
philpem@5 | 31 | # that may mean that it is complicated to manipulate, and that also |
philpem@5 | 32 | # therefore means that it is reserved for developers and experienced |
philpem@5 | 33 | # professionals having in-depth computer knowledge. Users are therefore |
philpem@5 | 34 | # encouraged to load and test the software's suitability as regards their |
philpem@5 | 35 | # requirements in conditions enabling the security of their systems and/or |
philpem@5 | 36 | # data to be ensured and, more generally, to use and operate it in the |
philpem@5 | 37 | # same conditions as regards security. |
philpem@5 | 38 | # |
philpem@5 | 39 | # The fact that you are presently reading this means that you have had |
philpem@5 | 40 | # knowledge of the CeCILL license and that you accept its terms. |
philpem@5 | 41 | # |
philpem@5 | 42 | */ |
philpem@5 | 43 | |
philpem@5 | 44 | #include <cv.h> |
philpem@5 | 45 | #include <highgui.h> |
philpem@5 | 46 | #include <math.h> |
philpem@5 | 47 | |
philpem@5 | 48 | #pragma comment(lib, "cv.lib") |
philpem@5 | 49 | #pragma comment(lib, "cvaux.lib") |
philpem@5 | 50 | #pragma comment(lib, "cxcore.lib") |
philpem@5 | 51 | #pragma comment(lib, "highgui.lib") |
philpem@5 | 52 | |
philpem@5 | 53 | #define cimg_plugin1 "plugins\cimgIPL.h" |
philpem@5 | 54 | #include "CImg.h" |
philpem@5 | 55 | using namespace cimg_library; |
philpem@5 | 56 | |
philpem@5 | 57 | int main(int argc, char* argv[]) { |
philpem@5 | 58 | int wid = 0; |
philpem@5 | 59 | CImg<> cImg(argv[1]); |
philpem@5 | 60 | cImg.display("cImg"); |
philpem@5 | 61 | IplImage* ipl; |
philpem@5 | 62 | //ipl = cvLoadImage(argv[1], -1); |
philpem@5 | 63 | ipl = cImg.get_IPL(); |
philpem@5 | 64 | |
philpem@5 | 65 | IplImage *ipl8; |
philpem@5 | 66 | IplImage *ipl16, *ipl32, *ipl64; |
philpem@5 | 67 | IplImage *ipl16to8, *ipl32to8, *ipl64to8; |
philpem@5 | 68 | cvNamedWindow("origin", wid++); |
philpem@5 | 69 | cvNamedWindow("8bit_OK", wid++); |
philpem@5 | 70 | cvNamedWindow("16bit", wid++); |
philpem@5 | 71 | cvNamedWindow("32bit", wid++); |
philpem@5 | 72 | cvNamedWindow("64bit", wid++); |
philpem@5 | 73 | cvNamedWindow("16bitto8", wid++); |
philpem@5 | 74 | cvNamedWindow("32bitto8", wid++); |
philpem@5 | 75 | cvNamedWindow("64bitto8", wid++); |
philpem@5 | 76 | |
philpem@5 | 77 | cvShowImage("origin", ipl); |
philpem@5 | 78 | |
philpem@5 | 79 | ipl8 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_8U, ipl->nChannels); |
philpem@5 | 80 | cvConvert(ipl, ipl8); |
philpem@5 | 81 | |
philpem@5 | 82 | ipl16 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_16U, ipl->nChannels); |
philpem@5 | 83 | cvConvert(ipl, ipl16); |
philpem@5 | 84 | |
philpem@5 | 85 | ipl32 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_32F, ipl->nChannels); |
philpem@5 | 86 | cvConvert(ipl, ipl32); |
philpem@5 | 87 | |
philpem@5 | 88 | ipl64 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_64F, ipl->nChannels); |
philpem@5 | 89 | cvConvert(ipl, ipl64); |
philpem@5 | 90 | |
philpem@5 | 91 | cvShowImage("8bit_OK", ipl8);// this canbe show properly |
philpem@5 | 92 | cvShowImage("16bit", ipl16);// maynot display properly, that's bug of cvShowImage |
philpem@5 | 93 | cvShowImage("32bit", ipl32);// maynot display properly, that's bug of cvShowImage |
philpem@5 | 94 | cvShowImage("64bit", ipl64);// maynot display properly, that's bug of cvShowImage |
philpem@5 | 95 | |
philpem@5 | 96 | // cvShowImage can only display IplImage with IPL_DEPTH_8X, proved by the following codes |
philpem@5 | 97 | ipl16to8 = cvCreateImage(cvGetSize(ipl16), IPL_DEPTH_8U, ipl16->nChannels); |
philpem@5 | 98 | cvConvert(ipl16, ipl16to8); |
philpem@5 | 99 | ipl32to8 = cvCreateImage(cvGetSize(ipl32), IPL_DEPTH_8U, ipl32->nChannels); |
philpem@5 | 100 | cvConvert(ipl32, ipl32to8); |
philpem@5 | 101 | ipl64to8 = cvCreateImage(cvGetSize(ipl64), IPL_DEPTH_8U, ipl64->nChannels); |
philpem@5 | 102 | cvConvert(ipl64, ipl64to8); |
philpem@5 | 103 | cvShowImage("16bitto8", ipl16to8); // diplay ok |
philpem@5 | 104 | cvShowImage("32bitto8", ipl32to8); // diplay ok |
philpem@5 | 105 | cvShowImage("64bitto8", ipl64to8); // diplay ok |
philpem@5 | 106 | |
philpem@5 | 107 | |
philpem@5 | 108 | // now, we test ipl8->cImg, ipl16->cImg, ipl32->cImg, ipl64->cImg |
philpem@5 | 109 | cImg.assign(ipl8); |
philpem@5 | 110 | cImg.display("ipl8->cimg"); |
philpem@5 | 111 | cImg.assign(ipl16); |
philpem@5 | 112 | cImg.display("ipl16->cimg"); |
philpem@5 | 113 | cImg.assign(ipl32); |
philpem@5 | 114 | cImg.display("ipl32->cimg"); |
philpem@5 | 115 | cImg.assign(ipl64); |
philpem@5 | 116 | cImg.display("ipl64->cimg"); |
philpem@5 | 117 | |
philpem@5 | 118 | cvWaitKey(0); |
philpem@5 | 119 | |
philpem@5 | 120 | // test another construct |
philpem@5 | 121 | CImg<unsigned char> testCImg1(ipl16); |
philpem@5 | 122 | testCImg1.display("testCImg1"); |
philpem@5 | 123 | CImg<unsigned char> testCImg2(ipl32); |
philpem@5 | 124 | testCImg2.display("testCImg2"); |
philpem@5 | 125 | CImg<unsigned char> testCImg3(ipl64); |
philpem@5 | 126 | testCImg3.display("testCImg3"); |
philpem@5 | 127 | |
philpem@5 | 128 | CImg<double> testCImg4(ipl16); |
philpem@5 | 129 | testCImg4.display("testCImg4"); |
philpem@5 | 130 | CImg<double> testCImg5(ipl32); |
philpem@5 | 131 | testCImg5.display("testCImg5"); |
philpem@5 | 132 | CImg<double> testCImg6(ipl64); |
philpem@5 | 133 | testCImg6.display("testCImg6"); |
philpem@5 | 134 | |
philpem@5 | 135 | cvReleaseImage(&ipl); |
philpem@5 | 136 | cvReleaseImage(&ipl8); |
philpem@5 | 137 | cvReleaseImage(&ipl16); |
philpem@5 | 138 | cvReleaseImage(&ipl32); |
philpem@5 | 139 | cvReleaseImage(&ipl64); |
philpem@5 | 140 | cvReleaseImage(&ipl16to8); |
philpem@5 | 141 | cvReleaseImage(&ipl32to8); |
philpem@5 | 142 | cvReleaseImage(&ipl64to8); |
philpem@5 | 143 | |
philpem@5 | 144 | cvDestroyWindow("origin"); |
philpem@5 | 145 | cvDestroyWindow("8bit_OK"); |
philpem@5 | 146 | cvDestroyWindow("16bit"); |
philpem@5 | 147 | cvDestroyWindow("32bit"); |
philpem@5 | 148 | cvDestroyWindow("64bit"); |
philpem@5 | 149 | cvDestroyWindow("16bitto8"); |
philpem@5 | 150 | cvDestroyWindow("32bitto8"); |
philpem@5 | 151 | cvDestroyWindow("64bitto8"); |
philpem@5 | 152 | |
philpem@5 | 153 | return 0; |
philpem@5 | 154 | } |