Merge pull request #13664 from smirnov-alexey:gapi_add_descrof_overloading
* Add version of descr_of function taking vector of Mat * Overload descr_of function for cv::Mat * Add template function instead of copypasting and change tests a little
This commit is contained in:
committed by
Alexander Alekhin
parent
e5917a8fa5
commit
5728679fd5
@@ -133,6 +133,8 @@ 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)
|
||||
|
||||
/** @} */
|
||||
@@ -140,6 +142,7 @@ GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat);
|
||||
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);
|
||||
|
||||
@@ -33,15 +33,35 @@ 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));
|
||||
}
|
||||
return vec_descr;
|
||||
}
|
||||
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
cv::GMatDesc cv::descr_of(const cv::Mat &mat)
|
||||
{
|
||||
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return vec_descr_of(vec);
|
||||
}
|
||||
|
||||
std::vector<cv::GMatDesc> cv::descr_of(const std::vector<cv::UMat> &vec)
|
||||
{
|
||||
return vec_descr_of(vec);
|
||||
}
|
||||
#endif
|
||||
|
||||
cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat)
|
||||
@@ -49,6 +69,11 @@ 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)
|
||||
{
|
||||
return vec_descr_of(vec);
|
||||
}
|
||||
|
||||
namespace cv {
|
||||
std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,45 @@ TEST(GAPI_MetaDesc, MatDesc)
|
||||
EXPECT_EQ(480, desc2.size.height);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, VecMatDesc)
|
||||
{
|
||||
std::vector<cv::Mat> vec1 = {
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, VecOwnMatDesc)
|
||||
{
|
||||
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 = 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);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compare_Equal_MatDesc)
|
||||
{
|
||||
const auto desc1 = cv::GMatDesc{CV_8U, 1, {64, 64}};
|
||||
|
||||
Reference in New Issue
Block a user