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
a1230ad0
Commit
a1230ad0
authored
Mar 12, 2020
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16796 from anton-potapov:kw_fixes_own_mat_total_overflow
parents
448a5452
d3b68b05
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
9 deletions
+14
-9
mat.hpp
modules/gapi/include/opencv2/gapi/own/mat.hpp
+3
-4
mat_tests.cpp
modules/gapi/test/own/mat_tests.cpp
+11
-5
No files found.
modules/gapi/include/opencv2/gapi/own/mat.hpp
View file @
a1230ad0
...
@@ -297,10 +297,9 @@ namespace cv { namespace gapi { namespace own {
...
@@ -297,10 +297,9 @@ namespace cv { namespace gapi { namespace own {
*/
*/
size_t
total
()
const
size_t
total
()
const
{
{
return
static_cast
<
std
::
size_t
>
return
dims
.
empty
()
(
dims
.
empty
()
?
(
static_cast
<
std
::
size_t
>
(
rows
)
*
cols
)
?
(
rows
*
cols
)
:
std
::
accumulate
(
dims
.
begin
(),
dims
.
end
(),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
size_t
>
());
:
std
::
accumulate
(
dims
.
begin
(),
dims
.
end
(),
1
,
std
::
multiplies
<
int
>
()));
}
}
/** @overload
/** @overload
...
...
modules/gapi/test/own/mat_tests.cpp
View file @
a1230ad0
...
@@ -14,6 +14,12 @@ namespace opencv_test
...
@@ -14,6 +14,12 @@ namespace opencv_test
using
Mat
=
cv
::
gapi
::
own
::
Mat
;
using
Mat
=
cv
::
gapi
::
own
::
Mat
;
using
Dims
=
std
::
vector
<
int
>
;
using
Dims
=
std
::
vector
<
int
>
;
namespace
{
inline
std
::
size_t
multiply_dims
(
Dims
const
&
dims
){
return
std
::
accumulate
(
dims
.
begin
(),
dims
.
end
(),
static_cast
<
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
());
}
}
TEST
(
OwnMat
,
DefaultConstruction
)
TEST
(
OwnMat
,
DefaultConstruction
)
{
{
Mat
m
;
Mat
m
;
...
@@ -74,7 +80,7 @@ TEST(OwnMat, CreateOverload)
...
@@ -74,7 +80,7 @@ TEST(OwnMat, CreateOverload)
ASSERT_NE
(
m
.
data
,
nullptr
);
ASSERT_NE
(
m
.
data
,
nullptr
);
ASSERT_EQ
((
cv
::
Size
{
m
.
cols
,
m
.
rows
}),
size
);
ASSERT_EQ
((
cv
::
Size
{
m
.
cols
,
m
.
rows
}),
size
);
ASSERT_EQ
(
m
.
total
(),
static_cast
<
size_t
>
(
size
.
height
*
size
.
width
)
);
ASSERT_EQ
(
m
.
total
(),
static_cast
<
size_t
>
(
size
.
height
)
*
size
.
width
);
ASSERT_EQ
(
m
.
type
(),
CV_8UC1
);
ASSERT_EQ
(
m
.
type
(),
CV_8UC1
);
ASSERT_EQ
(
m
.
depth
(),
CV_8U
);
ASSERT_EQ
(
m
.
depth
(),
CV_8U
);
ASSERT_EQ
(
m
.
channels
(),
1
);
ASSERT_EQ
(
m
.
channels
(),
1
);
...
@@ -371,7 +377,7 @@ TEST(OwnMat, CopyNDtoRegular)
...
@@ -371,7 +377,7 @@ TEST(OwnMat, CopyNDtoRegular)
ASSERT_NE
(
nullptr
,
a
.
data
);
ASSERT_NE
(
nullptr
,
a
.
data
);
ASSERT_EQ
(
sz
,
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
(
sz
,
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
(
static_cast
<
size_t
>
(
sz
.
width
*
sz
.
height
)
,
a
.
total
());
ASSERT_EQ
(
static_cast
<
size_t
>
(
sz
.
width
)
*
sz
.
height
,
a
.
total
());
ASSERT_EQ
(
CV_8U
,
a
.
type
());
ASSERT_EQ
(
CV_8U
,
a
.
type
());
ASSERT_EQ
(
CV_8U
,
a
.
depth
());
ASSERT_EQ
(
CV_8U
,
a
.
depth
());
ASSERT_EQ
(
1
,
a
.
channels
());
ASSERT_EQ
(
1
,
a
.
channels
());
...
@@ -387,7 +393,7 @@ TEST(OwnMat, CopyNDtoRegular)
...
@@ -387,7 +393,7 @@ TEST(OwnMat, CopyNDtoRegular)
ASSERT_NE
(
old_ptr
,
a
.
data
);
ASSERT_NE
(
old_ptr
,
a
.
data
);
ASSERT_NE
(
b
.
data
,
a
.
data
);
ASSERT_NE
(
b
.
data
,
a
.
data
);
ASSERT_EQ
((
cv
::
gapi
::
own
::
Size
{
0
,
0
}),
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
((
cv
::
gapi
::
own
::
Size
{
0
,
0
}),
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
(
static_cast
<
size_t
>
(
dims
[
0
]
*
dims
[
1
]
*
dims
[
2
]
*
dims
[
3
]
),
a
.
total
());
ASSERT_EQ
(
multiply_dims
(
dims
),
a
.
total
());
ASSERT_EQ
(
CV_32F
,
a
.
type
());
ASSERT_EQ
(
CV_32F
,
a
.
type
());
ASSERT_EQ
(
CV_32F
,
a
.
depth
());
ASSERT_EQ
(
CV_32F
,
a
.
depth
());
ASSERT_EQ
(
-
1
,
a
.
channels
());
ASSERT_EQ
(
-
1
,
a
.
channels
());
...
@@ -408,7 +414,7 @@ TEST(OwnMat, CopyRegularToND)
...
@@ -408,7 +414,7 @@ TEST(OwnMat, CopyRegularToND)
ASSERT_NE
(
nullptr
,
a
.
data
);
ASSERT_NE
(
nullptr
,
a
.
data
);
ASSERT_EQ
((
cv
::
gapi
::
own
::
Size
{
0
,
0
}),
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
((
cv
::
gapi
::
own
::
Size
{
0
,
0
}),
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
(
static_cast
<
size_t
>
(
dims
[
0
]
*
dims
[
1
]
*
dims
[
2
]
*
dims
[
3
]
),
a
.
total
());
ASSERT_EQ
(
multiply_dims
(
dims
),
a
.
total
());
ASSERT_EQ
(
CV_32F
,
a
.
type
());
ASSERT_EQ
(
CV_32F
,
a
.
type
());
ASSERT_EQ
(
CV_32F
,
a
.
depth
());
ASSERT_EQ
(
CV_32F
,
a
.
depth
());
ASSERT_EQ
(
-
1
,
a
.
channels
());
ASSERT_EQ
(
-
1
,
a
.
channels
());
...
@@ -424,7 +430,7 @@ TEST(OwnMat, CopyRegularToND)
...
@@ -424,7 +430,7 @@ TEST(OwnMat, CopyRegularToND)
ASSERT_NE
(
old_ptr
,
a
.
data
);
ASSERT_NE
(
old_ptr
,
a
.
data
);
ASSERT_NE
(
b
.
data
,
a
.
data
);
ASSERT_NE
(
b
.
data
,
a
.
data
);
ASSERT_EQ
(
sz
,
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
(
sz
,
(
cv
::
gapi
::
own
::
Size
{
a
.
cols
,
a
.
rows
}));
ASSERT_EQ
(
static_cast
<
size_t
>
(
sz
.
width
*
sz
.
height
)
,
a
.
total
());
ASSERT_EQ
(
static_cast
<
size_t
>
(
sz
.
width
)
*
sz
.
height
,
a
.
total
());
ASSERT_EQ
(
CV_8U
,
a
.
type
());
ASSERT_EQ
(
CV_8U
,
a
.
type
());
ASSERT_EQ
(
CV_8U
,
a
.
depth
());
ASSERT_EQ
(
CV_8U
,
a
.
depth
());
ASSERT_EQ
(
1
,
a
.
channels
());
ASSERT_EQ
(
1
,
a
.
channels
());
...
...
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