2020-11-16 10:05:04 +00:00
|
|
|
#include "ImageApplyDogEarDetection.h"
|
|
|
|
#include "ImageProcess_Public.h"
|
|
|
|
|
|
|
|
CImageApplyDogEarDetection::CImageApplyDogEarDetection()
|
2021-11-20 03:09:04 +00:00
|
|
|
: m_threshold(40)
|
|
|
|
, m_zoom(1.0)
|
|
|
|
, m_distance(50)
|
|
|
|
, m_result(false)
|
2020-11-16 10:05:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CImageApplyDogEarDetection::CImageApplyDogEarDetection(double threshlod, double zoom, double distance)
|
2021-11-20 03:09:04 +00:00
|
|
|
: m_threshold(threshlod)
|
|
|
|
, m_zoom(zoom)
|
|
|
|
, m_distance(distance)
|
|
|
|
, m_result(false)
|
2020-11-16 10:05:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CImageApplyDogEarDetection::~CImageApplyDogEarDetection()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-20 03:09:04 +00:00
|
|
|
void CImageApplyDogEarDetection::apply(cv::Mat& pDib, int side)
|
2020-11-16 10:05:04 +00:00
|
|
|
{
|
2021-11-20 03:09:04 +00:00
|
|
|
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;
|
2020-11-16 10:05:04 +00:00
|
|
|
|
2021-11-20 03:09:04 +00:00
|
|
|
cv::Mat thre;
|
|
|
|
hg::threshold_Mat(src, thre, m_threshold);
|
2020-11-16 10:05:04 +00:00
|
|
|
|
2021-11-20 03:09:04 +00:00
|
|
|
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));
|
2020-11-16 10:05:04 +00:00
|
|
|
|
2021-11-20 03:09:04 +00:00
|
|
|
std::vector<cv::Vec4i> hierarchy;
|
|
|
|
std::vector<std::vector<cv::Point>> contours;
|
|
|
|
hg::findContours(thre, contours, hierarchy, cv::RETR_EXTERNAL);
|
|
|
|
|
|
|
|
std::vector<cv::Point> 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;
|
|
|
|
}
|
2020-11-16 10:05:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 03:09:04 +00:00
|
|
|
void CImageApplyDogEarDetection::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
|
2020-11-16 10:05:04 +00:00
|
|
|
{
|
2021-11-20 03:09:04 +00:00
|
|
|
(void)mats;
|
|
|
|
(void)isTwoSide;
|
2020-11-16 10:05:04 +00:00
|
|
|
}
|
2021-11-20 03:09:04 +00:00
|
|
|
|