mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
fix#9570: implement mat ptr for generic types
The original template based mat ptr for indexing is not implemented, add the similar implementation as uchar type, but cast to user-defined type from the uchar pointer.
This commit is contained in:
@@ -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.0f, 22.0f, 33.0f, 44.0f);
|
||||
int idx[2] = {1, 0};
|
||||
ASSERT_FLOAT_EQ(33.0f, *(mat.ptr<float>(idx)));
|
||||
idx[0] = 1;
|
||||
idx[1] = 1;
|
||||
ASSERT_FLOAT_EQ(44.0f, *(mat.ptr<float>(idx)));
|
||||
}
|
||||
|
||||
TEST(Mat_, template_based_ptr)
|
||||
{
|
||||
int dim[4] = {2, 2, 1, 2};
|
||||
Mat_<float> mat = (Mat_<float>(4, dim) << 11.0f, 22.0f, 33.0f, 44.0f,
|
||||
55.0f, 66.0f, 77.0f, 88.0f);
|
||||
int idx[4] = {1, 0, 0, 1};
|
||||
ASSERT_FLOAT_EQ(66.0f, *(mat.ptr<float>(idx)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user