Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
6667d935
Commit
6667d935
authored
Jun 11, 2010
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated descriptor_extractro_matcher sample to use added drawMatches function
parent
17a8050f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
51 deletions
+26
-51
descriptor_extractor_matcher.cpp
samples/cpp/descriptor_extractor_matcher.cpp
+26
-51
No files found.
samples/cpp/descriptor_extractor_matcher.cpp
View file @
6667d935
#include <cv.h>
#include <cvaux.h>
#include <highgui.h>
#include "opencv2/features2d/features2d.hpp"
#include <iostream>
using
namespace
cv
;
using
namespace
std
;
...
...
@@ -110,55 +111,6 @@ DescriptorMatcher* createDescriptorMatcher( const string& descriptorMatcherType
return
dm
;
}
void
drawCorrespondences
(
const
Mat
&
img1
,
const
Mat
&
img2
,
const
vector
<
KeyPoint
>&
keypoints1
,
const
vector
<
KeyPoint
>&
keypoints2
,
const
vector
<
int
>&
matches
,
Mat
&
drawImg
,
const
Mat
&
H12
=
Mat
()
)
{
Scalar
RED
=
CV_RGB
(
255
,
0
,
0
);
// red keypoint - point without corresponding point
Scalar
GREEN
=
CV_RGB
(
0
,
255
,
0
);
// green keypoint - point having correct corresponding point
Scalar
BLUE
=
CV_RGB
(
0
,
0
,
255
);
// blue keypoint - point having incorrect corresponding point
Size
size
(
img1
.
cols
+
img2
.
cols
,
MAX
(
img1
.
rows
,
img2
.
rows
));
drawImg
.
create
(
size
,
CV_MAKETYPE
(
img1
.
depth
(),
3
));
Mat
drawImg1
=
drawImg
(
Rect
(
0
,
0
,
img1
.
cols
,
img1
.
rows
));
cvtColor
(
img1
,
drawImg1
,
CV_GRAY2RGB
);
Mat
drawImg2
=
drawImg
(
Rect
(
img1
.
cols
,
0
,
img2
.
cols
,
img2
.
rows
));
cvtColor
(
img2
,
drawImg2
,
CV_GRAY2RGB
);
// draw keypoints
for
(
vector
<
KeyPoint
>::
const_iterator
it
=
keypoints1
.
begin
();
it
<
keypoints1
.
end
();
++
it
)
{
circle
(
drawImg
,
it
->
pt
,
3
,
RED
);
}
for
(
vector
<
KeyPoint
>::
const_iterator
it
=
keypoints2
.
begin
();
it
<
keypoints2
.
end
();
++
it
)
{
Point
p
=
it
->
pt
;
circle
(
drawImg
,
Point2f
(
p
.
x
+
img1
.
cols
,
p
.
y
),
3
,
RED
);
}
// draw matches
vector
<
int
>::
const_iterator
mit
=
matches
.
begin
();
assert
(
matches
.
size
()
==
keypoints1
.
size
()
);
for
(
int
i1
=
0
;
mit
!=
matches
.
end
();
++
mit
,
i1
++
)
{
Point2f
pt1
=
keypoints1
[
i1
].
pt
,
pt2
=
keypoints2
[
*
mit
].
pt
,
dpt2
=
Point2f
(
std
::
min
(
pt2
.
x
+
img1
.
cols
,
float
(
drawImg
.
cols
-
1
)),
pt2
.
y
);
if
(
!
H12
.
empty
()
)
{
if
(
norm
(
pt2
-
applyHomography
(
H12
,
pt1
))
>
3
)
{
circle
(
drawImg
,
pt1
,
3
,
BLUE
);
circle
(
drawImg
,
dpt2
,
3
,
BLUE
);
continue
;
}
}
circle
(
drawImg
,
pt1
,
3
,
GREEN
);
circle
(
drawImg
,
dpt2
,
3
,
GREEN
);
line
(
drawImg
,
pt1
,
dpt2
,
GREEN
);
}
}
const
string
winName
=
"correspondences"
;
void
doIteration
(
const
Mat
&
img1
,
Mat
&
img2
,
bool
isWarpPerspective
,
...
...
@@ -208,7 +160,30 @@ void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective,
}
Mat
drawImg
;
drawCorrespondences
(
img1
,
img2
,
keypoints1
,
keypoints2
,
matches
,
drawImg
,
H12
);
if
(
!
H12
.
empty
()
)
{
vector
<
char
>
mask
(
matches
.
size
(),
0
);
vector
<
int
>::
const_iterator
mit
=
matches
.
begin
();
for
(
size_t
i1
=
0
;
mit
!=
matches
.
end
();
++
mit
,
i1
++
)
{
Point2f
pt1
=
keypoints1
[
i1
].
pt
,
pt2
=
keypoints2
[
*
mit
].
pt
;
if
(
norm
(
pt2
-
applyHomography
(
H12
,
pt1
))
<
4
)
// inlier
mask
[
i1
]
=
1
;
}
// draw inliers
drawMatches
(
img1
,
img2
,
keypoints1
,
keypoints2
,
matches
,
mask
,
drawImg
,
CV_RGB
(
0
,
255
,
0
),
CV_RGB
(
0
,
0
,
255
)
);
// draw outliers
/*for( size_t i1 = 0; i1 < mask.size(); i1++ )
mask[i1] = !mask[i1];
drawMatches( img1, img2, keypoints1, keypoints2, matches, mask, drawImg, CV_RGB(0, 0, 255), CV_RGB(255, 0, 0),
DrawMatchesFlags::DRAW_OVER_OUTIMG | DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );*/
}
else
{
drawMatches
(
img1
,
img2
,
keypoints1
,
keypoints2
,
matches
,
vector
<
char
>
(),
drawImg
,
CV_RGB
(
0
,
255
,
0
)
);
}
imshow
(
winName
,
drawImg
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment