From b5bd86b2a7f75aa206c354c78a5c75ae942707aa Mon Sep 17 00:00:00 2001 From: alexandre benoit Date: Wed, 24 Oct 2012 12:20:59 +0200 Subject: [PATCH] added retina code tutorial --- .../cpp/tutorial_code/contrib/retina_tutorial.cpp | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 samples/cpp/tutorial_code/contrib/retina_tutorial.cpp 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..e1ee118 --- /dev/null +++ b/samples/cpp/tutorial_code/contrib/retina_tutorial.cpp @@ -0,0 +1,147 @@ +//============================================================================ +// 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 : "<