mirror of http://192.168.1.51:8099/lmh188/twain3.0
替换图像处理锐化类
This commit is contained in:
parent
8cc46c7d6b
commit
841728fda1
|
@ -1,10 +1,9 @@
|
||||||
#include "ImageApplySharpen.h"
|
#include "ImageApplySharpen.h"
|
||||||
|
using namespace cv;
|
||||||
CImageApplySharpen::CImageApplySharpen()
|
CImageApplySharpen::CImageApplySharpen(int sharpentype)
|
||||||
: kernel(5, 5, CV_32FC1)
|
|
||||||
{
|
{
|
||||||
float kernel_data[] = { -0.1f, 0, 0, 0, -0.1f, 0, 0, 0, 0, 0, 0, 0, 1.5f, 0, 0, 0, 0, 0, 0, 0, -0.1f, 0, 0, 0, -0.1f };
|
sharpenType = sharpentype;
|
||||||
memcpy(kernel.data, kernel_data, sizeof(float) * 25);
|
kSize = (sharpentype == FilterMethod::Sharpen || sharpentype == FilterMethod::AverBlur) ? 5 : 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
CImageApplySharpen::~CImageApplySharpen()
|
CImageApplySharpen::~CImageApplySharpen()
|
||||||
|
@ -17,9 +16,18 @@ void CImageApplySharpen::apply(cv::Mat & pDib, int side)
|
||||||
FileTools::write_log("imgprc.txt", "enter CImageApplySharpen apply");
|
FileTools::write_log("imgprc.txt", "enter CImageApplySharpen apply");
|
||||||
#endif // LOG
|
#endif // LOG
|
||||||
|
|
||||||
if (pDib.empty()) return;
|
switch (sharpenType)
|
||||||
|
{
|
||||||
|
case CImageApplySharpen::Sharpen:
|
||||||
|
case CImageApplySharpen::Sharpen_More:
|
||||||
|
sharpen(pDib, kSize);
|
||||||
|
break;
|
||||||
|
case CImageApplySharpen::AverBlur:
|
||||||
|
case CImageApplySharpen::AverBlur_More:
|
||||||
|
averblur(pDib, static_cast<int>(kSize));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
cv::filter2D(pDib, pDib, pDib.depth(), kernel);
|
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
FileTools::write_log("imgprc.txt", "exit CImageApplySharpen apply");
|
FileTools::write_log("imgprc.txt", "exit CImageApplySharpen apply");
|
||||||
#endif // LOG
|
#endif // LOG
|
||||||
|
@ -29,8 +37,25 @@ void CImageApplySharpen::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
|
||||||
{
|
{
|
||||||
if (mats.empty()) return;
|
if (mats.empty()) return;
|
||||||
|
|
||||||
apply(mats[0], 0);
|
if (!mats[0].empty())
|
||||||
|
apply(mats[0], 0);
|
||||||
|
|
||||||
if (isTwoSide && mats.size() > 1)
|
if (isTwoSide && mats.size() > 1) {
|
||||||
apply(mats[1], 1);
|
if (!mats[1].empty())
|
||||||
|
apply(mats[1], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CImageApplySharpen::averblur(Mat& src, int kSize)
|
||||||
|
{
|
||||||
|
blur(src, src, Size(kSize, kSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CImageApplySharpen::sharpen(Mat& src, float kSize)
|
||||||
|
{
|
||||||
|
float other = (1.0f - kSize) / 4;
|
||||||
|
float kernel_data[] = { 0, other, 0, other, kSize, other, 0, other, 0 };
|
||||||
|
Mat kernel(3, 3, CV_32FC1, kernel_data);
|
||||||
|
|
||||||
|
filter2D(src, src, src.depth(), kernel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,30 @@
|
||||||
|
|
||||||
#include "ImageApply.h"
|
#include "ImageApply.h"
|
||||||
|
|
||||||
class CImageApplySharpen : public CImageApply
|
class CImageApplySharpen :
|
||||||
|
public CImageApply
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CImageApplySharpen();
|
enum FilterMethod
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Sharpen,
|
||||||
|
Sharpen_More,
|
||||||
|
AverBlur,
|
||||||
|
AverBlur_More
|
||||||
|
};
|
||||||
|
CImageApplySharpen(int sharpentype);
|
||||||
virtual ~CImageApplySharpen();
|
virtual ~CImageApplySharpen();
|
||||||
|
|
||||||
virtual void apply(cv::Mat& pDib, int side);
|
virtual void apply(cv::Mat& pDib, int side);
|
||||||
|
|
||||||
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
||||||
private:
|
private:
|
||||||
cv::Mat kernel;
|
void averblur(cv::Mat& src, int kSize);
|
||||||
|
void sharpen(cv::Mat& src, float kSize);
|
||||||
|
private:
|
||||||
|
int sharpenType;
|
||||||
|
float kSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !IMAGE_APPLY_SHARPEN_H
|
#endif // !IMAGE_APPLY_SHARPEN_H
|
||||||
|
|
Loading…
Reference in New Issue