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
49e16a3c
Commit
49e16a3c
authored
Mar 24, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8448 from jexner:foreach-segfault-fix
parents
e7cad594
46af0757
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
utility.hpp
modules/core/include/opencv2/core/utility.hpp
+1
-1
test_mat.cpp
modules/core/test/test_mat.cpp
+63
-0
No files found.
modules/core/include/opencv2/core/utility.hpp
View file @
49e16a3c
...
...
@@ -507,7 +507,7 @@ void Mat::forEach_impl(const Functor& operation) {
this
->
rowCall2
(
row
,
COLS
);
}
}
else
{
std
::
vector
<
int
>
idx
(
COL
S
);
/// idx is modified in this->rowCall
std
::
vector
<
int
>
idx
(
DIM
S
);
/// idx is modified in this->rowCall
idx
[
DIMS
-
2
]
=
range
.
start
-
1
;
for
(
int
line_num
=
range
.
start
;
line_num
<
range
.
end
;
++
line_num
)
{
...
...
modules/core/test/test_mat.cpp
View file @
49e16a3c
...
...
@@ -659,6 +659,18 @@ struct InitializerFunctor{
}
};
template
<
typename
Pixel
>
struct
InitializerFunctor5D
{
/// Initializer for cv::Mat::forEach test (5 dimensional case)
void
operator
()(
Pixel
&
pixel
,
const
int
*
idx
)
const
{
pixel
[
0
]
=
idx
[
0
];
pixel
[
1
]
=
idx
[
1
];
pixel
[
2
]
=
idx
[
2
];
pixel
[
3
]
=
idx
[
3
];
pixel
[
4
]
=
idx
[
4
];
}
};
void
Core_ArrayOpTest
::
run
(
int
/* start_from */
)
{
int
errcount
=
0
;
...
...
@@ -736,6 +748,57 @@ void Core_ArrayOpTest::run( int /* start_from */)
}
}
// test cv::Mat::forEach
// with a matrix that has more dimensions than columns
// See https://github.com/opencv/opencv/issues/8447
{
const
int
dims
[
5
]
=
{
2
,
2
,
2
,
2
,
2
};
typedef
cv
::
Vec
<
int
,
5
>
Pixel
;
cv
::
Mat
a
=
cv
::
Mat
::
zeros
(
5
,
dims
,
CV_32SC
(
5
));
InitializerFunctor5D
<
Pixel
>
initializer
;
a
.
forEach
<
Pixel
>
(
initializer
);
uint64
total
=
0
;
bool
error_reported
=
false
;
for
(
int
i0
=
0
;
i0
<
dims
[
0
];
++
i0
)
{
for
(
int
i1
=
0
;
i1
<
dims
[
1
];
++
i1
)
{
for
(
int
i2
=
0
;
i2
<
dims
[
2
];
++
i2
)
{
for
(
int
i3
=
0
;
i3
<
dims
[
3
];
++
i3
)
{
for
(
int
i4
=
0
;
i4
<
dims
[
4
];
++
i4
)
{
const
int
i
[
5
]
=
{
i0
,
i1
,
i2
,
i3
,
i4
};
Pixel
&
pixel
=
a
.
at
<
Pixel
>
(
i
);
if
(
pixel
[
0
]
!=
i0
||
pixel
[
1
]
!=
i1
||
pixel
[
2
]
!=
i2
||
pixel
[
3
]
!=
i3
||
pixel
[
4
]
!=
i4
)
{
if
(
!
error_reported
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"forEach is not correct.
\n
"
"First error detected at position (%d, %d, %d, %d, %d), got value (%d, %d, %d, %d, %d).
\n
"
,
i0
,
i1
,
i2
,
i3
,
i4
,
pixel
[
0
],
pixel
[
1
],
pixel
[
2
],
pixel
[
3
],
pixel
[
4
]);
error_reported
=
true
;
}
errcount
++
;
}
total
+=
pixel
[
0
];
total
+=
pixel
[
1
];
total
+=
pixel
[
2
];
total
+=
pixel
[
3
];
total
+=
pixel
[
4
];
}
}
}
}
}
uint64
total2
=
0
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
dims
)
/
sizeof
(
dims
[
0
]);
++
i
)
{
total2
+=
((
dims
[
i
]
-
1
)
*
dims
[
i
]
/
2
)
*
dims
[
0
]
*
dims
[
1
]
*
dims
[
2
]
*
dims
[
3
]
*
dims
[
4
]
/
dims
[
i
];
}
if
(
total
!=
total2
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"forEach is not correct because total is invalid.
\n
"
);
errcount
++
;
}
}
RNG
rng
;
const
int
MAX_DIM
=
5
,
MAX_DIM_SZ
=
10
;
// sparse matrix operations
...
...
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