#include "ImageApplyDogEarDetection.h" #include "ImageProcess_Public.h" CImageApplyDogEarDetection::CImageApplyDogEarDetection() : m_threshold(40) , m_zoom(1.0) , m_distance(50) , m_result(false) { } CImageApplyDogEarDetection::CImageApplyDogEarDetection(double threshlod, double zoom, double distance) : m_threshold(threshlod) , m_zoom(zoom) , m_distance(distance) , m_result(false) { } CImageApplyDogEarDetection::~CImageApplyDogEarDetection() { } void CImageApplyDogEarDetection::apply(cv::Mat& pDib, int side) { m_result = false; (void)side; if (pDib.empty()) return; cv::Mat src; if (m_zoom != 1.0) cv::resize(pDib, src, cv::Size(), m_zoom, m_zoom, cv::INTER_NEAREST); else src = pDib; cv::Mat thre; hg::threshold_Mat(src, thre, m_threshold); cv::Mat element = getStructuringElement(cv::MORPH_RECT, cv::Size(20, 1)); cv::morphologyEx(thre, thre, cv::MORPH_OPEN, element, cv::Point(-1, -1), 1, cv::BORDER_CONSTANT, cv::Scalar::all(0)); std::vector hierarchy; std::vector> contours; hg::findContours(thre, contours, hierarchy, cv::RETR_EXTERNAL); std::vector maxContour = hg::getMaxContour(contours, hierarchy); if (maxContour.size() == 0) { m_result = true; return; } hg::convexHull(maxContour, maxContour); cv::RotatedRect rect = hg::getBoundingRect(maxContour); cv::Point2f vertexes[4]; rect.points(vertexes); for (int i = 0; i < 4; i++) if ((-cv::pointPolygonTest(maxContour, vertexes[i], true)) > (m_distance * m_zoom)) { m_result = true; return; } } void CImageApplyDogEarDetection::apply(std::vector& mats, bool isTwoSide) { (void)mats; (void)isTwoSide; }