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