Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
6db3e956
Commit
6db3e956
authored
Feb 01, 2017
by
Vladislav Sovrasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reg: add support of different datatypes in Mapper::grid()
parent
d879ea48
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
14 deletions
+42
-14
mapper.cpp
modules/reg/src/mapper.cpp
+26
-9
test_reg.cpp
modules/reg/test/test_reg.cpp
+16
-5
No files found.
modules/reg/src/mapper.cpp
View file @
6db3e956
...
...
@@ -59,28 +59,45 @@ void Mapper::gradient(const Mat& img1, const Mat& img2, Mat& Ix, Mat& Iy, Mat& I
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void
Mapper
::
grid
(
const
Mat
&
img
,
Mat
&
grid_r
,
Mat
&
grid_c
)
const
template
<
typename
_Tp
>
void
fillGridMatrices
(
const
Mat
img
,
Mat
grid_r
,
Mat
grid_c
)
{
// Matrices with reference frame coordinates
grid_r
.
create
(
img
.
size
(),
img
.
type
());
grid_c
.
create
(
img
.
size
(),
img
.
type
());
if
(
img
.
channels
()
==
1
)
{
for
(
int
r_i
=
0
;
r_i
<
img
.
rows
;
++
r_i
)
{
for
(
int
c_i
=
0
;
c_i
<
img
.
cols
;
++
c_i
)
{
grid_r
.
at
<
double
>
(
r_i
,
c_i
)
=
r_i
;
grid_c
.
at
<
double
>
(
r_i
,
c_i
)
=
c_i
;
grid_r
.
at
<
_Tp
>
(
r_i
,
c_i
)
=
r_i
;
grid_c
.
at
<
_Tp
>
(
r_i
,
c_i
)
=
c_i
;
}
}
}
else
{
Vec
3d
ones
(
1.
,
1.
,
1.
);
Vec
<
_Tp
,
3
>
ones
(
1.
,
1.
,
1.
);
for
(
int
r_i
=
0
;
r_i
<
img
.
rows
;
++
r_i
)
{
for
(
int
c_i
=
0
;
c_i
<
img
.
cols
;
++
c_i
)
{
grid_r
.
at
<
Vec3d
>
(
r_i
,
c_i
)
=
r_i
*
ones
;
grid_c
.
at
<
Vec3d
>
(
r_i
,
c_i
)
=
c_i
*
ones
;
grid_r
.
at
<
Vec
<
_Tp
,
3
>
>
(
r_i
,
c_i
)
=
r_i
*
ones
;
grid_c
.
at
<
Vec
<
_Tp
,
3
>
>
(
r_i
,
c_i
)
=
c_i
*
ones
;
}
}
}
}
void
Mapper
::
grid
(
const
Mat
&
img
,
Mat
&
grid_r
,
Mat
&
grid_c
)
const
{
CV_DbgAssert
(
img
.
channels
()
==
1
||
img
.
channels
()
==
3
);
// Matrices with reference frame coordinates
grid_r
.
create
(
img
.
size
(),
img
.
type
());
grid_c
.
create
(
img
.
size
(),
img
.
type
());
if
(
img
.
depth
()
==
CV_8U
)
fillGridMatrices
<
uchar
>
(
img
,
grid_r
,
grid_c
);
if
(
img
.
depth
()
==
CV_16U
)
fillGridMatrices
<
ushort
>
(
img
,
grid_r
,
grid_c
);
else
if
(
img
.
depth
()
==
CV_32F
)
fillGridMatrices
<
float
>
(
img
,
grid_r
,
grid_c
);
else
if
(
img
.
depth
()
==
CV_64F
)
fillGridMatrices
<
double
>
(
img
,
grid_r
,
grid_c
);
}
}}
// namespace cv::reg
modules/reg/test/test_reg.cpp
View file @
6db3e956
...
...
@@ -63,7 +63,7 @@ using namespace cv::reg;
class
RegTest
:
public
testing
::
Test
{
public
:
void
loadImage
();
void
loadImage
(
int
dstDataType
=
CV_32FC3
);
void
testShift
();
void
testEuclidean
();
...
...
@@ -242,14 +242,13 @@ void RegTest::testProjective()
EXPECT_GE
(
projNorm
,
sqrt
(
3.
)
-
0.01
);
}
void
RegTest
::
loadImage
()
void
RegTest
::
loadImage
(
int
dstDataType
)
{
const
string
imageName
=
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"reg/home.png"
;
img1
=
imread
(
imageName
,
-
1
);
ASSERT_TRUE
(
img1
.
data
!=
0
);
// Convert to double, 3 channels
img1
.
convertTo
(
img1
,
CV_64FC3
);
ASSERT_TRUE
(
!
img1
.
empty
());
img1
.
convertTo
(
img1
,
dstDataType
);
}
...
...
@@ -282,3 +281,15 @@ TEST_F(RegTest, projective)
loadImage
();
testProjective
();
}
TEST_F
(
RegTest
,
projective_dt64fc3
)
{
loadImage
(
CV_64FC3
);
testProjective
();
}
TEST_F
(
RegTest
,
projective_dt64fc1
)
{
loadImage
(
CV_64FC1
);
testProjective
();
}
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