Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb05b49c

Browse files
Adding rbegin and rend to Mat_ class with the right parameters so we don't need to repeat the template argument.
An instantiating cv::Mat_<int> for example can call it's rbegin() function and doesn't need rbegin<int>() with this convience addition.Follows what is done for forward iterators
1 parentad29445 commitb05b49c

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

‎modules/core/include/opencv2/core/mat.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,12 @@ template<typename _Tp> class Mat_ : public Mat
22612261
const_iteratorbegin()const;
22622262
const_iteratorend()const;
22632263

2264+
//reverse iterators
2265+
std::reverse_iterator<iterator>rbegin();
2266+
std::reverse_iterator<iterator>rend();
2267+
std::reverse_iterator<const_iterator>rbegin()const;
2268+
std::reverse_iterator<const_iterator>rend()const;
2269+
22642270
//! template methods for for operation over all matrix elements.
22652271
// the operations take care of skipping gaps in the end of rows (if any)
22662272
template<typename Functor>voidforEach(const Functor& operation);

‎modules/core/include/opencv2/core/mat.inl.hpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,24 +1726,50 @@ MatConstIterator_<_Tp> Mat_<_Tp>::begin() const
17261726
return Mat::begin<_Tp>();
17271727
}
17281728

1729+
template<typename _Tp>inline
1730+
std::reverse_iterator<MatConstIterator_<_Tp>> Mat_<_Tp>::rbegin()const
1731+
{
1732+
return Mat::rbegin<_Tp>();
1733+
}
1734+
17291735
template<typename _Tp>inline
17301736
MatConstIterator_<_Tp> Mat_<_Tp>::end()const
17311737
{
17321738
return Mat::end<_Tp>();
17331739
}
17341740

1741+
template<typename _Tp>inline
1742+
std::reverse_iterator<MatConstIterator_<_Tp>> Mat_<_Tp>::rend()const
1743+
{
1744+
return Mat::rend<_Tp>();
1745+
}
1746+
17351747
template<typename _Tp>inline
17361748
MatIterator_<_Tp> Mat_<_Tp>::begin()
17371749
{
17381750
return Mat::begin<_Tp>();
17391751
}
17401752

1753+
template<typename _Tp>inline
1754+
std::reverse_iterator<MatIterator_<_Tp>> Mat_<_Tp>::rbegin()
1755+
{
1756+
return Mat::rbegin<_Tp>();
1757+
}
1758+
1759+
17411760
template<typename _Tp>inline
17421761
MatIterator_<_Tp> Mat_<_Tp>::end()
17431762
{
17441763
return Mat::end<_Tp>();
17451764
}
17461765

1766+
1767+
template<typename _Tp>inline
1768+
std::reverse_iterator<MatIterator_<_Tp>> Mat_<_Tp>::rend()
1769+
{
1770+
return Mat::rend<_Tp>();
1771+
}
1772+
17471773
template<typename _Tp>template<typename Functor>inline
17481774
void Mat_<_Tp>::forEach(const Functor& operation) {
17491775
Mat::forEach<_Tp, Functor>(operation);

‎modules/core/test/test_mat.cpp‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,30 +2366,52 @@ TEST(Mat, reverse_iterator_19967)
23662366
// 1D test
23672367
std::vector<uchar> data{0,1,2,3};
23682368
const std::vector<int> sizes_1d{4};
2369-
cv::Matm_1d(sizes_1d, CV_8U, data.data());
23702369

2370+
//Base class
2371+
cv::Matm_1d(sizes_1d, CV_8U, data.data());
23712372
auto mismatch_it_pair_1d =std::mismatch(data.rbegin(), data.rend(), m_1d.rbegin<uchar>());
23722373
EXPECT_EQ(mismatch_it_pair_1d.first, data.rend());// expect no mismatch
23732374
EXPECT_EQ(mismatch_it_pair_1d.second, m_1d.rend<uchar>());
23742375

2376+
//Templated derived class
2377+
cv::Mat_<uchar>m_1d_t(sizes_1d.size(), sizes_1d.data(), data.data());
2378+
automismatch_it_pair_1d_t =std::mismatch(data.rbegin(), data.rend(),m_1d_t.rbegin());
2379+
EXPECT_EQ(mismatch_it_pair_1d_t.first, data.rend());// expect no mismatch
2380+
EXPECT_EQ(mismatch_it_pair_1d_t.second,m_1d_t.rend());
2381+
2382+
23752383
// 2D test
23762384
const std::vector<int> sizes_2d{2,2};
2377-
cv::Matm_2d(sizes_2d, CV_8U, data.data());
23782385

2386+
//Base class
2387+
cv::Matm_2d(sizes_2d, CV_8U, data.data());
23792388
auto mismatch_it_pair_2d =std::mismatch(data.rbegin(), data.rend(), m_2d.rbegin<uchar>());
23802389
EXPECT_EQ(mismatch_it_pair_2d.first, data.rend());
23812390
EXPECT_EQ(mismatch_it_pair_2d.second, m_2d.rend<uchar>());
23822391

2392+
//Templated derived class
2393+
cv::Mat_<uchar>m_2d_t(sizes_2d.size(),sizes_2d.data(), data.data());
2394+
automismatch_it_pair_2d_t =std::mismatch(data.rbegin(), data.rend(),m_2d_t.rbegin());
2395+
EXPECT_EQ(mismatch_it_pair_2d_t.first, data.rend());
2396+
EXPECT_EQ(mismatch_it_pair_2d_t.second,m_2d_t.rend());
2397+
23832398
// 3D test
23842399
std::vector<uchar> data_3d{0,1,2,3,4,5,6,7};
23852400
const std::vector<int> sizes_3d{2,2,2};
2386-
cv::Matm_3d(sizes_3d, CV_8U, data_3d.data());
23872401

2402+
//Base class
2403+
cv::Matm_3d(sizes_3d, CV_8U, data_3d.data());
23882404
auto mismatch_it_pair_3d =std::mismatch(data_3d.rbegin(), data_3d.rend(), m_3d.rbegin<uchar>());
23892405
EXPECT_EQ(mismatch_it_pair_3d.first, data_3d.rend());
23902406
EXPECT_EQ(mismatch_it_pair_3d.second, m_3d.rend<uchar>());
23912407

2392-
// const test
2408+
//Templated derived class
2409+
cv::Mat_<uchar>m_3d_t(sizes_3d.size(),sizes_3d.data(), data_3d.data());
2410+
automismatch_it_pair_3d_t =std::mismatch(data_3d.rbegin(), data_3d.rend(),m_3d_t.rbegin());
2411+
EXPECT_EQ(mismatch_it_pair_3d_t.first, data_3d.rend());
2412+
EXPECT_EQ(mismatch_it_pair_3d_t.second,m_3d_t.rend());
2413+
2414+
// const test base class
23932415
const cv::Matm_1d_const(sizes_1d, CV_8U, data.data());
23942416

23952417
auto mismatch_it_pair_1d_const =std::mismatch(data.rbegin(), data.rend(), m_1d_const.rbegin<uchar>());
@@ -2398,6 +2420,17 @@ TEST(Mat, reverse_iterator_19967)
23982420

23992421
EXPECT_FALSE((std::is_assignable<decltype(m_1d_const.rend<uchar>()), uchar>::value)) <<"Constness of const iterator violated.";
24002422
EXPECT_FALSE((std::is_assignable<decltype(m_1d_const.rbegin<uchar>()), uchar>::value)) <<"Constness of const iterator violated.";
2423+
2424+
// const test templated dervied class
2425+
const cv::Mat_<uchar>m_1d_const_t(sizes_1d.size(), sizes_1d.data(), data.data());
2426+
2427+
automismatch_it_pair_1d_const_t =std::mismatch(data.rbegin(), data.rend(),m_1d_const_t.rbegin());
2428+
EXPECT_EQ(mismatch_it_pair_1d_const_t.first, data.rend());// expect no mismatch
2429+
EXPECT_EQ(mismatch_it_pair_1d_const_t.second,m_1d_const_t.rend());
2430+
2431+
EXPECT_FALSE((std::is_assignable<decltype(m_1d_const_t.rend()), uchar>::value)) <<"Constness of const iterator violated.";
2432+
EXPECT_FALSE((std::is_assignable<decltype(m_1d_const_t.rbegin()), uchar>::value)) <<"Constness of const iterator violated.";
2433+
24012434
}
24022435

24032436
}}// namespace

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp