From: alexandre benoit Date: Wed, 24 Oct 2012 10:20:59 +0000 (+0200) Subject: added retina code tutorial X-Git-Tag: accepted/2.0/20130307.220821~344^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3fb90abb767e46f84e9902468c9e53a3e94a6a4f;p=profile%2Fivi%2Fopencv.git added retina code tutorial --- diff --git a/samples/cpp/tutorial_code/contrib/retina_tutorial.cpp b/samples/cpp/tutorial_code/contrib/retina_tutorial.cpp new file mode 100644 index 0000000..3fc9a09 --- /dev/null +++ b/samples/cpp/tutorial_code/contrib/retina_tutorial.cpp @@ -0,0 +1,146 @@ +//============================================================================ +// Name : retina_tutorial.cpp +// Author : Alexandre Benoit, benoit.alexandre.vision@gmail.com +// Version : 0.1 +// Copyright : LISTIC/GIPSA French Labs, july 2012 +// Description : Gipsa/LISTIC Labs retina demo in C++, Ansi-style +//============================================================================ + +#include +#include + +#include "opencv2/opencv.hpp" + +static void help(std::string errorMessage) +{ + std::cout<<"Program init error : "< you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<= 3) + { + std::cout<<"RetinaDemo: processing image "<>inputFrame; + }else + { + // bad command parameter + help("bad command parameter"); + return -1; + } + + if (inputFrame.empty()) + { + help("Input media could not be loaded, aborting"); + return -1; + } + + + ////////////////////////////////////////////////////////////////////////////// + // Program start in a try/catch safety context (Retina may throw errors) + try + { + // create a retina instance with default parameters setup, uncomment the initialisation you wanna test + cv::Ptr myRetina; + + // if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision) + if (useLogSampling) + { + myRetina = new cv::Retina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0); + } + else// -> else allocate "classical" retina : + myRetina = new cv::Retina(inputFrame.size()); + + // save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup" + myRetina->write("RetinaDefaultParameters.xml"); + + // load parameters if file exists + myRetina->setup("RetinaSpecificParameters.xml"); + + // reset all retina buffers (imagine you close your eyes for a long time) + myRetina->clearBuffers(); + + // declare retina output buffers + cv::Mat retinaOutput_parvo; + cv::Mat retinaOutput_magno; + + // processing loop with no stop condition + while(true) + { + // if using video stream, then, grabbing a new frame, else, input remains the same + if (videoCapture.isOpened()) + videoCapture>>inputFrame; + + // run retina filter on the loaded input frame + myRetina->run(inputFrame); + // Retrieve and display retina output + myRetina->getParvo(retinaOutput_parvo); + myRetina->getMagno(retinaOutput_magno); + cv::imshow("retina input", inputFrame); + cv::imshow("Retina Parvo", retinaOutput_parvo); + cv::imshow("Retina Magno", retinaOutput_magno); + cv::waitKey(10); + } + }catch(cv::Exception e) + { + std::cerr<<"Error using Retina : "<