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
024be9b8
Commit
024be9b8
authored
Oct 11, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9818 from tz70s:issue#9570
parents
8b168175
6c1247b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
mat.inl.hpp
modules/core/include/opencv2/core/mat.inl.hpp
+28
-0
test_mat.cpp
modules/core/test/test_mat.cpp
+20
-0
No files found.
modules/core/include/opencv2/core/mat.inl.hpp
View file @
024be9b8
...
...
@@ -1058,6 +1058,34 @@ const uchar* Mat::ptr(const int* idx) const
return
p
;
}
template
<
typename
_Tp
>
inline
_Tp
*
Mat
::
ptr
(
const
int
*
idx
)
{
int
i
,
d
=
dims
;
uchar
*
p
=
data
;
CV_DbgAssert
(
d
>=
1
&&
p
);
for
(
i
=
0
;
i
<
d
;
i
++
)
{
CV_DbgAssert
(
(
unsigned
)
idx
[
i
]
<
(
unsigned
)
size
.
p
[
i
]
);
p
+=
idx
[
i
]
*
step
.
p
[
i
];
}
return
(
_Tp
*
)
p
;
}
template
<
typename
_Tp
>
inline
const
_Tp
*
Mat
::
ptr
(
const
int
*
idx
)
const
{
int
i
,
d
=
dims
;
uchar
*
p
=
data
;
CV_DbgAssert
(
d
>=
1
&&
p
);
for
(
i
=
0
;
i
<
d
;
i
++
)
{
CV_DbgAssert
(
(
unsigned
)
idx
[
i
]
<
(
unsigned
)
size
.
p
[
i
]
);
p
+=
idx
[
i
]
*
step
.
p
[
i
];
}
return
(
const
_Tp
*
)
p
;
}
template
<
typename
_Tp
>
inline
_Tp
&
Mat
::
at
(
int
i0
,
int
i1
)
{
...
...
modules/core/test/test_mat.cpp
View file @
024be9b8
...
...
@@ -1804,4 +1804,24 @@ TEST(Mat_, from_initializer_list)
ASSERT_DOUBLE_EQ
(
norm
(
A
,
B
,
NORM_INF
),
0.
);
}
TEST
(
Mat
,
template_based_ptr
)
{
Mat
mat
=
(
Mat_
<
float
>
(
2
,
2
)
<<
11.0
f
,
22.0
f
,
33.0
f
,
44.0
f
);
int
idx
[
2
]
=
{
1
,
0
};
ASSERT_FLOAT_EQ
(
33.0
f
,
*
(
mat
.
ptr
<
float
>
(
idx
)));
idx
[
0
]
=
1
;
idx
[
1
]
=
1
;
ASSERT_FLOAT_EQ
(
44.0
f
,
*
(
mat
.
ptr
<
float
>
(
idx
)));
}
TEST
(
Mat_
,
template_based_ptr
)
{
int
dim
[
4
]
=
{
2
,
2
,
1
,
2
};
Mat_
<
float
>
mat
=
(
Mat_
<
float
>
(
4
,
dim
)
<<
11.0
f
,
22.0
f
,
33.0
f
,
44.0
f
,
55.0
f
,
66.0
f
,
77.0
f
,
88.0
f
);
int
idx
[
4
]
=
{
1
,
0
,
0
,
1
};
ASSERT_FLOAT_EQ
(
66.0
f
,
*
(
mat
.
ptr
<
float
>
(
idx
)));
}
#endif
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