Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
364c8c74
Commit
364c8c74
authored
9 years ago
by
Joan Solà Ortega
Browse files
Options
Downloads
Patches
Plain Diff
testing matching using opencv
parent
ece95158
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/examples/CMakeLists.txt
+4
-0
4 additions, 0 deletions
src/examples/CMakeLists.txt
src/examples/test_image.cpp
+1
-1
1 addition, 1 deletion
src/examples/test_image.cpp
src/examples/test_opencv.cpp
+161
-0
161 additions, 0 deletions
src/examples/test_opencv.cpp
with
166 additions
and
1 deletion
src/examples/CMakeLists.txt
+
4
−
0
View file @
364c8c74
...
@@ -75,6 +75,10 @@ IF(OpenCV_FOUND)
...
@@ -75,6 +75,10 @@ IF(OpenCV_FOUND)
ADD_EXECUTABLE
(
test_image test_image.cpp
)
ADD_EXECUTABLE
(
test_image test_image.cpp
)
TARGET_LINK_LIBRARIES
(
test_image
${
PROJECT_NAME
}
)
TARGET_LINK_LIBRARIES
(
test_image
${
PROJECT_NAME
}
)
# Testing opencv matching and fundamental matrix with ransac
ADD_EXECUTABLE
(
test_opencv test_opencv.cpp
)
TARGET_LINK_LIBRARIES
(
test_opencv
${
PROJECT_NAME
}
)
# Testing OpenCV functions for projection of points
# Testing OpenCV functions for projection of points
ADD_EXECUTABLE
(
test_projection_points test_projection_points.cpp
)
ADD_EXECUTABLE
(
test_projection_points test_projection_points.cpp
)
TARGET_LINK_LIBRARIES
(
test_projection_points
${
PROJECT_NAME
}
)
TARGET_LINK_LIBRARIES
(
test_projection_points
${
PROJECT_NAME
}
)
...
...
This diff is collapsed.
Click to expand it.
src/examples/test_image.cpp
+
1
−
1
View file @
364c8c74
...
@@ -90,7 +90,7 @@ int main(int argc, char** argv)
...
@@ -90,7 +90,7 @@ int main(int argc, char** argv)
tracker_params
.
image
=
{
img_width
,
img_height
};
tracker_params
.
image
=
{
img_width
,
img_height
};
tracker_params
.
detector
.
threshold
=
30
;
tracker_params
.
detector
.
threshold
=
30
;
tracker_params
.
detector
.
threshold_new_features
=
70
;
tracker_params
.
detector
.
threshold_new_features
=
70
;
tracker_params
.
detector
.
octaves
=
0
;
tracker_params
.
detector
.
octaves
=
2
;
tracker_params
.
detector
.
nominal_pattern_radius
=
4
;
tracker_params
.
detector
.
nominal_pattern_radius
=
4
;
tracker_params
.
descriptor
.
size
=
512
;
tracker_params
.
descriptor
.
size
=
512
;
tracker_params
.
descriptor
.
pattern_scale
=
1.0
;
tracker_params
.
descriptor
.
pattern_scale
=
1.0
;
...
...
This diff is collapsed.
Click to expand it.
src/examples/test_opencv.cpp
0 → 100644
+
161
−
0
View file @
364c8c74
/*
* test_opencv.cpp
*
* Created on: Apr 24, 2016
* Author: jsola
*/
// Testing things for the 3D image odometry
// general includes
#include
"unistd.h"
#include
<time.h>
#include
"opencv2/calib3d/calib3d.hpp"
#include
"opencv2/features2d/features2d.hpp"
#include
<opencv2/highgui/highgui.hpp>
#include
<opencv2/core/core.hpp>
// General includes
#include
<math.h>
#include
<complex>
// std::complex, std::norm
//std includes
#include
<iostream>
int
main
(
int
argc
,
char
**
argv
)
{
std
::
cout
<<
std
::
endl
<<
" ========= OpenCv test ==========="
<<
std
::
endl
<<
std
::
endl
;
const
char
*
filename
;
if
(
argc
==
1
)
{
filename
=
"/home/jtarraso/Vídeos/House interior.mp4"
;
}
else
{
if
(
std
::
string
(
argv
[
1
])
==
"0"
)
{
//camera
filename
=
"0"
;
}
else
{
filename
=
argv
[
1
];
}
}
std
::
cout
<<
"Input video file: "
<<
filename
<<
std
::
endl
;
cv
::
VideoCapture
capture
(
filename
);
if
(
!
capture
.
isOpened
())
// check if we succeeded
{
std
::
cout
<<
"failed"
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"succeded"
<<
std
::
endl
;
}
capture
.
set
(
CV_CAP_PROP_POS_MSEC
,
0000
);
unsigned
int
img_width
=
(
unsigned
int
)
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
);
unsigned
int
img_height
=
(
unsigned
int
)
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
);
std
::
cout
<<
"Image size: "
<<
img_width
<<
"x"
<<
img_height
<<
std
::
endl
;
unsigned
int
buffer_size
=
4
;
std
::
vector
<
cv
::
Mat
>
frame
(
buffer_size
);
cv
::
Mat
img_1
,
img_2
;
unsigned
int
margin
=
0
;
cv
::
Rect
roi
(
margin
,
margin
,
img_width
-
2
*
margin
,
img_height
-
2
*
margin
);
cv
::
namedWindow
(
"Feature tracker"
);
// Creates a window for display.
cv
::
moveWindow
(
"Feature tracker"
,
0
,
0
);
cv
::
BRISK
detector
;
cv
::
BRISK
descriptor
;
// cv::FlannBasedMatcher matcher;
cv
::
BFMatcher
matcher
(
cv
::
NORM_HAMMING
);
std
::
vector
<
cv
::
KeyPoint
>
keypoints_1
,
keypoints_2
,
matched_1
,
matched_2
;
cv
::
Mat
descriptors_1
,
descriptors_2
;
std
::
vector
<
cv
::
DMatch
>
matches
;
unsigned
int
f
=
0
;
while
(
f
<
800
)
{
f
++
;
std
::
cout
<<
"
\n
=============== Frame #: "
<<
f
<<
" in buffer: "
<<
f
%
buffer_size
<<
" ==============="
<<
std
::
endl
;
capture
>>
frame
[
f
%
buffer_size
];
if
(
!
frame
[
f
%
buffer_size
].
empty
())
{
cv
::
imshow
(
"Feature tracker"
,
frame
[
f
%
buffer_size
]);
cv
::
waitKey
(
1
);
if
(
f
>
1
)
{
img_1
=
frame
[
f
%
buffer_size
];
img_2
=
frame
[(
f
-
1
)
%
buffer_size
];
// detect and describe in both images
detector
.
detect
(
img_1
(
roi
),
keypoints_1
);
detector
.
detect
(
img_2
(
roi
),
keypoints_2
);
descriptor
.
compute
(
img_1
(
roi
),
keypoints_1
,
descriptors_1
);
descriptor
.
compute
(
img_2
(
roi
),
keypoints_2
,
descriptors_2
);
// match (try flann later)
//-- Step 3: Matching descriptor vectors using FLANN matcher
matcher
.
match
(
descriptors_1
,
descriptors_2
,
matches
);
double
max_dist
=
0
;
double
min_dist
=
512
;
//-- Quick calculation of max and min distances between keypoints
for
(
int
i
=
0
;
i
<
descriptors_1
.
rows
;
i
++
)
{
double
dist
=
matches
[
i
].
distance
;
if
(
dist
<
min_dist
)
min_dist
=
dist
;
if
(
dist
>
max_dist
)
max_dist
=
dist
;
}
printf
(
"-- Max dist : %f
\n
"
,
max_dist
);
printf
(
"-- Min dist : %f
\n
"
,
min_dist
);
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
//-- small)
//-- PS.- radiusMatch can also be used here.
std
::
vector
<
cv
::
DMatch
>
good_matches
;
for
(
int
i
=
0
;
i
<
descriptors_1
.
rows
;
i
++
)
{
if
(
matches
[
i
].
distance
<=
50
)
//std::max(2*min_dist, 0.02) )
{
good_matches
.
push_back
(
matches
[
i
]);
}
}
//-- Draw only "good" matches
cv
::
Mat
img_matches
;
cv
::
drawMatches
(
img_1
(
roi
),
keypoints_1
,
img_2
(
roi
),
keypoints_2
,
good_matches
,
img_matches
,
cv
::
Scalar
::
all
(
-
1
),
cv
::
Scalar
::
all
(
-
1
),
std
::
vector
<
char
>
(),
cv
::
DrawMatchesFlags
::
NOT_DRAW_SINGLE_POINTS
);
//-- Show detected matches
imshow
(
"Good Matches"
,
img_matches
);
// // find fundamental matrix using RANSAC
// cv::Mat F = findFundamentalMat(keypoints_1, keypoints_2, cv::FM_RANSAC);
//
// std::cout << F << std::endl;
}
}
else
{
cv
::
waitKey
(
2000
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment