OpenCV4入门教程127:Retina特征点检测

索引地址:系列索引

1963年12月30日E. Land作为人类视觉的亮度和颜色感知的模型在俄亥俄州提出了一种颜色恒常知觉的计算理论——Retinex理论。Retinex是一个合成词,它的构成是retina(视网膜)+cortex(皮层)→ Retinex。模仿人类视觉系统发展了Retinex算法,从单尺度Retinex算法(single scale retinex, SSR)改进成多尺度加权平均的Retinex算法(multi-scale retinex, MSR),再发展成带彩色恢复的多尺度Retinex算法(multi-scale retinex with color restoration, MSRCR)。

步骤:

  • 数据准备。如果输入图像为彩色图像,则将其划分为R ,G,B 三个波段;将每个像素的值由整数转换为浮点数。
  • 计算每个波段内相对明暗感觉。
  • 数据显示。将每个波段内像素间的相对明暗关系确定的色彩值转换为RGB 值以便能在现有的设备中显示和使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//============================================================================
// Name : 视网膜演示:演示使用的是一种gipsa /”实验室的视网膜模型的包装类。 Retina特征点检测。
// 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 "opencv2/opencv.hpp"
#include "opencv2/bioinspired/retina.hpp"
#include <cstring>
#include <iostream>

//--------------------------------------【help( )函数】--------------------------------------
// 描述:输出一些帮助信息
//----------------------------------------------------------------------------------------------
static void help(std::string errorMessage) {
std::cout << "Program init error : " << errorMessage << std::endl;
std::cout << "\nProgram call procedure : retinaDemo [processing mode] [Optional : media "
"target] [Optional LAST parameter: \"log\" to activate retina log sampling]"
<< std::endl;
std::cout << "\t[processing mode] :" << std::endl;
std::cout << "\t -image : for still image processing" << std::endl;
std::cout << "\t -video : for video stream processing" << std::endl;
std::cout << "\t[Optional : media target] :" << std::endl;
std::cout << "\t if processing an image or video file, then, specify the path and filename of "
"the target to process"
<< std::endl;
std::cout << "\t leave empty if processing video stream coming from a connected video device"
<< std::endl;
std::cout << "\t[Optional : activate retina log sampling] : an optional last parameter can be "
"specified for retina spatial log sampling"
<< std::endl;
std::cout << "\t set \"log\" without quotes to activate this sampling, output frame size will "
"be divided by 4"
<< std::endl;
std::cout << "\nExamples:" << std::endl;
std::cout << "\t-Image processing : ./retinaDemo -image lena.jpg" << std::endl;
std::cout << "\t-Image processing with log sampling : ./retinaDemo -image lena.jpg log"
<< std::endl;
std::cout << "\t-Video processing : ./retinaDemo -video myMovie.mp4" << std::endl;
std::cout << "\t-Live video processing : ./retinaDemo -video" << std::endl;
std::cout << "\nPlease start again with new parameters" << std::endl;
}

//-----------------------------------【main( )函数】--------------------------------------------
// 描述:控制台应用程序的入口函数,我们的程序从这里开始
//-------------------------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
// welcome message
std::cout << "****************************************************" << std::endl;
std::cout << "* Retina demonstration : demonstrates the use of is a wrapper class of the "
"Gipsa/Listic Labs retina model."
<< std::endl;
std::cout << "* This retina model allows spatio-temporal image processing (applied on still "
"images, video sequences)."
<< std::endl;
std::cout << "* As a summary, these are the retina model properties:" << std::endl;
std::cout << "* => It applies a spectral whithening (mid-frequency details enhancement)"
<< std::endl;
std::cout << "* => high frequency spatio-temporal noise reduction" << std::endl;
std::cout << "* => low frequency luminance to be reduced (luminance range compression)"
<< std::endl;
std::cout << "* => local logarithmic luminance compression allows details to be enhanced in "
"low light conditions\n"
<< std::endl;
std::cout << "* for more information, reer to the following papers :" << std::endl;
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;
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;
std::cout << "* => reports comments/remarks at benoit.alexandre.vision@gmail.com" << std::endl;
std::cout << "* => more informations and papers at : "
"http://sites.google.com/site/benoitalexandrevision/"
<< std::endl;
std::cout << "****************************************************" << std::endl;
std::cout << " NOTE : this program generates the default retina parameters file "
"'RetinaDefaultParameters.xml'"
<< std::endl;
std::cout << " => you can use this to fine tune parameters and load them if you save to file "
"'RetinaSpecificParameters.xml'"
<< std::endl;

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

inputFrame = cv::imread("box_in_scene.png", 1); // load image in RGB mode

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<cv::bioinspired::Retina> myRetina =
cv::bioinspired::Retina::create(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0);

// 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::Mat retinaOutput_parvo;
cv::Mat retinaOutput_magno;

// processing loop with stop condition
bool continueProcessing = true; // FIXME : not yet managed during process...
while (continueProcessing) {
// if using video stream, then, grabbing a new frame, else, input remains the same
if (videoCapture.isOpened())
videoCapture >> inputFrame;

// run retina filter
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 : " << e.what() << std::endl;
}

// Program end message
std::cout << "Retina demo end" << std::endl;

return 0;
}

效果

retina


OpenCV4入门教程127:Retina特征点检测
https://feater.top/opencv/opencv-retina-feature-detection/
作者
JackeyLea
发布于
2020年11月10日
许可协议