Skip to content

Commit 8dc1920

Browse files
committed
bioinspired: cleanup in samples
1 parent ec6ab8c commit 8dc1920

File tree

2 files changed

+53
-172
lines changed

2 files changed

+53
-172
lines changed

modules/bioinspired/samples/basicRetina.cpp

Lines changed: 0 additions & 91 deletions
This file was deleted.

modules/bioinspired/samples/retinaDemo.cpp

Lines changed: 53 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,66 @@
1313
#include "opencv2/imgcodecs.hpp"
1414
#include "opencv2/videoio.hpp"
1515
#include "opencv2/highgui.hpp"
16+
#include "opencv2/core/ocl.hpp"
1617

17-
static void help(std::string errorMessage)
18-
{
19-
std::cout<<"Program init error : "<<errorMessage<<std::endl;
20-
std::cout<<"\nProgram call procedure : retinaDemo [processing mode] [Optional : media target] [Optional LAST parameter: \"log\" to activate retina log sampling]"<<std::endl;
21-
std::cout<<"\t[processing mode] :"<<std::endl;
22-
std::cout<<"\t -image : for still image processing"<<std::endl;
23-
std::cout<<"\t -video : for video stream processing"<<std::endl;
24-
std::cout<<"\t[Optional : media target] :"<<std::endl;
25-
std::cout<<"\t if processing an image or video file, then, specify the path and filename of the target to process"<<std::endl;
26-
std::cout<<"\t leave empty if processing video stream coming from a connected video device"<<std::endl;
27-
std::cout<<"\t[Optional : activate retina log sampling] : an optional last parameter can be specified for retina spatial log sampling"<<std::endl;
28-
std::cout<<"\t set \"log\" without quotes to activate this sampling, output frame size will be divided by 4"<<std::endl;
29-
std::cout<<"\nExamples:"<<std::endl;
30-
std::cout<<"\t-Image processing : ./retinaDemo -image lena.jpg"<<std::endl;
31-
std::cout<<"\t-Image processing with log sampling : ./retinaDemo -image lena.jpg log"<<std::endl;
32-
std::cout<<"\t-Video processing : ./retinaDemo -video myMovie.mp4"<<std::endl;
33-
std::cout<<"\t-Live video processing : ./retinaDemo -video"<<std::endl;
34-
std::cout<<"\nPlease start again with new parameters"<<std::endl;
35-
}
18+
const std::string keys =
19+
"{image | | Input from image file }"
20+
"{video | | Input from video file }"
21+
"{camera | 0 | Index of input camera. If image or video is not specified, camera 0 will be used }"
22+
"{log | | Activate retina log sampling }"
23+
"{ocl | | Use OpenCL acceleration if possible }"
24+
"{help | | Print help}";
3625

3726
int main(int argc, char* argv[])
3827
{
3928
// welcome message
40-
std::cout<<"****************************************************"<<std::endl;
41-
std::cout<<"* Retina demonstration : demonstrates the use of is a wrapper class of the Gipsa/Listic Labs retina model."<<std::endl;
42-
std::cout<<"* This retina model allows spatio-temporal image processing (applied on still images, video sequences)."<<std::endl;
43-
std::cout<<"* As a summary, these are the retina model properties:"<<std::endl;
44-
std::cout<<"* => It applies a spectral whithening (mid-frequency details enhancement)"<<std::endl;
45-
std::cout<<"* => high frequency spatio-temporal noise reduction"<<std::endl;
46-
std::cout<<"* => low frequency luminance to be reduced (luminance range compression)"<<std::endl;
47-
std::cout<<"* => local logarithmic luminance compression allows details to be enhanced in low light conditions\n"<<std::endl;
48-
std::cout<<"* for more information, reer to the following papers :"<<std::endl;
49-
std::cout<<"* Benoit A., Caplier A., Durette B., Herault, J., \"USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING\", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011"<<std::endl;
50-
std::cout<<"* Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891."<<std::endl;
51-
std::cout<<"* => reports comments/remarks at [email protected]"<<std::endl;
52-
std::cout<<"* => more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"<<std::endl;
53-
std::cout<<"****************************************************"<<std::endl;
54-
std::cout<<" NOTE : this program generates the default retina parameters file 'RetinaDefaultParameters.xml'"<<std::endl;
55-
std::cout<<" => you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<<std::endl;
56-
57-
// basic input arguments checking
58-
if (argc<2)
59-
{
60-
help("bad number of parameter");
61-
return -1;
62-
}
63-
64-
bool useLogSampling = !strcmp(argv[argc-1], "log"); // check if user wants retina log sampling processing
65-
66-
std::string inputMediaType=argv[1];
29+
std::cout<<"****************************************************"<<std::endl
30+
<<"* Retina demonstration : demonstrates the use of is a wrapper class of the Gipsa/Listic Labs retina model."<<std::endl
31+
<<"* This retina model allows spatio-temporal image processing (applied on still images, video sequences)."<<std::endl
32+
<<"* As a summary, these are the retina model properties:"<<std::endl
33+
<<"* => It applies a spectral whithening (mid-frequency details enhancement)"<<std::endl
34+
<<"* => high frequency spatio-temporal noise reduction"<<std::endl
35+
<<"* => low frequency luminance to be reduced (luminance range compression)"<<std::endl
36+
<<"* => local logarithmic luminance compression allows details to be enhanced in low light conditions\n"<<std::endl
37+
<<"* for more information, reer to the following papers :"<<std::endl
38+
<<"* Benoit A., Caplier A., Durette B., Herault, J., \"USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING\", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011"<<std::endl
39+
<<"* Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891."<<std::endl
40+
<<"* => reports comments/remarks at [email protected]"<<std::endl
41+
<<"* => more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"<<std::endl
42+
<<"****************************************************"<<std::endl
43+
<<" NOTE : this program generates the default retina parameters file 'RetinaDefaultParameters.xml'"<<std::endl
44+
<<" => you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<<std::endl;
45+
46+
cv::CommandLineParser parser(argc, argv, keys);
47+
if(!parser.check() || parser.has("help")) {
48+
parser.printMessage();
49+
return 0;
50+
}
51+
52+
bool useLogSampling = parser.has("log"); // check if user wants retina log sampling processing
53+
bool useOCL = parser.has("ocl");
54+
cv::ocl::setUseOpenCL(useOCL);
55+
if(useOCL && !cv::ocl::useOpenCL())
56+
std::cout << "Failed to enable OpenCL\n";
6757

6858
// declare the retina input buffer... that will be fed differently in regard of the input media
6959
cv::Mat inputFrame;
7060
cv::VideoCapture videoCapture; // in case a video media is used, its manager is declared here
7161

72-
//////////////////////////////////////////////////////////////////////////////
73-
// checking input media type (still image, video file, live video acquisition)
74-
if (!strcmp(inputMediaType.c_str(), "-image") && argc >= 3)
75-
{
76-
std::cout<<"RetinaDemo: processing image "<<argv[2]<<std::endl;
77-
// image processing case
78-
inputFrame = cv::imread(std::string(argv[2]), 1); // load image in RGB mode
79-
}else
80-
if (!strcmp(inputMediaType.c_str(), "-video"))
81-
{
82-
if (argc == 2 || (argc == 3 && useLogSampling)) // attempt to grab images from a video capture device
83-
{
84-
videoCapture.open(0);
85-
}else// attempt to grab images from a video filestream
86-
{
87-
std::cout<<"RetinaDemo: processing video stream "<<argv[2]<<std::endl;
88-
videoCapture.open(argv[2]);
89-
}
90-
91-
// grab a first frame to check if everything is ok
92-
videoCapture>>inputFrame;
93-
}else
94-
{
95-
// bad command parameter
96-
help("bad command parameter");
97-
return -1;
98-
}
62+
if(parser.has("video"))
63+
videoCapture.open(parser.get<cv::String>("video"));
64+
else if(parser.has("image"))
65+
inputFrame = cv::imread(parser.get<cv::String>("image"));
66+
else
67+
videoCapture.open(parser.get<int>("camera"));
9968

100-
if (inputFrame.empty())
101-
{
102-
help("Input media could not be loaded, aborting");
103-
return -1;
104-
}
69+
videoCapture >> inputFrame;
10570

71+
if(inputFrame.empty())
72+
{
73+
std::cout << "Failed to open media source\n";
74+
return 0;
75+
}
10676

10777
//////////////////////////////////////////////////////////////////////////////
10878
// Program start in a try/catch safety context (Retina may throw errors)
@@ -127,8 +97,8 @@ int main(int argc, char* argv[])
12797
myRetina->clearBuffers();
12898

12999
// declare retina output buffers
130-
cv::Mat retinaOutput_parvo;
131-
cv::Mat retinaOutput_magno;
100+
cv::UMat retinaOutput_parvo;
101+
cv::UMat retinaOutput_magno;
132102

133103
// processing loop with stop condition
134104
bool continueProcessing=true; // FIXME : not yet managed during process...
@@ -147,7 +117,9 @@ int main(int argc, char* argv[])
147117
cv::imshow("Retina Parvo", retinaOutput_parvo);
148118
cv::imshow("Retina Magno", retinaOutput_magno);
149119

150-
cv::waitKey(5);
120+
int key = cv::waitKey(5);
121+
if(key == 'q')
122+
break;
151123
}
152124
}catch(cv::Exception e)
153125
{

0 commit comments

Comments
 (0)