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
f44632ee
Commit
f44632ee
authored
May 23, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switched float with short in blending step (opencv_stitching)
parent
5bf8109d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
23 deletions
+37
-23
pyramids.cpp
modules/imgproc/src/pyramids.cpp
+4
-0
autocalib.cpp
modules/stitching/autocalib.cpp
+1
-1
blenders.cpp
modules/stitching/blenders.cpp
+29
-18
main.cpp
modules/stitching/main.cpp
+3
-4
No files found.
modules/imgproc/src/pyramids.cpp
View file @
f44632ee
...
...
@@ -411,6 +411,8 @@ void cv::pyrDown( const InputArray& _src, OutputArray _dst, const Size& _dsz )
PyrFunc
func
=
0
;
if
(
depth
==
CV_8U
)
func
=
pyrDown_
<
FixPtCast
<
uchar
,
8
>
,
PyrDownVec_32s8u
>
;
else
if
(
depth
==
CV_16S
)
func
=
pyrDown_
<
FixPtCast
<
short
,
8
>
,
NoVec
<
int
,
short
>
>
;
else
if
(
depth
==
CV_16U
)
func
=
pyrDown_
<
FixPtCast
<
ushort
,
8
>
,
NoVec
<
int
,
ushort
>
>
;
else
if
(
depth
==
CV_32F
)
...
...
@@ -433,6 +435,8 @@ void cv::pyrUp( const InputArray& _src, OutputArray _dst, const Size& _dsz )
PyrFunc
func
=
0
;
if
(
depth
==
CV_8U
)
func
=
pyrUp_
<
FixPtCast
<
uchar
,
6
>
,
NoVec
<
int
,
uchar
>
>
;
else
if
(
depth
==
CV_16S
)
func
=
pyrUp_
<
FixPtCast
<
short
,
6
>
,
NoVec
<
int
,
short
>
>
;
else
if
(
depth
==
CV_16U
)
func
=
pyrUp_
<
FixPtCast
<
ushort
,
6
>
,
NoVec
<
int
,
ushort
>
>
;
else
if
(
depth
==
CV_32F
)
...
...
modules/stitching/autocalib.cpp
View file @
f44632ee
...
...
@@ -96,7 +96,7 @@ double estimateFocal(const vector<ImageFeatures> &features, const vector<Matches
}
}
if
(
static_cast
<
int
>
(
focals
.
size
())
>=
2
*
(
num_images
-
1
)
)
if
(
static_cast
<
int
>
(
focals
.
size
())
>=
num_images
*
(
num_images
-
1
)
/
2
)
{
nth_element
(
focals
.
begin
(),
focals
.
end
(),
focals
.
begin
()
+
focals
.
size
()
/
2
);
return
focals
[
focals
.
size
()
/
2
];
...
...
modules/stitching/blenders.cpp
View file @
f44632ee
...
...
@@ -68,7 +68,7 @@ void Blender::prepare(const vector<Point> &corners, const vector<Size> &sizes)
void
Blender
::
prepare
(
Rect
dst_roi
)
{
dst_
.
create
(
dst_roi
.
size
(),
CV_
32F
C3
);
dst_
.
create
(
dst_roi
.
size
(),
CV_
16S
C3
);
dst_
.
setTo
(
Scalar
::
all
(
0
));
dst_mask_
.
create
(
dst_roi
.
size
(),
CV_8U
);
dst_mask_
.
setTo
(
Scalar
::
all
(
0
));
...
...
@@ -78,7 +78,7 @@ void Blender::prepare(Rect dst_roi)
void
Blender
::
feed
(
const
Mat
&
img
,
const
Mat
&
mask
,
Point
tl
)
{
CV_Assert
(
img
.
type
()
==
CV_
32F
C3
);
CV_Assert
(
img
.
type
()
==
CV_
16S
C3
);
CV_Assert
(
mask
.
type
()
==
CV_8U
);
int
dx
=
tl
.
x
-
dst_roi_
.
x
;
...
...
@@ -86,8 +86,8 @@ void Blender::feed(const Mat &img, const Mat &mask, Point tl)
for
(
int
y
=
0
;
y
<
img
.
rows
;
++
y
)
{
const
Point3
f
*
src_row
=
img
.
ptr
<
Point3f
>
(
y
);
Point3
f
*
dst_row
=
dst_
.
ptr
<
Point3f
>
(
dy
+
y
);
const
Point3
_
<
short
>
*
src_row
=
img
.
ptr
<
Point3_
<
short
>
>
(
y
);
Point3
_
<
short
>
*
dst_row
=
dst_
.
ptr
<
Point3_
<
short
>
>
(
dy
+
y
);
const
uchar
*
mask_row
=
mask
.
ptr
<
uchar
>
(
y
);
uchar
*
dst_mask_row
=
dst_mask_
.
ptr
<
uchar
>
(
dy
+
y
);
...
...
@@ -122,7 +122,7 @@ void FeatherBlender::prepare(Rect dst_roi)
void
FeatherBlender
::
feed
(
const
Mat
&
img
,
const
Mat
&
mask
,
Point
tl
)
{
CV_Assert
(
img
.
type
()
==
CV_
32F
C3
);
CV_Assert
(
img
.
type
()
==
CV_
16S
C3
);
CV_Assert
(
mask
.
type
()
==
CV_8U
);
int
dx
=
tl
.
x
-
dst_roi_
.
x
;
...
...
@@ -132,15 +132,17 @@ void FeatherBlender::feed(const Mat &img, const Mat &mask, Point tl)
for
(
int
y
=
0
;
y
<
img
.
rows
;
++
y
)
{
const
Point3
f
*
src_row
=
img
.
ptr
<
Point3f
>
(
y
);
Point3
f
*
dst_row
=
dst_
.
ptr
<
Point3f
>
(
dy
+
y
);
const
Point3
_
<
short
>*
src_row
=
img
.
ptr
<
Point3_
<
short
>
>
(
y
);
Point3
_
<
short
>*
dst_row
=
dst_
.
ptr
<
Point3_
<
short
>
>
(
dy
+
y
);
const
float
*
weight_row
=
weight_map_
.
ptr
<
float
>
(
y
);
float
*
dst_weight_row
=
dst_weight_map_
.
ptr
<
float
>
(
dy
+
y
);
for
(
int
x
=
0
;
x
<
img
.
cols
;
++
x
)
{
dst_row
[
dx
+
x
]
+=
src_row
[
x
]
*
weight_row
[
x
];
dst_row
[
dx
+
x
].
x
+=
static_cast
<
short
>
(
src_row
[
x
].
x
*
weight_row
[
x
]);
dst_row
[
dx
+
x
].
y
+=
static_cast
<
short
>
(
src_row
[
x
].
y
*
weight_row
[
x
]);
dst_row
[
dx
+
x
].
z
+=
static_cast
<
short
>
(
src_row
[
x
].
z
*
weight_row
[
x
]);
dst_weight_row
[
dx
+
x
]
+=
weight_row
[
x
];
}
}
...
...
@@ -169,7 +171,7 @@ void MultiBandBlender::prepare(Rect dst_roi)
for
(
int
i
=
1
;
i
<=
num_bands_
;
++
i
)
{
dst_pyr_laplace_
[
i
].
create
((
dst_pyr_laplace_
[
i
-
1
].
rows
+
1
)
/
2
,
(
dst_pyr_laplace_
[
i
-
1
].
cols
+
1
)
/
2
,
CV_
32F
C3
);
(
dst_pyr_laplace_
[
i
-
1
].
cols
+
1
)
/
2
,
CV_
16S
C3
);
dst_band_weights_
[
i
].
create
((
dst_band_weights_
[
i
-
1
].
rows
+
1
)
/
2
,
(
dst_band_weights_
[
i
-
1
].
cols
+
1
)
/
2
,
CV_32F
);
dst_pyr_laplace_
[
i
].
setTo
(
Scalar
::
all
(
0
));
...
...
@@ -180,7 +182,7 @@ void MultiBandBlender::prepare(Rect dst_roi)
void
MultiBandBlender
::
feed
(
const
Mat
&
img
,
const
Mat
&
mask
,
Point
tl
)
{
CV_Assert
(
img
.
type
()
==
CV_
32F
C3
);
CV_Assert
(
img
.
type
()
==
CV_
16S
C3
);
CV_Assert
(
mask
.
type
()
==
CV_8U
);
int
top
=
tl
.
y
-
dst_roi_
.
y
;
...
...
@@ -212,13 +214,17 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
{
for
(
int
y
=
0
;
y
<
dst_pyr_laplace_
[
i
].
rows
;
++
y
)
{
const
Point3
f
*
src_row
=
src_pyr_laplace
[
i
].
ptr
<
Point3f
>
(
y
);
Point3
f
*
dst_row
=
dst_pyr_laplace_
[
i
].
ptr
<
Point3f
>
(
y
);
const
Point3
_
<
short
>*
src_row
=
src_pyr_laplace
[
i
].
ptr
<
Point3_
<
short
>
>
(
y
);
Point3
_
<
short
>*
dst_row
=
dst_pyr_laplace_
[
i
].
ptr
<
Point3_
<
short
>
>
(
y
);
const
float
*
weight_row
=
weight_pyr_gauss
[
i
].
ptr
<
float
>
(
y
);
for
(
int
x
=
0
;
x
<
dst_pyr_laplace_
[
i
].
cols
;
++
x
)
dst_row
[
x
]
+=
src_row
[
x
]
*
weight_row
[
x
];
{
dst_row
[
x
].
x
+=
static_cast
<
short
>
(
src_row
[
x
].
x
*
weight_row
[
x
]);
dst_row
[
x
].
y
+=
static_cast
<
short
>
(
src_row
[
x
].
y
*
weight_row
[
x
]);
dst_row
[
x
].
z
+=
static_cast
<
short
>
(
src_row
[
x
].
z
*
weight_row
[
x
]);
}
}
dst_band_weights_
[
i
]
+=
weight_pyr_gauss
[
i
];
}
...
...
@@ -265,14 +271,18 @@ Rect resultRoi(const vector<Point> &corners, const vector<Size> &sizes)
void
normalize
(
const
Mat
&
weight
,
Mat
&
src
)
{
CV_Assert
(
weight
.
type
()
==
CV_32F
);
CV_Assert
(
src
.
type
()
==
CV_
32F
C3
);
CV_Assert
(
src
.
type
()
==
CV_
16S
C3
);
for
(
int
y
=
0
;
y
<
src
.
rows
;
++
y
)
{
Point3
f
*
row
=
src
.
ptr
<
Point3f
>
(
y
);
Point3
_
<
short
>
*
row
=
src
.
ptr
<
Point3_
<
short
>
>
(
y
);
const
float
*
weight_row
=
weight
.
ptr
<
float
>
(
y
);
for
(
int
x
=
0
;
x
<
src
.
cols
;
++
x
)
row
[
x
]
*=
1.
f
/
(
weight_row
[
x
]
+
WEIGHT_EPS
);
{
row
[
x
].
x
=
static_cast
<
short
>
(
row
[
x
].
x
/
(
weight_row
[
x
]
+
WEIGHT_EPS
));
row
[
x
].
y
=
static_cast
<
short
>
(
row
[
x
].
y
/
(
weight_row
[
x
]
+
WEIGHT_EPS
));
row
[
x
].
z
=
static_cast
<
short
>
(
row
[
x
].
z
/
(
weight_row
[
x
]
+
WEIGHT_EPS
));
}
}
}
...
...
@@ -296,7 +306,7 @@ void createLaplacePyr(const vector<Mat> &pyr_gauss, vector<Mat> &pyr_laplace)
for
(
size_t
i
=
0
;
i
<
pyr_laplace
.
size
()
-
1
;
++
i
)
{
pyrUp
(
pyr_gauss
[
i
+
1
],
tmp
,
pyr_gauss
[
i
].
size
());
pyr_laplace
[
i
]
=
pyr_gauss
[
i
]
-
tmp
;
subtract
(
pyr_gauss
[
i
],
tmp
,
pyr_laplace
[
i
])
;
}
pyr_laplace
[
pyr_laplace
.
size
()
-
1
]
=
pyr_gauss
[
pyr_laplace
.
size
()
-
1
].
clone
();
}
...
...
@@ -311,6 +321,7 @@ void restoreImageFromLaplacePyr(vector<Mat> &pyr)
for
(
size_t
i
=
pyr
.
size
()
-
1
;
i
>
0
;
--
i
)
{
pyrUp
(
pyr
[
i
],
tmp
,
pyr
[
i
-
1
].
size
());
pyr
[
i
-
1
]
+=
tmp
;
add
(
tmp
,
pyr
[
i
-
1
],
pyr
[
i
-
1
])
;
}
}
modules/stitching/main.cpp
View file @
f44632ee
...
...
@@ -401,7 +401,6 @@ int main(int argc, char* argv[])
cameras
[
i
].
R
,
masks_warped
[
i
],
INTER_NEAREST
,
BORDER_CONSTANT
);
}
// Convert to float for blending
vector
<
Mat
>
images_warped_f
(
num_images
);
for
(
int
i
=
0
;
i
<
num_images
;
++
i
)
images_warped
[
i
].
convertTo
(
images_warped_f
[
i
],
CV_32F
);
...
...
@@ -426,7 +425,7 @@ int main(int argc, char* argv[])
LOGLN
(
"Compositing..."
);
t
=
getTickCount
();
Mat
img_warped
,
img_warped_
f
;
Mat
img_warped
,
img_warped_
s
;
Mat
dilated_mask
,
seam_mask
,
mask
,
mask_warped
;
Ptr
<
Blender
>
blender
;
double
compose_seam_aspect
=
1
;
...
...
@@ -461,7 +460,7 @@ int main(int argc, char* argv[])
// Warp the current image
warper
->
warp
(
img
,
static_cast
<
float
>
(
cameras
[
img_idx
].
focal
),
cameras
[
img_idx
].
R
,
img_warped
);
img_warped
.
convertTo
(
img_warped_
f
,
CV_32F
);
img_warped
.
convertTo
(
img_warped_
s
,
CV_16S
);
img_warped
.
release
();
img
.
release
();
...
...
@@ -497,7 +496,7 @@ int main(int argc, char* argv[])
}
// Blend the current image
blender
->
feed
(
img_warped_
f
,
mask_warped
,
corners
[
img_idx
]);
blender
->
feed
(
img_warped_
s
,
mask_warped
,
corners
[
img_idx
]);
}
Mat
result
,
result_mask
;
...
...
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