PTdecode/CImg-1.3.0/examples/use_cimgIPL.cpp

Mon, 03 Aug 2009 23:39:53 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 03 Aug 2009 23:39:53 +0100
changeset 10
604c205d9163
parent 5
1204ebf9340d
permissions
-rwxr-xr-x

add basic test routine for Ptouch library

     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.sourceforge.net )
     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 */
    44 #include <cv.h>
    45 #include <highgui.h>
    46 #include <math.h>
    48 #pragma comment(lib, "cv.lib")
    49 #pragma comment(lib, "cvaux.lib")
    50 #pragma comment(lib, "cxcore.lib")
    51 #pragma comment(lib, "highgui.lib")
    53 #define cimg_plugin1 "plugins\cimgIPL.h"
    54 #include "CImg.h"
    55 using namespace cimg_library;
    57 int main(int argc, char* argv[]) {
    58   int wid = 0;
    59   CImg<> cImg(argv[1]);
    60   cImg.display("cImg");
    61   IplImage* ipl;
    62   //ipl = cvLoadImage(argv[1], -1);
    63   ipl = cImg.get_IPL();
    65   IplImage *ipl8;
    66   IplImage *ipl16, *ipl32, *ipl64;
    67   IplImage *ipl16to8, *ipl32to8, *ipl64to8;
    68   cvNamedWindow("origin", wid++);
    69   cvNamedWindow("8bit_OK", wid++);
    70   cvNamedWindow("16bit", wid++);
    71   cvNamedWindow("32bit", wid++);
    72   cvNamedWindow("64bit", wid++);
    73   cvNamedWindow("16bitto8", wid++);
    74   cvNamedWindow("32bitto8", wid++);
    75   cvNamedWindow("64bitto8", wid++);
    77   cvShowImage("origin", ipl);
    79   ipl8 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_8U, ipl->nChannels);
    80   cvConvert(ipl, ipl8);
    82   ipl16 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_16U, ipl->nChannels);
    83   cvConvert(ipl, ipl16);
    85   ipl32 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_32F, ipl->nChannels);
    86   cvConvert(ipl, ipl32);
    88   ipl64 = cvCreateImage(cvGetSize(ipl), IPL_DEPTH_64F, ipl->nChannels);
    89   cvConvert(ipl, ipl64);
    91   cvShowImage("8bit_OK", ipl8);// this canbe show properly
    92   cvShowImage("16bit", ipl16);// maynot display properly, that's bug of cvShowImage
    93   cvShowImage("32bit", ipl32);// maynot display properly, that's bug of cvShowImage
    94   cvShowImage("64bit", ipl64);// maynot display properly, that's bug of cvShowImage
    96   // cvShowImage can only display IplImage with IPL_DEPTH_8X, proved by the following codes
    97   ipl16to8 = cvCreateImage(cvGetSize(ipl16), IPL_DEPTH_8U, ipl16->nChannels);
    98   cvConvert(ipl16, ipl16to8);
    99   ipl32to8 = cvCreateImage(cvGetSize(ipl32), IPL_DEPTH_8U, ipl32->nChannels);
   100   cvConvert(ipl32, ipl32to8);
   101   ipl64to8 = cvCreateImage(cvGetSize(ipl64), IPL_DEPTH_8U, ipl64->nChannels);
   102   cvConvert(ipl64, ipl64to8);
   103   cvShowImage("16bitto8", ipl16to8);    // diplay ok
   104   cvShowImage("32bitto8", ipl32to8);    // diplay ok
   105   cvShowImage("64bitto8", ipl64to8);    // diplay ok
   108   // now, we test ipl8->cImg, ipl16->cImg, ipl32->cImg, ipl64->cImg
   109   cImg.assign(ipl8);
   110   cImg.display("ipl8->cimg");
   111   cImg.assign(ipl16);
   112   cImg.display("ipl16->cimg");
   113   cImg.assign(ipl32);
   114   cImg.display("ipl32->cimg");
   115   cImg.assign(ipl64);
   116   cImg.display("ipl64->cimg");
   118   cvWaitKey(0);
   120   // test another construct
   121   CImg<unsigned char> testCImg1(ipl16);
   122   testCImg1.display("testCImg1");
   123   CImg<unsigned char> testCImg2(ipl32);
   124   testCImg2.display("testCImg2");
   125   CImg<unsigned char> testCImg3(ipl64);
   126   testCImg3.display("testCImg3");
   128   CImg<double> testCImg4(ipl16);
   129   testCImg4.display("testCImg4");
   130   CImg<double> testCImg5(ipl32);
   131   testCImg5.display("testCImg5");
   132   CImg<double> testCImg6(ipl64);
   133   testCImg6.display("testCImg6");
   135   cvReleaseImage(&ipl);
   136   cvReleaseImage(&ipl8);
   137   cvReleaseImage(&ipl16);
   138   cvReleaseImage(&ipl32);
   139   cvReleaseImage(&ipl64);
   140   cvReleaseImage(&ipl16to8);
   141   cvReleaseImage(&ipl32to8);
   142   cvReleaseImage(&ipl64to8);
   144   cvDestroyWindow("origin");
   145   cvDestroyWindow("8bit_OK");
   146   cvDestroyWindow("16bit");
   147   cvDestroyWindow("32bit");
   148   cvDestroyWindow("64bit");
   149   cvDestroyWindow("16bitto8");
   150   cvDestroyWindow("32bitto8");
   151   cvDestroyWindow("64bitto8");
   153   return 0;
   154 }