#ifndef LIBCVD_OPENCV_H #define LIBCVD_OPENCV_H #include #include #include #include #include #include namespace CVD { namespace Internal { template struct opencv_traits { static const int depth = cv::DataDepth::value; static const int channels = 1; }; template struct opencv_traits> : public opencv_traits { static const int channels = 3; }; template struct opencv_traits> : public opencv_traits { static const int channels = 4; }; template struct opencv_type { static const int type = CV_MAKETYPE(opencv_traits::depth, opencv_traits::channels); }; }; template cv::Mat toMat(const CVD::BasicImage& img) { return cv::Mat(img.size().y, img.size().x, Internal::opencv_type::type, (void*)img.data(), img.row_stride() * sizeof(T)); } template void equalizeHist(const CVD::BasicImage& in, CVD::BasicImage& out) { equalizeHist(toMat(in), toMat(out)); } namespace OpenCV { struct ContourHierarchy { int next_index; int previous_index; int first_child_index; int parent_index; }; namespace Internal { inline void convert_hierarchy(const std::vector& cv_hierarchy, std::vector& hierarchy) { hierarchy.reserve(cv_hierarchy.size()); std::transform( cv_hierarchy.begin(), cv_hierarchy.end(), std::back_inserter(hierarchy), [](const cv::Vec4i& p) { return ContourHierarchy { p[0], p[1], p[2], p[3] }; }); } } template void resize(const CVD::BasicImage& in, CVD::BasicImage& out, int interpolation = cv::INTER_LINEAR) { cv::resize(toMat(in), toMat(out), cv::Size(out.size().x, out.size().y), 0, 0, interpolation); } } } #endif