47 lines
1.0 KiB
C++
47 lines
1.0 KiB
C++
#include "ImageApplyDetachNoise.h"
|
|
#include "ImageProcess_Public.h"
|
|
|
|
CImageApplyDetachNoise::CImageApplyDetachNoise(int noise)
|
|
: m_noise(noise)
|
|
{
|
|
}
|
|
|
|
CImageApplyDetachNoise::~CImageApplyDetachNoise(void)
|
|
{
|
|
}
|
|
|
|
void CImageApplyDetachNoise::apply(cv::Mat& pDib, int side)
|
|
{
|
|
(void)side;
|
|
if (pDib.empty()||pDib.channels() != 1)
|
|
return;
|
|
|
|
cv::Mat mask;
|
|
cv::threshold(pDib, mask, 127, 255, cv::THRESH_BINARY_INV);
|
|
|
|
std::vector<std::vector<cv::Point>> contours;
|
|
std::vector<cv::Vec4i> h;
|
|
hg::findContours(mask, contours, h);
|
|
|
|
for (const std::vector<cv::Point>& contour : contours)
|
|
{
|
|
cv::Rect rect = cv::boundingRect(contour);
|
|
if (rect.width <= m_noise && rect.height <= m_noise)
|
|
fillConvexPoly(pDib, contour, cv::Scalar(255));
|
|
|
|
}
|
|
}
|
|
|
|
void CImageApplyDetachNoise::apply(std::vector<cv::Mat> &mats, bool isTwoSide)
|
|
{
|
|
(void)isTwoSide;
|
|
int i = 0;
|
|
for (cv::Mat& var : mats) {
|
|
if (i != 0 && isTwoSide == false)
|
|
break;
|
|
if (!var.empty())
|
|
apply(var, 0);
|
|
i++;
|
|
}
|
|
}
|