43#include <opencv2/opencv_modules.hpp>
45#ifdef HAVE_OPENCV_FEATURES2D
57static const char* keys =
58{
"{@image_path | | Image path }" };
62 cout <<
"\nThis example shows the functionalities of lines extraction " <<
"furnished by BinaryDescriptor class\n"
63 <<
"Please, run this sample using a command in the form\n" <<
"./example_line_descriptor_lines_extraction <path_to_input_image>" << endl;
66int main(
int argc,
char** argv )
72 if( image_path.empty() )
80 if( imageMat.
data == NULL )
82 std::cout <<
"Error, image could not be loaded. Please, check its path" << std::endl;
93 vector<KeyLine> lines;
97 bd->detect(imageMat, lines, 2, 1, mask);
101 cvtColor(output, output, COLOR_GRAY2BGR);
102 对于 (
size_t i = 0; i < lines.size(); i++)
108 int R = (rand() % (int)(255 + 1));
109 int G = (rand() % (int)(255 + 1));
110 int B = (rand() % (int)(255 + 1));
117 线(输出, pt1, pt2,
标量(B, G, R), 3);
131 std::cerr <<
"OpenCV was built without features2d module" << std::endl;
设计用于命令行解析。
定义 utility.hpp:820
CV_NODISCARD_STD Mat clone() const
创建数组和底层数据的完整副本。
MatSize size
定义 mat.hpp:2160
uchar * data
指向数据
定义 mat.hpp:2140
int channels() const
返回矩阵通道数。
std::string String
定义 cvstd.hpp:151
std::shared_ptr< _Tp > Ptr
定义 cvstd_wrapper.hpp:23
#define CV_8UC1
定义 interface.h:88
GMat mask(const GMat &src, const GMat &mask)
将蒙版应用到矩阵。
void imshow(const String &winname, InputArray mat)
在指定窗口中显示图像。
int waitKey(int delay=0)
等待按下的键。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR)
从文件中加载图像。
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
将图像从一种颜色空间转换为另一种颜色空间。
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制连接两个点的线段。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3
"黑匣子"代表与磁盘上文件关联的文件存储。
定义 core.hpp:102
表示线的类。
定义 descriptor.hpp:105
float endPointY
定义 descriptor.hpp:131
float startPointX
定义 descriptor.hpp:128
float endPointX
定义 descriptor.hpp:130
float startPointY
定义 descriptor.hpp:129
int octave
定义 descriptor.hpp:114
43#include <opencv2/opencv_modules.hpp>
45#ifdef HAVE_OPENCV_FEATURES2D
53#define MATCHES_DIST_THRESHOLD 25
58static const char* keys =
59{
"{@image_path1 | | Image path 1 }"
60 "{@image_path2 | | Image path 2 }" };
64 std::cout <<
"\nThis example shows the functionalities of lines extraction " <<
"and descriptors computation furnished by BinaryDescriptor class\n"
65 <<
"Please, run this sample using a command in the form\n" <<
"./example_line_descriptor_compute_descriptors <path_to_input_image 1>"
66 <<
"<path_to_input_image 2>" << std::endl;
70int main(
int argc,
char** argv )
77 if( image_path1.empty() || image_path2.empty() )
87 如果( imageMat1.
data == NULL || imageMat2.
data == NULL )
89 std::cout <<
"错误,图像无法加载。请检查其路径" << std::endl;
100 std::vector<KeyLine> keylines1, keylines2;
103 ( *bd )( imageMat1, mask1, keylines1, descr1,
false, false );
104 ( *bd )( imageMat2, mask2, keylines2, descr2,
false, false );
107 std::vector<KeyLine> lbd_octave1, lbd_octave2;
108 Mat left_lbd, right_lbd;
109 对于 (
int i = 0; i < (int) keylines1.size(); i++ )
111 如果( keylines1[i].八度 == 0 )
113 lbd_octave1.
压回( keylines1[i] );
114 left_lbd.
压回(descr1.
行( i ) );
118 对于 (
int j = 0; j < (int) keylines2.大小(); j++ )
120 如果( keylines2[j].八度 == 0 )
122 lbd_octave2.压回( keylines2[j] );
123 right_lbd.
压回( descr2.
行( j ) );
131 std::vector<DMatch> 匹配;
132 bdm->匹配( left_lbd, right_lbd, 匹配 );
135 std::vector<DMatch> 好_匹配;
136 对于 (
int i = 0; i < (int) 匹配.大小(); i++ )
138 如果( 匹配[i].距离 < 匹配距离阈值 )
145 std::vector<char>
掩码( 匹配.大小(), 1 );
146 绘制直线匹配( imageMat1, lbd_octave1, imageMat2, lbd_octave2, 好_匹配, 输出图像, Scalar::all( -1 ), Scalar::all( -1 ), 掩码,
149 imshow(
"Matches", outImg );
151 imwrite(
"/home/ubisum/Desktop/images/env_match/matches.jpg", outImg);
156 std::vector<KeyLine> klsd1, klsd2;
157 Mat lsd_descr1, lsd_descr2;
158 lsd->detect( imageMat1, klsd1, 2, 2, mask1 );
159 lsd->detect( imageMat2, klsd2, 2, 2, mask2 );
162 bd->compute( imageMat1, klsd1, lsd_descr1 );
163 bd->compute( imageMat2, klsd2, lsd_descr2 );
166 std::vector<KeyLine> octave0_1, octave0_2;
167 Mat leftDEscr, rightDescr;
168 for (
int i = 0; i < (int) klsd1.size(); i++ )
170 if( klsd1[i].octave == 1 )
177 for (
int j = 0; j < (int) klsd2.size(); j++ )
179 if( klsd2[j].octave == 1 )
181 octave0_2.push_back( klsd2[j] );
187 std::vector<DMatch> lsd_matches;
188 bdm->match( leftDEscr, rightDescr, lsd_matches );
191 good_matches.clear();
192 for (
int i = 0; i < (int) lsd_matches.size(); i++ )
194 if( lsd_matches[i].distance < MATCHES_DIST_THRESHOLD )
195 good_matches.push_back( lsd_matches[i] );
200 resize( imageMat1, imageMat1,
Size( imageMat1.cols / 2, imageMat1.rows / 2 ), 0, 0, INTER_LINEAR_EXACT );
201 resize( imageMat2, imageMat2,
Size( imageMat2.cols / 2, imageMat2.rows / 2 ), 0, 0, INTER_LINEAR_EXACT );
202 std::vector<char> lsd_mask( matches.size(), 1 );
203 drawLineMatches( imageMat1, octave0_1, imageMat2, octave0_2, good_matches, lsd_outImg, Scalar::all( -1 ), Scalar::all( -1 ), lsd_mask,
204 DrawLinesMatchesFlags::DEFAULT );
206 imshow(
"LSD matches", lsd_outImg );
216 std::cerr <<
"OpenCV was built without features2d module" << std::endl;
Mat row(int y) const
创建指定矩阵行的矩阵头。
void push_back(const _Tp &elem)
在矩阵底部添加元素。
用于指定图像或矩形大小的模板类。
定义 types.hpp:335
CV_EXPORTS_W bool imwrite(const String &filename, InputArray img, const std::vector< int > ¶ms=std::vector< int >())
将图像保存到指定文件中。
void drawLineMatches(const Mat &img1, const std::vector< KeyLine > &keylines1, const Mat &img2, const std::vector< KeyLine > &keylines2, const std::vector< DMatch > &matches1to2, Mat &outImg, const Scalar &matchColor=Scalar::all(-1), const Scalar &singleLineColor=Scalar::all(-1), const std::vector< char > &matchesMask=std::vector< char >(), int flags=DrawLinesMatchesFlags::DEFAULT)
绘制从两个图像中的关键线找到的匹配项。
43#include <opencv2/opencv_modules.hpp>
45#ifdef HAVE_OPENCV_FEATURES2D
58static const std::string images[] =
59{
"cameraman.jpg",
"church.jpg",
"church2.png",
"einstein.jpg",
"stuff.jpg" };
61static const char* keys =
62{
"{@image_path | | Image path }" };
66 std::cout <<
"\nThis example shows the functionalities of radius matching " <<
"\nPlease, run this sample using a command in the form\n"
67 <<
"./example_line_descriptor_radius_matching <path_to_input_images>/" << std::endl;
70int main(
int argc,
char** argv )
77 int num_elements =
sizeof ( images ) /
sizeof ( images[0] );
78 std::vector < Mat > descriptorsMat;
79 std::vector < std::vector<KeyLine> > linesMat;
82 Ptr < BinaryDescriptor > bd = BinaryDescriptor::createBinaryDescriptor();
85 for (
int i = 0; i < num_elements; i++ )
88 std::stringstream image_path;
89 image_path << pathToImages << images[i];
90 std::cout << image_path.str().c_str() << std::endl;
93 Mat loadedImage =
imread( image_path.str().c_str(), 1 );
94 if( loadedImage.
data == NULL )
96 std::cout <<
"无法载入图片。" << std::endl;
102 std::vector < KeyLine > lines;
104 bd->detect( loadedImage, lines );
105 bd->compute( loadedImage, lines, computedDescr );
107 descriptorsMat.
push_back( computedDescr );
108 linesMat.push_back( lines );
114 for (
size_t j = 0; j < descriptorsMat.size(); j++ )
116 if( descriptorsMat[j].rows >= 5 )
117 queries.
push_back( descriptorsMat[j].rowRange( 0, 5 ) );
119 else if( descriptorsMat[j].rows > 0 && descriptorsMat[j].rows < 5 )
123 std::cout <<
"它生成了一个 " << queries.
rows <<
" 个描述符的矩阵" << std::endl;
126 Ptr < BinaryDescriptorMatcher > bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
129 bdm->add( descriptorsMat );
132 std::vector < std::vector<DMatch> > matches;
133 bdm->radiusMatch( queries, matches, 30 );
134 std::cout <<
"size matches sample " << matches.size() << std::endl;
136 对于 (
int i = 0; i < (int) 匹配.大小(); i++ )
138 for (
int j = 0; j < (int) matches[i].
size(); j++ )
140 std::cout <<
"match: " << matches[i][j].queryIdx <<
" " << matches[i][j].trainIdx <<
" " << matches[i][j].distance << std::endl;
151 std::cerr <<
"OpenCV was built without features2d module" << std::endl;
int rows
行和列数或(-1,-1),当矩阵的维度大于 2 时
定义 mat.hpp:2138
GOpaque< Size > size(const GMat &src)
从 Mat 中获取维度。