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
06d4aa60
Commit
06d4aa60
authored
Oct 16, 2014
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now all the samples and opencv_contrib compile!
parent
09df1a28
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
109 additions
and
72 deletions
+109
-72
features2d.hpp
modules/features2d/include/opencv2/features2d.hpp
+4
-0
mser.cpp
modules/features2d/src/mser.cpp
+32
-0
matchers.cpp
modules/stitching/src/matchers.cpp
+0
-2
RobustMatcher.h
...ode/calib3d/real_time_pose_estimation/src/RobustMatcher.h
+9
-9
main_detection.cpp
.../calib3d/real_time_pose_estimation/src/main_detection.cpp
+0
-0
main_registration.cpp
...lib3d/real_time_pose_estimation/src/main_registration.cpp
+55
-52
AKAZE_match.cpp
samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
+3
-3
planar_tracking.cpp
...torial_code/features2D/AKAZE_tracking/planar_tracking.cpp
+4
-4
videostab.cpp
samples/cpp/videostab.cpp
+2
-2
No files found.
modules/features2d/include/opencv2/features2d.hpp
View file @
06d4aa60
...
...
@@ -197,6 +197,10 @@ public:
CV_WRAP
virtual
int
detectAndLabel
(
InputArray
image
,
OutputArray
label
,
OutputArray
stats
=
noArray
()
)
=
0
;
CV_WRAP
virtual
void
detectAndStore
(
InputArray
image
,
std
::
vector
<
std
::
vector
<
Point
>
>&
msers
,
OutputArray
stats
=
noArray
()
)
=
0
;
};
//! detects corners using FAST algorithm by E. Rosten
...
...
modules/features2d/src/mser.cpp
View file @
06d4aa60
...
...
@@ -301,6 +301,9 @@ public:
};
int
detectAndLabel
(
InputArray
_src
,
OutputArray
_labels
,
OutputArray
_bboxes
);
void
detectAndStore
(
InputArray
image
,
std
::
vector
<
std
::
vector
<
Point
>
>&
msers
,
OutputArray
stats
);
void
detect
(
InputArray
_src
,
vector
<
KeyPoint
>&
keypoints
,
InputArray
_mask
);
void
preprocess1
(
const
Mat
&
img
,
int
*
level_size
)
...
...
@@ -955,6 +958,35 @@ int MSER_Impl::detectAndLabel( InputArray _src, OutputArray _labels, OutputArray
return
(
int
)
bboxvec
.
size
();
}
void
MSER_Impl
::
detectAndStore
(
InputArray
image
,
std
::
vector
<
std
::
vector
<
Point
>
>&
msers
,
OutputArray
stats
)
{
vector
<
Rect
>
bboxvec
;
Mat
labels
;
int
i
,
x
,
y
,
nregs
=
detectAndLabel
(
image
,
labels
,
bboxvec
);
msers
.
resize
(
nregs
);
for
(
i
=
0
;
i
<
nregs
;
i
++
)
{
Rect
r
=
bboxvec
[
i
];
vector
<
Point
>&
msers_i
=
msers
[
i
];
msers_i
.
clear
();
for
(
y
=
r
.
y
;
y
<
r
.
y
+
r
.
height
;
y
++
)
{
const
int
*
lptr
=
labels
.
ptr
<
int
>
(
y
);
for
(
x
=
r
.
x
;
x
<
r
.
x
+
r
.
width
;
x
++
)
{
if
(
lptr
[
x
]
==
i
+
1
)
msers_i
.
push_back
(
Point
(
x
,
y
));
}
}
}
if
(
stats
.
needed
()
)
Mat
(
bboxvec
).
copyTo
(
stats
);
}
void
MSER_Impl
::
detect
(
InputArray
_image
,
vector
<
KeyPoint
>&
keypoints
,
InputArray
_mask
)
{
vector
<
Rect
>
bboxes
;
...
...
modules/stitching/src/matchers.cpp
View file @
06d4aa60
...
...
@@ -48,8 +48,6 @@ using namespace cv::cuda;
#ifdef HAVE_OPENCV_XFEATURES2D
#include "opencv2/xfeatures2d.hpp"
static
bool
makeUseOfXfeatures2d
=
xfeatures2d
::
initModule_xfeatures2d
();
#endif
namespace
{
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/RobustMatcher.h
View file @
06d4aa60
...
...
@@ -19,23 +19,23 @@ public:
RobustMatcher
()
:
ratio_
(
0
.
8
f
)
{
// ORB is the default feature
detector_
=
new
cv
::
OrbFeatureDetector
();
extractor_
=
new
cv
::
OrbDescriptorExtractor
();
detector_
=
cv
::
ORB
::
create
();
extractor_
=
cv
::
ORB
::
create
();
// BruteFroce matcher with Norm Hamming is the default matcher
matcher_
=
new
cv
::
BFMatcher
(
cv
::
NORM_HAMMING
,
false
);
matcher_
=
cv
::
makePtr
<
cv
::
BFMatcher
>
(
cv
::
NORM_HAMMING
,
false
);
}
virtual
~
RobustMatcher
();
// Set the feature detector
void
setFeatureDetector
(
c
v
::
FeatureDetector
*
detect
)
{
detector_
=
detect
;
}
void
setFeatureDetector
(
c
onst
cv
::
Ptr
<
cv
::
FeatureDetector
>&
detect
)
{
detector_
=
detect
;
}
// Set the descriptor extractor
void
setDescriptorExtractor
(
c
v
::
DescriptorExtractor
*
desc
)
{
extractor_
=
desc
;
}
void
setDescriptorExtractor
(
c
onst
cv
::
Ptr
<
cv
::
DescriptorExtractor
>&
desc
)
{
extractor_
=
desc
;
}
// Set the matcher
void
setDescriptorMatcher
(
c
v
::
DescriptorMatcher
*
match
)
{
matcher_
=
match
;
}
void
setDescriptorMatcher
(
c
onst
cv
::
Ptr
<
cv
::
DescriptorMatcher
>&
match
)
{
matcher_
=
match
;
}
// Compute the keypoints of an image
void
computeKeyPoints
(
const
cv
::
Mat
&
image
,
std
::
vector
<
cv
::
KeyPoint
>&
keypoints
);
...
...
@@ -69,11 +69,11 @@ public:
private
:
// pointer to the feature point detector object
cv
::
FeatureDetector
*
detector_
;
cv
::
Ptr
<
cv
::
FeatureDetector
>
detector_
;
// pointer to the feature descriptor extractor object
cv
::
DescriptorExtractor
*
extractor_
;
cv
::
Ptr
<
cv
::
DescriptorExtractor
>
extractor_
;
// pointer to the matcher object
cv
::
DescriptorMatcher
*
matcher_
;
cv
::
Ptr
<
cv
::
DescriptorMatcher
>
matcher_
;
// max ratio between 1st and 2nd NN
float
ratio_
;
};
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp
View file @
06d4aa60
This diff is collapsed.
Click to expand it.
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp
View file @
06d4aa60
...
...
@@ -13,13 +13,16 @@
#include "ModelRegistration.h"
#include "Utils.h"
using
namespace
cv
;
using
namespace
std
;
/** GLOBAL VARIABLES **/
st
d
::
st
ring
tutorial_path
=
"../../samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/"
;
// path to tutorial
string
tutorial_path
=
"../../samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/"
;
// path to tutorial
st
d
::
st
ring
img_path
=
tutorial_path
+
"Data/resized_IMG_3875.JPG"
;
// image to register
st
d
::
st
ring
ply_read_path
=
tutorial_path
+
"Data/box.ply"
;
// object mesh
st
d
::
st
ring
write_path
=
tutorial_path
+
"Data/cookies_ORB.yml"
;
// output file
string
img_path
=
tutorial_path
+
"Data/resized_IMG_3875.JPG"
;
// image to register
string
ply_read_path
=
tutorial_path
+
"Data/box.ply"
;
// object mesh
string
write_path
=
tutorial_path
+
"Data/cookies_ORB.yml"
;
// output file
// Boolean the know if the registration it's done
bool
end_registration
=
false
;
...
...
@@ -39,10 +42,10 @@ int n = 8;
int
pts
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
// 3 -> 4
// Some basic colors
cv
::
Scalar
red
(
0
,
0
,
255
);
cv
::
Scalar
green
(
0
,
255
,
0
);
cv
::
Scalar
blue
(
255
,
0
,
0
);
cv
::
Scalar
yellow
(
0
,
255
,
255
);
Scalar
red
(
0
,
0
,
255
);
Scalar
green
(
0
,
255
,
0
);
Scalar
blue
(
255
,
0
,
0
);
Scalar
yellow
(
0
,
255
,
255
);
/*
* CREATE MODEL REGISTRATION OBJECT
...
...
@@ -61,13 +64,13 @@ void help();
// Mouse events for model registration
static
void
onMouseModelRegistration
(
int
event
,
int
x
,
int
y
,
int
,
void
*
)
{
if
(
event
==
cv
::
EVENT_LBUTTONUP
)
if
(
event
==
EVENT_LBUTTONUP
)
{
int
n_regist
=
registration
.
getNumRegist
();
int
n_vertex
=
pts
[
n_regist
];
cv
::
Point2f
point_2d
=
cv
::
Point2f
((
float
)
x
,(
float
)
y
);
cv
::
Point3f
point_3d
=
mesh
.
getVertex
(
n_vertex
-
1
);
Point2f
point_2d
=
Point2f
((
float
)
x
,(
float
)
y
);
Point3f
point_3d
=
mesh
.
getVertex
(
n_vertex
-
1
);
bool
is_registrable
=
registration
.
is_registrable
();
if
(
is_registrable
)
...
...
@@ -92,23 +95,23 @@ int main()
//Instantiate robust matcher: detector, extractor, matcher
RobustMatcher
rmatcher
;
cv
::
FeatureDetector
*
detector
=
new
cv
::
OrbFeatureDetector
(
numKeyPoints
);
Ptr
<
FeatureDetector
>
detector
=
ORB
::
create
(
numKeyPoints
);
rmatcher
.
setFeatureDetector
(
detector
);
/** GROUND TRUTH OF THE FIRST IMAGE **/
// Create & Open Window
cv
::
namedWindow
(
"MODEL REGISTRATION"
,
cv
::
WINDOW_KEEPRATIO
);
namedWindow
(
"MODEL REGISTRATION"
,
WINDOW_KEEPRATIO
);
// Set up the mouse events
cv
::
setMouseCallback
(
"MODEL REGISTRATION"
,
onMouseModelRegistration
,
0
);
setMouseCallback
(
"MODEL REGISTRATION"
,
onMouseModelRegistration
,
0
);
// Open the image to register
cv
::
Mat
img_in
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
Mat
img_vis
=
img_in
.
clone
();
Mat
img_in
=
imread
(
img_path
,
IMREAD_COLOR
);
Mat
img_vis
=
img_in
.
clone
();
if
(
!
img_in
.
data
)
{
std
::
cout
<<
"Could not open or find the image"
<<
std
::
endl
;
cout
<<
"Could not open or find the image"
<<
endl
;
return
-
1
;
}
...
...
@@ -116,18 +119,18 @@ int main()
int
num_registrations
=
n
;
registration
.
setNumMax
(
num_registrations
);
std
::
cout
<<
"Click the box corners ..."
<<
std
::
endl
;
std
::
cout
<<
"Waiting ..."
<<
std
::
endl
;
cout
<<
"Click the box corners ..."
<<
endl
;
cout
<<
"Waiting ..."
<<
endl
;
// Loop until all the points are registered
while
(
cv
::
waitKey
(
30
)
<
0
)
while
(
waitKey
(
30
)
<
0
)
{
// Refresh debug image
img_vis
=
img_in
.
clone
();
// Current registered points
std
::
vector
<
cv
::
Point2f
>
list_points2d
=
registration
.
get_points2d
();
std
::
vector
<
cv
::
Point3f
>
list_points3d
=
registration
.
get_points3d
();
vector
<
Point2f
>
list_points2d
=
registration
.
get_points2d
();
vector
<
Point3f
>
list_points3d
=
registration
.
get_points3d
();
// Draw current registered points
drawPoints
(
img_vis
,
list_points2d
,
list_points3d
,
red
);
...
...
@@ -139,7 +142,7 @@ int main()
// Draw debug text
int
n_regist
=
registration
.
getNumRegist
();
int
n_vertex
=
pts
[
n_regist
];
cv
::
Point3f
current_poin3d
=
mesh
.
getVertex
(
n_vertex
-
1
);
Point3f
current_poin3d
=
mesh
.
getVertex
(
n_vertex
-
1
);
drawQuestion
(
img_vis
,
current_poin3d
,
green
);
drawCounter
(
img_vis
,
registration
.
getNumRegist
(),
registration
.
getNumMax
(),
red
);
...
...
@@ -153,43 +156,43 @@ int main()
}
// Show the image
cv
::
imshow
(
"MODEL REGISTRATION"
,
img_vis
);
imshow
(
"MODEL REGISTRATION"
,
img_vis
);
}
/** COMPUTE CAMERA POSE **/
std
::
cout
<<
"COMPUTING POSE ..."
<<
std
::
endl
;
cout
<<
"COMPUTING POSE ..."
<<
endl
;
// The list of registered points
std
::
vector
<
cv
::
Point2f
>
list_points2d
=
registration
.
get_points2d
();
std
::
vector
<
cv
::
Point3f
>
list_points3d
=
registration
.
get_points3d
();
vector
<
Point2f
>
list_points2d
=
registration
.
get_points2d
();
vector
<
Point3f
>
list_points3d
=
registration
.
get_points3d
();
// Estimate pose given the registered points
bool
is_correspondence
=
pnp_registration
.
estimatePose
(
list_points3d
,
list_points2d
,
cv
::
SOLVEPNP_ITERATIVE
);
bool
is_correspondence
=
pnp_registration
.
estimatePose
(
list_points3d
,
list_points2d
,
SOLVEPNP_ITERATIVE
);
if
(
is_correspondence
)
{
std
::
cout
<<
"Correspondence found"
<<
std
::
endl
;
cout
<<
"Correspondence found"
<<
endl
;
// Compute all the 2D points of the mesh to verify the algorithm and draw it
std
::
vector
<
cv
::
Point2f
>
list_points2d_mesh
=
pnp_registration
.
verify_points
(
&
mesh
);
vector
<
Point2f
>
list_points2d_mesh
=
pnp_registration
.
verify_points
(
&
mesh
);
draw2DPoints
(
img_vis
,
list_points2d_mesh
,
green
);
}
else
{
std
::
cout
<<
"Correspondence not found"
<<
std
::
endl
<<
std
::
endl
;
cout
<<
"Correspondence not found"
<<
endl
<<
endl
;
}
// Show the image
cv
::
imshow
(
"MODEL REGISTRATION"
,
img_vis
);
imshow
(
"MODEL REGISTRATION"
,
img_vis
);
// Show image until ESC pressed
cv
::
waitKey
(
0
);
waitKey
(
0
);
/** COMPUTE 3D of the image Keypoints **/
// Containers for keypoints and descriptors of the model
std
::
vector
<
cv
::
KeyPoint
>
keypoints_model
;
cv
::
Mat
descriptors
;
vector
<
KeyPoint
>
keypoints_model
;
Mat
descriptors
;
// Compute keypoints and descriptors
rmatcher
.
computeKeyPoints
(
img_in
,
keypoints_model
);
...
...
@@ -197,8 +200,8 @@ int main()
// Check if keypoints are on the surface of the registration image and add to the model
for
(
unsigned
int
i
=
0
;
i
<
keypoints_model
.
size
();
++
i
)
{
cv
::
Point2f
point2d
(
keypoints_model
[
i
].
pt
);
cv
::
Point3f
point3d
;
Point2f
point2d
(
keypoints_model
[
i
].
pt
);
Point3f
point3d
;
bool
on_surface
=
pnp_registration
.
backproject2DPoint
(
&
mesh
,
point2d
,
point3d
);
if
(
on_surface
)
{
...
...
@@ -219,12 +222,12 @@ int main()
img_vis
=
img_in
.
clone
();
// The list of the points2d of the model
std
::
vector
<
cv
::
Point2f
>
list_points_in
=
model
.
get_points2d_in
();
std
::
vector
<
cv
::
Point2f
>
list_points_out
=
model
.
get_points2d_out
();
vector
<
Point2f
>
list_points_in
=
model
.
get_points2d_in
();
vector
<
Point2f
>
list_points_out
=
model
.
get_points2d_out
();
// Draw some debug text
st
d
::
st
ring
num
=
IntToString
((
int
)
list_points_in
.
size
());
st
d
::
st
ring
text
=
"There are "
+
num
+
" inliers"
;
string
num
=
IntToString
((
int
)
list_points_in
.
size
());
string
text
=
"There are "
+
num
+
" inliers"
;
drawText
(
img_vis
,
text
,
green
);
// Draw some debug text
...
...
@@ -240,26 +243,26 @@ int main()
draw2DPoints
(
img_vis
,
list_points_out
,
red
);
// Show the image
cv
::
imshow
(
"MODEL REGISTRATION"
,
img_vis
);
imshow
(
"MODEL REGISTRATION"
,
img_vis
);
// Wait until ESC pressed
cv
::
waitKey
(
0
);
waitKey
(
0
);
// Close and Destroy Window
cv
::
destroyWindow
(
"MODEL REGISTRATION"
);
destroyWindow
(
"MODEL REGISTRATION"
);
std
::
cout
<<
"GOODBYE"
<<
std
::
endl
;
cout
<<
"GOODBYE"
<<
endl
;
}
/**********************************************************************************************************/
void
help
()
{
std
::
cout
<<
"--------------------------------------------------------------------------"
<<
std
::
endl
<<
"This program shows how to create your 3D textured model. "
<<
std
::
endl
<<
"Usage:"
<<
std
::
endl
<<
"./cpp-tutorial-pnp_registration"
<<
std
::
endl
<<
"--------------------------------------------------------------------------"
<<
std
::
endl
<<
std
::
endl
;
cout
<<
"--------------------------------------------------------------------------"
<<
endl
<<
"This program shows how to create your 3D textured model. "
<<
endl
<<
"Usage:"
<<
endl
<<
"./cpp-tutorial-pnp_registration"
<<
endl
<<
"--------------------------------------------------------------------------"
<<
endl
<<
endl
;
}
samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
View file @
06d4aa60
...
...
@@ -22,9 +22,9 @@ int main(void)
vector
<
KeyPoint
>
kpts1
,
kpts2
;
Mat
desc1
,
desc2
;
AKAZE
akaze
;
akaze
(
img1
,
noArray
(),
kpts1
,
desc1
);
akaze
(
img2
,
noArray
(),
kpts2
,
desc2
);
Ptr
<
AKAZE
>
akaze
=
AKAZE
::
create
()
;
akaze
->
detectAndCompute
(
img1
,
noArray
(),
kpts1
,
desc1
);
akaze
->
detectAndCompute
(
img2
,
noArray
(),
kpts2
,
desc2
);
BFMatcher
matcher
(
NORM_HAMMING
);
vector
<
vector
<
DMatch
>
>
nn_matches
;
...
...
samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp
View file @
06d4aa60
...
...
@@ -41,7 +41,7 @@ protected:
void
Tracker
::
setFirstFrame
(
const
Mat
frame
,
vector
<
Point2f
>
bb
,
string
title
,
Stats
&
stats
)
{
first_frame
=
frame
.
clone
();
(
*
detector
)
(
first_frame
,
noArray
(),
first_kp
,
first_desc
);
detector
->
detectAndCompute
(
first_frame
,
noArray
(),
first_kp
,
first_desc
);
stats
.
keypoints
=
(
int
)
first_kp
.
size
();
drawBoundingBox
(
first_frame
,
bb
);
putText
(
first_frame
,
title
,
Point
(
0
,
60
),
FONT_HERSHEY_PLAIN
,
5
,
Scalar
::
all
(
0
),
4
);
...
...
@@ -52,7 +52,7 @@ Mat Tracker::process(const Mat frame, Stats& stats)
{
vector
<
KeyPoint
>
kp
;
Mat
desc
;
(
*
detector
)
(
frame
,
noArray
(),
kp
,
desc
);
detector
->
detectAndCompute
(
frame
,
noArray
(),
kp
,
desc
);
stats
.
keypoints
=
(
int
)
kp
.
size
();
vector
<
vector
<
DMatch
>
>
matches
;
...
...
@@ -135,9 +135,9 @@ int main(int argc, char **argv)
return
1
;
}
fs
[
"bounding_box"
]
>>
bb
;
Ptr
<
Feature2D
>
akaze
=
Feature2D
::
create
(
"AKAZE"
);
Ptr
<
Feature2D
>
akaze
=
AKAZE
::
create
(
);
akaze
->
set
(
"threshold"
,
akaze_thresh
);
Ptr
<
Feature2D
>
orb
=
Feature2D
::
create
(
"ORB"
);
Ptr
<
Feature2D
>
orb
=
ORB
::
create
(
);
Ptr
<
DescriptorMatcher
>
matcher
=
DescriptorMatcher
::
create
(
"BruteForce-Hamming"
);
Tracker
akaze_tracker
(
akaze
,
matcher
);
Tracker
orb_tracker
(
orb
,
matcher
);
...
...
samples/cpp/videostab.cpp
View file @
06d4aa60
...
...
@@ -227,7 +227,7 @@ public:
#endif
Ptr
<
KeypointBasedMotionEstimator
>
kbest
=
makePtr
<
KeypointBasedMotionEstimator
>
(
est
);
kbest
->
setDetector
(
makePtr
<
GoodFeaturesToTrackDetector
>
(
argi
(
prefix
+
"nkps"
)));
kbest
->
setDetector
(
GFTTDetector
::
create
(
argi
(
prefix
+
"nkps"
)));
kbest
->
setOutlierRejector
(
outlierRejector
);
return
kbest
;
}
...
...
@@ -268,7 +268,7 @@ public:
#endif
Ptr
<
KeypointBasedMotionEstimator
>
kbest
=
makePtr
<
KeypointBasedMotionEstimator
>
(
est
);
kbest
->
setDetector
(
makePtr
<
GoodFeaturesToTrackDetector
>
(
argi
(
prefix
+
"nkps"
)));
kbest
->
setDetector
(
GFTTDetector
::
create
(
argi
(
prefix
+
"nkps"
)));
kbest
->
setOutlierRejector
(
outlierRejector
);
return
kbest
;
}
...
...
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