Skip to content

Commit

Permalink
Merge pull request opencv#13678 from smirnov-alexey:gapi_fix_descrof_…
Browse files Browse the repository at this point in the history
…overloading

* Return vector of MetaArg instead of MatDesc and fix test with ADL check

* Fix construction of vector

* Change names and tests according to review
Also add GAPI_EXPORTS prefix for two ostream operators
  • Loading branch information
smirnov-alexey authored and alalek committed Jan 28, 2019
1 parent e2dbf05 commit a65ccc0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
5 changes: 1 addition & 4 deletions modules/gapi/include/opencv2/gapi/gmat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,16 @@ static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; }
class Mat;
GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat);
GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat);
GAPI_EXPORTS std::vector<GMatDesc> descr_of(const std::vector<cv::Mat> &vec);
GAPI_EXPORTS std::vector<GMatDesc> descr_of(const std::vector<cv::UMat> &vec);
#endif // !defined(GAPI_STANDALONE)

/** @} */

namespace gapi { namespace own {
class Mat;
GAPI_EXPORTS GMatDesc descr_of(const Mat &mat);
GAPI_EXPORTS std::vector<GMatDesc> descr_of(const std::vector<Mat> &vec);
}}//gapi::own

std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc);
GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc);

} // namespace cv

Expand Down
11 changes: 10 additions & 1 deletion modules/gapi/include/opencv2/gapi/gmetaarg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using GMetaArg = util::variant
, GScalarDesc
, GArrayDesc
>;
std::ostream& operator<<(std::ostream& os, const GMetaArg &);
GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const GMetaArg &);

using GMetaArgs = std::vector<GMetaArg>;

Expand All @@ -61,6 +61,15 @@ namespace detail

} // namespace detail

class Mat;
class UMat;
GAPI_EXPORTS cv::GMetaArgs descr_of(const std::vector<cv::Mat> &vec);
GAPI_EXPORTS cv::GMetaArgs descr_of(const std::vector<cv::UMat> &vec);
namespace gapi { namespace own {
class Mat;
GAPI_EXPORTS cv::GMetaArgs descr_of(const std::vector<Mat> &vec);
}} // namespace gapi::own

} // namespace cv

#endif // OPENCV_GAPI_GMETAARG_HPP
22 changes: 13 additions & 9 deletions modules/gapi/src/api/gmat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ const cv::GOrigin& cv::GMat::priv() const
return *m_priv;
}

template <typename T> std::vector<cv::GMatDesc> vec_descr_of(const std::vector<T> &vec)
{
std::vector<cv::GMatDesc> vec_descr;
for(auto& mat : vec){
vec_descr.emplace_back(descr_of(mat));
namespace{
template <typename T> cv::GMetaArgs vec_descr_of(const std::vector<T> &vec)
{
cv::GMetaArgs vec_descr;
vec_descr.reserve(vec.size());
for(auto& mat : vec){
vec_descr.emplace_back(descr_of(mat));
}
return vec_descr;
}
return vec_descr;
}


#if !defined(GAPI_STANDALONE)
cv::GMatDesc cv::descr_of(const cv::Mat &mat)
{
Expand All @@ -53,12 +57,12 @@ cv::GMatDesc cv::descr_of(const cv::UMat &mat)
return GMatDesc{ mat.depth(), mat.channels(),{ mat.cols, mat.rows } };
}

std::vector<cv::GMatDesc> cv::descr_of(const std::vector<cv::Mat> &vec)
cv::GMetaArgs cv::descr_of(const std::vector<cv::Mat> &vec)
{
return vec_descr_of(vec);
}

std::vector<cv::GMatDesc> cv::descr_of(const std::vector<cv::UMat> &vec)
cv::GMetaArgs cv::descr_of(const std::vector<cv::UMat> &vec)
{
return vec_descr_of(vec);
}
Expand All @@ -69,7 +73,7 @@ cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat)
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
}

std::vector<cv::GMatDesc> cv::gapi::own::descr_of(const std::vector<cv::gapi::own::Mat> &vec)
cv::GMetaArgs cv::gapi::own::descr_of(const std::vector<cv::gapi::own::Mat> &vec)
{
return vec_descr_of(vec);
}
Expand Down
32 changes: 15 additions & 17 deletions modules/gapi/test/gapi_desc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,13 @@ TEST(GAPI_MetaDesc, VecMatDesc)
cv::Mat(240, 320, CV_8U)};

const auto desc1 = cv::descr_of(vec1);
EXPECT_EQ(CV_8U, desc1[0].depth);
EXPECT_EQ(1, desc1[0].chan);
EXPECT_EQ(320, desc1[0].size.width);
EXPECT_EQ(240, desc1[0].size.height);
EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get<GMatDesc>(desc1[0]));

std::vector<cv::UMat> vec2 = {
cv::UMat(480, 640, CV_8UC3)};

const auto desc2 = cv::descr_of(vec2);
EXPECT_EQ(CV_8U, desc2[0].depth);
EXPECT_EQ(3, desc2[0].chan);
EXPECT_EQ(640, desc2[0].size.width);
EXPECT_EQ(480, desc2[0].size.height);
EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get<GMatDesc>(desc2[0]));
}

TEST(GAPI_MetaDesc, VecOwnMatDesc)
Expand All @@ -68,15 +62,19 @@ TEST(GAPI_MetaDesc, VecOwnMatDesc)
cv::gapi::own::Mat(480, 640, CV_8UC3, nullptr)};

const auto desc = cv::gapi::own::descr_of(vec);
EXPECT_EQ(CV_8U, desc[0].depth);
EXPECT_EQ(1, desc[0].chan);
EXPECT_EQ(320, desc[0].size.width);
EXPECT_EQ(240, desc[0].size.height);

EXPECT_EQ(CV_8U, desc[1].depth);
EXPECT_EQ(3, desc[1].chan);
EXPECT_EQ(640, desc[1].size.width);
EXPECT_EQ(480, desc[1].size.height);
EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get<GMatDesc>(desc[0]));
EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get<GMatDesc>(desc[1]));
}

TEST(GAPI_MetaDesc, AdlVecOwnMatDesc)
{
std::vector<cv::gapi::own::Mat> vec = {
cv::gapi::own::Mat(240, 320, CV_8U, nullptr),
cv::gapi::own::Mat(480, 640, CV_8UC3, nullptr)};

const auto desc = descr_of(vec);
EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get<GMatDesc>(desc[0]));
EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get<GMatDesc>(desc[1]));
}

TEST(GAPI_MetaDesc, Compare_Equal_MatDesc)
Expand Down

0 comments on commit a65ccc0

Please sign in to comment.