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
4567b432
Commit
4567b432
authored
May 18, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduced memory requirements in opencv_stitching
parent
71ca501b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
40 deletions
+34
-40
autocalib.cpp
modules/stitching/autocalib.cpp
+1
-1
blenders.cpp
modules/stitching/blenders.cpp
+11
-19
blenders.hpp
modules/stitching/blenders.hpp
+0
-2
main.cpp
modules/stitching/main.cpp
+13
-9
motion_estimators.cpp
modules/stitching/motion_estimators.cpp
+7
-7
motion_estimators.hpp
modules/stitching/motion_estimators.hpp
+2
-2
No files found.
modules/stitching/autocalib.cpp
View file @
4567b432
...
...
@@ -56,7 +56,7 @@ double estimateFocal(const vector<Mat> &images, const vector<ImageFeatures> &/*f
}
}
if
(
focals
.
size
()
+
1
>=
images
.
size
(
))
if
(
focals
.
size
()
>=
2
*
(
num_images
-
1
))
{
nth_element
(
focals
.
begin
(),
focals
.
end
(),
focals
.
begin
()
+
focals
.
size
()
/
2
);
return
focals
[
focals
.
size
()
/
2
];
...
...
modules/stitching/blenders.cpp
View file @
4567b432
...
...
@@ -133,19 +133,20 @@ Point MultiBandBlender::blend(const vector<Mat> &src, const vector<Point> &corne
int
left
=
corners
[
img_idx
].
x
-
dst_roi
.
x
;
int
right
=
dst_roi
.
br
().
x
-
corners
[
img_idx
].
x
-
src
[
img_idx
].
cols
;
Mat
big_src
;
copyMakeBorder
(
src
[
img_idx
],
big_src
,
top
,
bottom
,
left
,
right
,
BORDER_REFLECT
);
vector
<
Mat
>
src_pyr_gauss
;
vector
<
Mat
>
src_pyr_gauss
(
num_bands_
+
1
);
copyMakeBorder
(
src
[
img_idx
],
src_pyr_gauss
[
0
],
top
,
bottom
,
left
,
right
,
BORDER_REFLECT
);
for
(
int
i
=
0
;
i
<
num_bands_
;
++
i
)
pyrDown
(
src_pyr_gauss
[
i
],
src_pyr_gauss
[
i
+
1
]);
vector
<
Mat
>
src_pyr_laplace
;
createGaussPyr
(
big_src
,
num_bands_
,
src_pyr_gauss
);
createLaplacePyr
(
src_pyr_gauss
,
src_pyr_laplace
);
Mat
big_mask
;
copyMakeBorder
(
masks
[
img_idx
],
big_mask
,
top
,
bottom
,
left
,
right
,
BORDER_CONSTANT
)
;
Mat
weight_map
;
big_mask
.
convertTo
(
weight_map
,
CV_32F
,
1.
/
255.
);
vector
<
Mat
>
weight_pyr_gauss
;
createGaussPyr
(
weight_map
,
num_bands_
,
weight_pyr_gauss
);
vector
<
Mat
>
weight_pyr_gauss
(
num_bands_
+
1
)
;
Mat
mask_f
;
masks
[
img_idx
].
convertTo
(
mask_f
,
CV_32F
,
1.
/
255.
)
;
copyMakeBorder
(
mask_f
,
weight_pyr_gauss
[
0
],
top
,
bottom
,
left
,
right
,
BORDER_CONSTANT
);
for
(
int
i
=
0
;
i
<
num_bands_
;
++
i
)
pyrDown
(
weight_pyr_gauss
[
i
],
weight_pyr_gauss
[
i
+
1
]
);
for
(
int
band_idx
=
0
;
band_idx
<=
num_bands_
;
++
band_idx
)
{
...
...
@@ -286,15 +287,6 @@ void createWeightMap(const Mat &mask, float sharpness, Mat &weight)
}
void
createGaussPyr
(
const
Mat
&
img
,
int
num_layers
,
vector
<
Mat
>
&
pyr
)
{
pyr
.
resize
(
num_layers
+
1
);
pyr
[
0
]
=
img
.
clone
();
for
(
int
i
=
0
;
i
<
num_layers
;
++
i
)
pyrDown
(
pyr
[
i
],
pyr
[
i
+
1
]);
}
void
createLaplacePyr
(
const
vector
<
Mat
>
&
pyr_gauss
,
vector
<
Mat
>
&
pyr_laplace
)
{
if
(
pyr_gauss
.
size
()
==
0
)
...
...
modules/stitching/blenders.hpp
View file @
4567b432
...
...
@@ -63,8 +63,6 @@ void normalize(const cv::Mat& weight, cv::Mat& src);
void
createWeightMap
(
const
cv
::
Mat
&
mask
,
float
sharpness
,
cv
::
Mat
&
weight
);
void
createGaussPyr
(
const
cv
::
Mat
&
img
,
int
num_layers
,
std
::
vector
<
cv
::
Mat
>&
pyr
);
void
createLaplacePyr
(
const
std
::
vector
<
cv
::
Mat
>&
pyr_gauss
,
std
::
vector
<
cv
::
Mat
>&
pyr_laplace
);
// Restores source image in-place. Result will be stored in pyr[0].
...
...
modules/stitching/main.cpp
View file @
4567b432
...
...
@@ -35,8 +35,8 @@ int main(int argc, char* argv[])
vector
<
string
>
img_names
;
vector
<
Mat
>
images
;
bool
trygpu
=
true
;
double
work_megapix
=
-
1
;
double
compose_megapix
=
-
1
;
double
work_megapix
=
1
;
double
compose_megapix
=
1
;
int
ba_space
=
BundleAdjuster
::
FOCAL_RAY_SPACE
;
float
conf_thresh
=
1.
f
;
bool
wave_correct
=
true
;
...
...
@@ -47,8 +47,8 @@ int main(int argc, char* argv[])
int
blend_type
=
Blender
::
MULTI_BAND
;
string
result_name
=
"result.png"
;
double
work_scale
=
1
,
compose_scale
=
1
;
bool
is_work_scale_set
=
false
,
is_compose_scale_set
=
tru
e
;
double
work_scale
,
compose_scale
;
bool
is_work_scale_set
=
false
,
is_compose_scale_set
=
fals
e
;
if
(
argc
==
1
)
{
...
...
@@ -85,7 +85,6 @@ int main(int argc, char* argv[])
else
if
(
string
(
argv
[
i
])
==
"--compose_megapix"
)
{
compose_megapix
=
atof
(
argv
[
i
+
1
]);
is_compose_scale_set
=
false
;
i
++
;
}
else
if
(
string
(
argv
[
i
])
==
"--result"
)
...
...
@@ -195,7 +194,7 @@ int main(int argc, char* argv[])
{
if
(
!
is_work_scale_set
)
{
work_scale
=
min
(
1.0
,
sqrt
(
work_megapix
*
1
000000
/
full_img
.
size
().
area
()));
work_scale
=
min
(
1.0
,
sqrt
(
work_megapix
*
1
e6
/
full_img
.
size
().
area
()));
is_work_scale_set
=
true
;
}
Mat
img
;
...
...
@@ -224,7 +223,11 @@ int main(int argc, char* argv[])
matcher
=
BestOf2NearestMatcher
(
true
,
match_conf
);
matcher
(
images
,
features
,
pairwise_matches
);
leaveBiggestComponent
(
images
,
features
,
pairwise_matches
,
conf_thresh
);
vector
<
int
>
indices
=
leaveBiggestComponent
(
images
,
features
,
pairwise_matches
,
conf_thresh
);
vector
<
string
>
img_names_subset
;
for
(
size_t
i
=
0
;
i
<
indices
.
size
();
++
i
)
img_names_subset
.
push_back
(
img_names
[
indices
[
i
]]);
img_names
=
img_names_subset
;
num_images
=
static_cast
<
int
>
(
images
.
size
());
if
(
num_images
<
2
)
...
...
@@ -271,14 +274,15 @@ int main(int argc, char* argv[])
nth_element
(
focals
.
begin
(),
focals
.
end
(),
focals
.
begin
()
+
focals
.
size
()
/
2
);
float
camera_focal
=
static_cast
<
float
>
(
focals
[
focals
.
size
()
/
2
]);
if
(
work_megapix
>
0
||
compose_megapix
>
0
)
if
((
work_megapix
>
0
||
compose_megapix
>
0
)
&&
abs
(
work_megapix
-
compose_megapix
)
>
1e-3
)
{
for
(
int
i
=
0
;
i
<
num_images
;
++
i
)
{
Mat
full_img
=
imread
(
img_names
[
i
]);
if
(
!
is_compose_scale_set
)
{
compose_scale
=
min
(
1.0
,
sqrt
(
compose_megapix
*
1
000000
/
full_img
.
size
().
area
()));
compose_scale
=
min
(
1.0
,
sqrt
(
compose_megapix
*
1
e6
/
full_img
.
size
().
area
()));
is_compose_scale_set
=
true
;
}
Mat
img
;
...
...
modules/stitching/motion_estimators.cpp
View file @
4567b432
...
...
@@ -328,8 +328,7 @@ void waveCorrect(vector<Mat> &rmats)
SVD
svd
;
svd
(
cov
,
SVD
::
FULL_UV
);
svd
.
vt
.
row
(
2
).
copyTo
(
r1
);
if
(
determinant
(
svd
.
vt
)
<
0
)
r1
*=
-
1
;
if
(
determinant
(
svd
.
vt
)
<
0
)
r1
*=
-
1
;
Mat
avgz
=
Mat
::
zeros
(
3
,
1
,
CV_32F
);
for
(
size_t
i
=
0
;
i
<
rmats
.
size
();
++
i
)
...
...
@@ -338,8 +337,7 @@ void waveCorrect(vector<Mat> &rmats)
normalize
(
r0
,
r0
);
r1
.
cross
(
r0
).
copyTo
(
r2
);
if
(
determinant
(
R
)
<
0
)
R
*=
-
1
;
if
(
determinant
(
R
)
<
0
)
R
*=
-
1
;
for
(
size_t
i
=
0
;
i
<
rmats
.
size
();
++
i
)
rmats
[
i
]
=
R
*
rmats
[
i
];
...
...
@@ -348,8 +346,8 @@ void waveCorrect(vector<Mat> &rmats)
//////////////////////////////////////////////////////////////////////////////
v
oid
leaveBiggestComponent
(
vector
<
Mat
>
&
images
,
vector
<
ImageFeatures
>
&
features
,
vector
<
MatchesInfo
>
&
pairwise_matches
,
float
conf_threshold
)
v
ector
<
int
>
leaveBiggestComponent
(
vector
<
Mat
>
&
images
,
vector
<
ImageFeatures
>
&
features
,
vector
<
MatchesInfo
>
&
pairwise_matches
,
float
conf_threshold
)
{
const
int
num_images
=
static_cast
<
int
>
(
images
.
size
());
...
...
@@ -393,7 +391,7 @@ void leaveBiggestComponent(vector<Mat> &images, vector<ImageFeatures> &features,
}
if
(
static_cast
<
int
>
(
images_subset
.
size
())
==
num_images
)
return
;
return
indices
;
LOG
(
"Removed some images, because can't match them: ("
);
LOG
(
indices_removed
[
0
]);
...
...
@@ -403,6 +401,8 @@ void leaveBiggestComponent(vector<Mat> &images, vector<ImageFeatures> &features,
images
=
images_subset
;
features
=
features_subset
;
pairwise_matches
=
pairwise_matches_subset
;
return
indices
;
}
...
...
modules/stitching/motion_estimators.hpp
View file @
4567b432
...
...
@@ -83,8 +83,8 @@ void waveCorrect(std::vector<cv::Mat> &rmats);
//////////////////////////////////////////////////////////////////////////////
// Auxiliary functions
void
leaveBiggestComponent
(
std
::
vector
<
cv
::
Mat
>
&
images
,
std
::
vector
<
ImageFeatures
>
&
features
,
std
::
vector
<
MatchesInfo
>
&
pairwise_matches
,
float
conf_threshold
);
std
::
vector
<
int
>
leaveBiggestComponent
(
std
::
vector
<
cv
::
Mat
>
&
images
,
std
::
vector
<
ImageFeatures
>
&
features
,
std
::
vector
<
MatchesInfo
>
&
pairwise_matches
,
float
conf_threshold
);
void
findMaxSpanningTree
(
int
num_images
,
const
std
::
vector
<
MatchesInfo
>
&
pairwise_matches
,
Graph
&
span_tree
,
std
::
vector
<
int
>
&
centers
);
...
...
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