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
eadb3bad
Commit
eadb3bad
authored
May 28, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring of opencv_stitching
parent
7881134c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
26 deletions
+31
-26
main.cpp
modules/stitching/main.cpp
+24
-23
matchers.cpp
modules/stitching/matchers.cpp
+2
-0
motion_estimators.cpp
modules/stitching/motion_estimators.cpp
+5
-3
No files found.
modules/stitching/main.cpp
View file @
eadb3bad
...
@@ -79,7 +79,7 @@ void printUsage()
...
@@ -79,7 +79,7 @@ void printUsage()
" Resolution for compositing step. Use -1 for original resolution.
\n
"
" Resolution for compositing step. Use -1 for original resolution.
\n
"
" The default is -1.
\n
"
" The default is -1.
\n
"
" --match_conf <float>
\n
"
" --match_conf <float>
\n
"
" Confidence for feature matching step. The default is 0.
6
.
\n
"
" Confidence for feature matching step. The default is 0.
7
.
\n
"
" --ba (ray|focal_ray)
\n
"
" --ba (ray|focal_ray)
\n
"
" Bundle adjustment cost function. The default is 'focal_ray'.
\n
"
" Bundle adjustment cost function. The default is 'focal_ray'.
\n
"
" --conf_thresh <float>
\n
"
" --conf_thresh <float>
\n
"
...
@@ -113,8 +113,7 @@ float conf_thresh = 1.f;
...
@@ -113,8 +113,7 @@ float conf_thresh = 1.f;
bool
wave_correct
=
true
;
bool
wave_correct
=
true
;
int
warp_type
=
Warper
::
SPHERICAL
;
int
warp_type
=
Warper
::
SPHERICAL
;
int
expos_comp_type
=
ExposureCompensator
::
GAIN
;
int
expos_comp_type
=
ExposureCompensator
::
GAIN
;
bool
user_match_conf
=
false
;
float
match_conf
=
0.7
f
;
float
match_conf
=
0.6
f
;
int
seam_find_type
=
SeamFinder
::
GC_COLOR
;
int
seam_find_type
=
SeamFinder
::
GC_COLOR
;
int
blend_type
=
Blender
::
MULTI_BAND
;
int
blend_type
=
Blender
::
MULTI_BAND
;
int
num_bands
=
5
;
int
num_bands
=
5
;
...
@@ -129,7 +128,12 @@ int parseCmdArgs(int argc, char** argv)
...
@@ -129,7 +128,12 @@ int parseCmdArgs(int argc, char** argv)
}
}
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
{
if
(
string
(
argv
[
i
])
==
"--preview"
)
if
(
string
(
argv
[
i
])
==
"--help"
||
string
(
argv
[
i
])
==
"/?"
)
{
printUsage
();
return
-
1
;
}
else
if
(
string
(
argv
[
i
])
==
"--preview"
)
{
{
preview
=
true
;
preview
=
true
;
}
}
...
@@ -168,7 +172,6 @@ int parseCmdArgs(int argc, char** argv)
...
@@ -168,7 +172,6 @@ int parseCmdArgs(int argc, char** argv)
}
}
else
if
(
string
(
argv
[
i
])
==
"--match_conf"
)
else
if
(
string
(
argv
[
i
])
==
"--match_conf"
)
{
{
user_match_conf
=
true
;
match_conf
=
static_cast
<
float
>
(
atof
(
argv
[
i
+
1
]));
match_conf
=
static_cast
<
float
>
(
atof
(
argv
[
i
+
1
]));
i
++
;
i
++
;
}
}
...
@@ -348,7 +351,7 @@ int main(int argc, char* argv[])
...
@@ -348,7 +351,7 @@ int main(int argc, char* argv[])
finder
(
img
,
features
[
i
]);
finder
(
img
,
features
[
i
]);
features
[
i
].
img_idx
=
i
;
features
[
i
].
img_idx
=
i
;
LOGLN
(
"Features in image #"
<<
i
<<
": "
<<
features
[
i
].
keypoints
.
size
());
LOGLN
(
"Features in image #"
<<
i
+
1
<<
": "
<<
features
[
i
].
keypoints
.
size
());
resize
(
full_img
,
img
,
Size
(),
seam_scale
,
seam_scale
);
resize
(
full_img
,
img
,
Size
(),
seam_scale
,
seam_scale
);
images
[
i
]
=
img
.
clone
();
images
[
i
]
=
img
.
clone
();
...
@@ -359,12 +362,10 @@ int main(int argc, char* argv[])
...
@@ -359,12 +362,10 @@ int main(int argc, char* argv[])
LOGLN
(
"Finding features, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
LOGLN
(
"Finding features, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
LOG
LN
(
"Pairwise matching...
"
);
LOG
(
"Pairwise matching
"
);
t
=
getTickCount
();
t
=
getTickCount
();
vector
<
MatchesInfo
>
pairwise_matches
;
vector
<
MatchesInfo
>
pairwise_matches
;
BestOf2NearestMatcher
matcher
(
try_gpu
);
BestOf2NearestMatcher
matcher
(
try_gpu
,
match_conf
);
if
(
user_match_conf
)
matcher
=
BestOf2NearestMatcher
(
try_gpu
,
match_conf
);
matcher
(
features
,
pairwise_matches
);
matcher
(
features
,
pairwise_matches
);
LOGLN
(
"Pairwise matching, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
LOGLN
(
"Pairwise matching, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
...
@@ -401,15 +402,25 @@ int main(int argc, char* argv[])
...
@@ -401,15 +402,25 @@ int main(int argc, char* argv[])
Mat
R
;
Mat
R
;
cameras
[
i
].
R
.
convertTo
(
R
,
CV_32F
);
cameras
[
i
].
R
.
convertTo
(
R
,
CV_32F
);
cameras
[
i
].
R
=
R
;
cameras
[
i
].
R
=
R
;
LOGLN
(
"Initial focal length #"
<<
i
<<
": "
<<
cameras
[
i
].
focal
);
LOGLN
(
"Initial focal length #"
<<
i
ndices
[
i
]
+
1
<<
": "
<<
cameras
[
i
].
focal
);
}
}
LOG
LN
(
"Bundle adjustment...
"
);
LOG
(
"Bundle adjustment
"
);
t
=
getTickCount
();
t
=
getTickCount
();
BundleAdjuster
adjuster
(
ba_space
,
conf_thresh
);
BundleAdjuster
adjuster
(
ba_space
,
conf_thresh
);
adjuster
(
features
,
pairwise_matches
,
cameras
);
adjuster
(
features
,
pairwise_matches
,
cameras
);
LOGLN
(
"Bundle adjustment, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
LOGLN
(
"Bundle adjustment, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
// Find median focal length
vector
<
double
>
focals
;
for
(
size_t
i
=
0
;
i
<
cameras
.
size
();
++
i
)
{
LOGLN
(
"Camera #"
<<
indices
[
i
]
+
1
<<
" focal length: "
<<
cameras
[
i
].
focal
);
focals
.
push_back
(
cameras
[
i
].
focal
);
}
nth_element
(
focals
.
begin
(),
focals
.
begin
()
+
focals
.
size
()
/
2
,
focals
.
end
());
float
warped_image_scale
=
static_cast
<
float
>
(
focals
[
focals
.
size
()
/
2
]);
if
(
wave_correct
)
if
(
wave_correct
)
{
{
LOGLN
(
"Wave correcting..."
);
LOGLN
(
"Wave correcting..."
);
...
@@ -423,16 +434,6 @@ int main(int argc, char* argv[])
...
@@ -423,16 +434,6 @@ int main(int argc, char* argv[])
LOGLN
(
"Wave correcting, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
LOGLN
(
"Wave correcting, time: "
<<
((
getTickCount
()
-
t
)
/
getTickFrequency
())
<<
" sec"
);
}
}
// Find median focal length
vector
<
double
>
focals
;
for
(
size_t
i
=
0
;
i
<
cameras
.
size
();
++
i
)
{
LOGLN
(
"Camera #"
<<
i
<<
" focal length: "
<<
cameras
[
i
].
focal
);
focals
.
push_back
(
cameras
[
i
].
focal
);
}
nth_element
(
focals
.
begin
(),
focals
.
begin
()
+
focals
.
size
()
/
2
,
focals
.
end
());
float
warped_image_scale
=
static_cast
<
float
>
(
focals
[
focals
.
size
()
/
2
]);
LOGLN
(
"Warping images (auxiliary)... "
);
LOGLN
(
"Warping images (auxiliary)... "
);
t
=
getTickCount
();
t
=
getTickCount
();
...
@@ -496,7 +497,7 @@ int main(int argc, char* argv[])
...
@@ -496,7 +497,7 @@ int main(int argc, char* argv[])
for
(
int
img_idx
=
0
;
img_idx
<
num_images
;
++
img_idx
)
for
(
int
img_idx
=
0
;
img_idx
<
num_images
;
++
img_idx
)
{
{
LOGLN
(
"Compositing image #"
<<
i
mg_idx
);
LOGLN
(
"Compositing image #"
<<
i
ndices
[
img_idx
]
+
1
);
// Read image and resize it if necessary
// Read image and resize it if necessary
full_img
=
imread
(
img_names
[
img_idx
]);
full_img
=
imread
(
img_names
[
img_idx
]);
...
...
modules/stitching/matchers.cpp
View file @
eadb3bad
...
@@ -219,6 +219,7 @@ struct MatchPairsBody
...
@@ -219,6 +219,7 @@ struct MatchPairsBody
for
(
size_t
j
=
0
;
j
<
pairwise_matches
[
dual_pair_idx
].
matches
.
size
();
++
j
)
for
(
size_t
j
=
0
;
j
<
pairwise_matches
[
dual_pair_idx
].
matches
.
size
();
++
j
)
swap
(
pairwise_matches
[
dual_pair_idx
].
matches
[
j
].
queryIdx
,
swap
(
pairwise_matches
[
dual_pair_idx
].
matches
[
j
].
queryIdx
,
pairwise_matches
[
dual_pair_idx
].
matches
[
j
].
trainIdx
);
pairwise_matches
[
dual_pair_idx
].
matches
[
j
].
trainIdx
);
LOG
(
"."
);
}
}
}
}
...
@@ -248,6 +249,7 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
...
@@ -248,6 +249,7 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
parallel_for
(
BlockedRange
(
0
,
static_cast
<
int
>
(
near_pairs
.
size
())),
body
);
parallel_for
(
BlockedRange
(
0
,
static_cast
<
int
>
(
near_pairs
.
size
())),
body
);
else
else
body
(
BlockedRange
(
0
,
static_cast
<
int
>
(
near_pairs
.
size
())));
body
(
BlockedRange
(
0
,
static_cast
<
int
>
(
near_pairs
.
size
())));
LOGLN
(
""
);
}
}
...
...
modules/stitching/motion_estimators.cpp
View file @
eadb3bad
...
@@ -198,14 +198,15 @@ void BundleAdjuster::estimate(const vector<ImageFeatures> &features, const vecto
...
@@ -198,14 +198,15 @@ void BundleAdjuster::estimate(const vector<ImageFeatures> &features, const vecto
if
(
_err
)
if
(
_err
)
{
{
calcError
(
err_
);
calcError
(
err_
);
LOG
LN
(
"Error: "
<<
sqrt
(
err_
.
dot
(
err_
))
);
LOG
(
"."
);
count
++
;
count
++
;
CvMat
matErr
=
err_
;
CvMat
matErr
=
err_
;
cvCopy
(
&
matErr
,
_err
);
cvCopy
(
&
matErr
,
_err
);
}
}
}
}
LOGLN
(
""
);
LOGLN
(
"Bundle adjustment, final error: "
<<
sqrt
(
err_
.
dot
(
err_
)));
LOGLN
(
"Bundle adjustment, final error: "
<<
sqrt
(
err_
.
dot
(
err_
)));
LOGLN
(
"Bundle adjustment, iteration done: "
<<
count
);
LOGLN
(
"Bundle adjustment, iteration
s
done: "
<<
count
);
// Obtain global motion
// Obtain global motion
for
(
int
i
=
0
;
i
<
num_images_
;
++
i
)
for
(
int
i
=
0
;
i
<
num_images_
;
++
i
)
...
@@ -432,7 +433,8 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
...
@@ -432,7 +433,8 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
LOG
(
"Removed some images, because can't match them: ("
);
LOG
(
"Removed some images, because can't match them: ("
);
LOG
(
indices_removed
[
0
]);
LOG
(
indices_removed
[
0
]);
for
(
size_t
i
=
1
;
i
<
indices_removed
.
size
();
++
i
)
LOG
(
", "
<<
indices_removed
[
i
]);
for
(
size_t
i
=
1
;
i
<
indices_removed
.
size
();
++
i
)
LOG
(
", "
<<
indices_removed
[
i
]
+
1
);
LOGLN
(
")"
);
LOGLN
(
")"
);
features
=
features_subset
;
features
=
features_subset
;
...
...
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