//============================================================================ // Name : retinademo.cpp // Author : Alexandre Benoit, benoit.alexandre.vision@gmail.com // Version : 0.1 // Copyright : LISTIC/GIPSA French Labs, july 2011 // Description : Gipsa/LISTIC Labs retina demo in C++, Ansi-style //============================================================================ #include #include #include "opencv2/bioinspired.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/videoio.hpp" #include "opencv2/highgui.hpp" #include "opencv2/core/ocl.hpp" const std::string keys = "{image | | Input from image file }" "{video | | Input from video file }" "{camera | 0 | Index of input camera. If image or video is not specified, camera 0 will be used }" "{log | | Activate retina log sampling }" "{ocl | | Use OpenCL acceleration if possible }" "{help | | Print help}"; int main(int argc, char* argv[]) { // welcome message std::cout<<"****************************************************"< It applies a spectral whithening (mid-frequency details enhancement)"< high frequency spatio-temporal noise reduction"< low frequency luminance to be reduced (luminance range compression)"< local logarithmic luminance compression allows details to be enhanced in low light conditions\n"< reports comments/remarks at benoit.alexandre.vision@gmail.com"< more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"< you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<("video")); else if(parser.has("image")) inputFrame = cv::imread(parser.get("image")); else videoCapture.open(parser.get("camera")); if (videoCapture.isOpened()) { videoCapture >> inputFrame; } if(inputFrame.empty()) { std::cout << "Failed to open media source\n"; return 0; } ////////////////////////////////////////////////////////////////////////////// // 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 = cv::bioinspired::Retina::create(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0); } else// -> else allocate "classical" retina : myRetina = cv::bioinspired::Retina::create(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"); myRetina->clearBuffers(); // declare retina output buffers cv::UMat retinaOutput_parvo; cv::UMat retinaOutput_magno; // processing loop with stop condition int64 totalTime = 0; int64 totalFrames = 0; while(true) { // if using video stream, then, grabbing a new frame, else, input remains the same if (videoCapture.isOpened()) videoCapture>>inputFrame; if(inputFrame.empty()) break; // run retina filter int64 frameTime = cv::getTickCount(); myRetina->run(inputFrame); // Retrieve and display retina output frameTime = cv::getTickCount() - frameTime; totalTime += frameTime; totalFrames++; 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); int key = cv::waitKey(5); if(key == 'q') break; } std::cout << "\nMean frame processing time: " << (totalTime / cv::getTickFrequency()) / totalFrames << " s" << std::endl; std::cout << "Retina demo end" << std::endl; } catch(const cv::Exception& e) { std::cerr<<"Error using Retina : "<