Basic Image AlgorithmS Library 2.8.0

ExampleIplWrapOpenCV.cpp

howto use the wrapper to use a BIAS imaeg with OpenCV image algorithms

Author:
Woetzel
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).

Copyright (C) 2003-2009    (see file CONTACT for details)
  Multimediale Systeme der Informationsverarbeitung
  Institut fuer Informatik
  Christian-Albrechts-Universitaet Kiel


BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/**
   @example ExampleIplWrapOpenCV.cpp
   @relates WrapBias2Ipl
   @brief  howto use the wrapper to use a BIAS imaeg with OpenCV image algorithms
   @ingroup g_examples
   @author Woetzel
*/
//#include <Base/Common/LeakChecking.h>

#include <iostream>
#include <string>

// BIAS
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/WrapBias2Ipl.hh>


#include <bias_config.h>
#ifndef BIAS_HAVE_OPENCV
#  error You need to enable OPENCV to compile this file. Please reconfigure BIAS with USE_OPENCV
#endif
#include "cv.h"
//#include "highgui.h"

using namespace std;
using namespace BIAS;

int main( int argc, char** argv ){
    bool darttest=false;
    if (argc>=2) if (strcmp(argv[1],"-darttest")==0) {
        darttest=true;
        std::cout<<"started dart test: "<<argv[0]<<std::endl;
    }

    // load a BIAS image to work with:
    string filename( BIAS_TESTS_DATA "r4.jpg" );
    if (!darttest && (argc>1)) filename=argv[1];
    BIAS::Image<unsigned char> img;
    if (BIAS::ImageIO::Load(filename, img) !=0){
        cout<<"error loading image "<<filename<<endl;
        return -1;
    };
    cout<<"loaded image with dim: "<<img.GetWidth()<<"x"<<img.GetHeight()<<endl;

    // wrapper to use BIAS image in OpenCV:
    WrapBias2Ipl wrap(&img);

    // work:  draw something:
    {
        cvLine( wrap.p_imgIpl,
            cvPoint(-20,0),
            cvPoint(200,200),
            cvScalar(255, 0, 0),
            1, 8, 0 );
        cvEllipse( wrap.p_imgIpl,
            cvPoint(50,100),
            cvSize(20,40),
            20,
            0, 270,
            cvScalar(0,255,0) );

        string msg("Hello BIAS world! 1234567890");
        int linetype=CV_AA; // antialiased
        CvFont font1, font2, font3;
        cvInitFont( &font1, CV_FONT_HERSHEY_SIMPLEX,
            1.0, 1.0,
            0, 1, linetype);
        cvInitFont( &font2, CV_FONT_HERSHEY_PLAIN,
            1.0, 1.0,
            0, 1, 0);
        cvInitFont( &font3,
            CV_FONT_HERSHEY_COMPLEX, // font name
            1.0, // hscale
            1.0, // vscale
            0,   // shear
            2,   // thickness
            linetype
            );
        cvPutText( wrap.p_imgIpl, msg.c_str(),
            cvPoint(100,50), &font1, cvScalar(255,0,0) );
        cvPutText( wrap.p_imgIpl, msg.c_str(),
            cvPoint(100,100), &font2, cvScalar(0,255,0) );
        cvPutText( wrap.p_imgIpl, msg.c_str(),
            cvPoint(100,150), &font3, cvScalar(0,0,255) );
    }

    // display using CV routines
    // color channel order may be wrong! (use fixed highgui)
    // avoid gui display on darttest because it doesn't work on Linux without login.
    if (!darttest) wrap.Display(true, 2000);

    // output to disk:
    //cvSaveImage("out_wrapIPL.jpg", wrap.p_imgIpl);
    BIAS::ImageIO::Save("out_ExampleIplWrapOpenCV.jpg", *wrap.p_imgBias, BIAS::ImageIO::FF_jpg);

    return 0;
}
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends