From: alexandre benoit Date: Wed, 24 Oct 2012 10:20:59 +0000 (+0200) Subject: added retina code tutorial X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3904^2~14^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5bd86b2a7f75aa206c354c78a5c75ae942707aa;p=platform%2Fupstream%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..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 : "<