mirror of http://192.168.1.51:8099/lmh188/twain3.0
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
|
#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);
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CImageApplyDogEarDetection::apply(std::vector<cv::Mat> &mats, bool isTwoSide)
|
||
|
{
|
||
|
(void)mats;
|
||
|
(void)isTwoSide;
|
||
|
}
|