Commit 9ad8bd85 张士柳

1 个父辈 24544381
...@@ -346,7 +346,7 @@ namespace eyemLib_Sharp ...@@ -346,7 +346,7 @@ namespace eyemLib_Sharp
/// 圆形Mark点定位 /// 圆形Mark点定位
/// </summary> /// </summary>
/// <param name="tpImage">图像</param> /// <param name="tpImage">图像</param>
/// <param name="tpHSVModel">HSV阈值</param> /// <param name="tpHSVModel">HSV阈值范围</param>
/// <param name="tpCircle">结果</param> /// <param name="tpCircle">结果</param>
/// <param name="tpDstImg">结果图</param> /// <param name="tpDstImg">结果图</param>
/// <param name="bHighAccuracy">是否使用高精度</param> /// <param name="bHighAccuracy">是否使用高精度</param>
...@@ -401,15 +401,6 @@ namespace eyemLib_Sharp ...@@ -401,15 +401,6 @@ namespace eyemLib_Sharp
//例程 //例程
public static void eyeyTestTemplateModelMethod(string fileName) public static void eyeyTestTemplateModelMethod(string fileName)
{ {
#region //从本地读图
EyemImage image, tpDstImg;
int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0)
{
Console.WriteLine("读图失败!");
return;
}
////红色分割 ////红色分割
//EyemHSVModel tpHsvModel = new EyemHSVModel(); //EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 0, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 10, 255, 255 }; //tpHsvModel.dpRangeL = new double[] { 0, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 10, 255, 255 };
...@@ -425,6 +416,15 @@ namespace eyemLib_Sharp ...@@ -425,6 +416,15 @@ namespace eyemLib_Sharp
//tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 }; //tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 }; //tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
#region //从本地读图
//EyemImage image, tpDstImg;
//int flag = eyemImageRead(fileName, -1, out image);
//if (flag != 0)
//{
// Console.WriteLine("读图失败!");
// return;
//}
//EyemOcsFXYR tpCircle = new EyemOcsFXYR(); //EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//flag = eyemMarkerTracing(image, tpHsvModel, ref tpCircle, out tpDstImg); //flag = eyemMarkerTracing(image, tpHsvModel, ref tpCircle, out tpDstImg);
......
...@@ -208,7 +208,7 @@ inline bool BarcodeDetector::isValidCoord(const cv::Point &coord, const cv::Size ...@@ -208,7 +208,7 @@ inline bool BarcodeDetector::isValidCoord(const cv::Point &coord, const cv::Size
return false; return false;
} }
if ((unsigned)coord.x > (unsigned) (limit.width - 1) || ((unsigned)coord.y > (unsigned) (limit.height - 1))) if ((unsigned)coord.x > (unsigned) (limit.width - 1) || ((unsigned)coord.y >(unsigned) (limit.height - 1)))
{ {
return false; return false;
} }
...@@ -438,6 +438,7 @@ bool BarcodeDetector::detect(cv::Mat img, std::vector<cv::Point>& points) ...@@ -438,6 +438,7 @@ bool BarcodeDetector::detect(cv::Mat img, std::vector<cv::Point>& points)
} }
} }
updatePointsResult(points, trans_points); updatePointsResult(points, trans_points);
return true;
} }
void BarcodeDetector::drawBarcode(cv::Mat& img, const std::vector<cv::Point>& points) { void BarcodeDetector::drawBarcode(cv::Mat& img, const std::vector<cv::Point>& points) {
......
...@@ -417,7 +417,7 @@ static int Otsu(int hist[]) ...@@ -417,7 +417,7 @@ static int Otsu(int hist[])
// The float casting here is to avoid compiler warning about loss of precision and // The float casting here is to avoid compiler warning about loss of precision and
// will prevent overflow in the case of large saturated images // will prevent overflow in the case of large saturated images
denom = (double)(N1) * (N - N1); // Maximum value of denom is (N^2)/4 = approx. 3E10 denom = (double)(N1)* (N - N1); // Maximum value of denom is (N^2)/4 = approx. 3E10
if (denom != 0) { if (denom != 0) {
// Float here is to avoid loss of precision when dividing // Float here is to avoid loss of precision when dividing
...@@ -1325,7 +1325,10 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst ...@@ -1325,7 +1325,10 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst
int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg) int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg)
{ {
CV_Assert(tpImage.vpImage != NULL);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
......
...@@ -162,24 +162,21 @@ int eyemEdgesSubpixel(EyemImage tpImage, int iFilter, int iLow, int iHigh) ...@@ -162,24 +162,21 @@ int eyemEdgesSubpixel(EyemImage tpImage, int iFilter, int iLow, int iHigh)
int eyemSobelAmp(EyemImage tpImage, EyemImage &ImaAmp) int eyemSobelAmp(EyemImage tpImage, EyemImage &ImaAmp)
{ {
cv::Mat image(tpImage.iHeight, tpImage.iWidth, CV_8UC1, tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage&&tpImage.iDepth == 0);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
cv::Mat dx, dy; cv::Mat dx, dy;
cv::spatialGradient(image, dx, dy); cv::spatialGradient(image, dx, dy);
cv::Mat mag; cv::Mat mag;
cv::magnitude(dx, dy, mag); cv::magnitude(dx, dy, mag);
return FUNC_OK; return FUNC_OK;
} }
int eyemSkeleton(EyemImage tpImage, cv::Mat &skeleton) int eyemSkeleton(EyemImage tpImage, cv::Mat &skeleton)
{ {
cv::Mat image(tpImage.iHeight, tpImage.iWidth, CV_8UC1, tpImage.vpImage); cv::Mat image(tpImage.iHeight, tpImage.iWidth, CV_8UC1, tpImage.vpImage);
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
...@@ -193,15 +190,6 @@ int eyemAutoCanny(EyemImage tpImage, double dSigma = 0.33) ...@@ -193,15 +190,6 @@ int eyemAutoCanny(EyemImage tpImage, double dSigma = 0.33)
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
cv::Mat F;
cv::GaussianBlur(image, F, cv::Size(3, 3), 0, 0);
////get the median value of the matrix
//double v = medianMat(output);
////generate the thresholds
//int lower = (int)std::max(0.0, (1, 0 - sigma)*v);
//int upper = (int)std::min(255.0, (1, 0 + sigma)*v);
////apply canny operator
//cv::Canny(output, output, lower, upper, 3);
return FUNC_OK; return FUNC_OK;
} }
...@@ -543,7 +543,7 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap ...@@ -543,7 +543,7 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap
cv::Size szMap(iSapLength, 1); cv::Size szMap(iSapLength, 1);
//采样图像 //采样图像
int m = 0; float *pPolarBuf = new float[szMap.width*szMap.height * sizeof(float_t)]; int m = 0; float *pPolarBuf = new float[szMap.width*szMap.height * sizeof(float_t)];
for (float t = -CV_PI; t < CV_PI; t += plusStep, m++) for (double t = -CV_PI; t < CV_PI; t += plusStep, m++)
{ {
//路径上的点 //路径上的点
float _plusX = float(tpCenter.dX + (float)(iRadius + n)*cos(t)); float _plusX = float(tpCenter.dX + (float)(iRadius + n)*cos(t));
......
...@@ -795,6 +795,7 @@ extern "C" { ...@@ -795,6 +795,7 @@ extern "C" {
EXPORTS int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg); EXPORTS int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg);
EXPORTS int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg); EXPORTS int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg);
EXPORTS int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg); EXPORTS int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg);
EXPORTS int eyemShockFilter(EyemImage tpImage, int kSize, double dSigma, double dBlend, const int iIter, EyemImage *tpDstImg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -74,8 +74,8 @@ ...@@ -74,8 +74,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;D:\feature_extract\include;D:\feature_extract\include\ncnn;$(IncludePath)</IncludePath> <IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;D:\feature_extract\lib;$(LibraryPath)</LibraryPath> <LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt> <TargetExt>.dll</TargetExt>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...@@ -83,8 +83,8 @@ ...@@ -83,8 +83,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;D:\feature_extract\include;D:\feature_extract\include\ncnn;$(IncludePath)</IncludePath> <IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;D:\feature_extract\lib;$(LibraryPath)</LibraryPath> <LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt> <TargetExt>.dll</TargetExt>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;libresnet.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;libresnet.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
......
...@@ -18,10 +18,8 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, ...@@ -18,10 +18,8 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
} }
//图像信息 //图像信息
tpImage->iWidth = iWidth; tpImage->iHeight = iHeight; tpImage->iChannels = iChannels; tpImage->iWidth = iWidth; tpImage->iHeight = iHeight; tpImage->iChannels = iChannels;
//内存尺寸 //内存尺寸
int _Size = iWidth*iHeight*iChannels; int _Size = iWidth*iHeight*iChannels;
//分配所需内存 //分配所需内存
if (strcmp(ccSubType, "uint8_t") == 0) { if (strcmp(ccSubType, "uint8_t") == 0) {
tpImage->iDepth = 0; tpImage->iDepth = 0;
...@@ -625,16 +623,6 @@ int eyemMatAt(EyemImage tpImage, EyemOcsIXY tpPoint) ...@@ -625,16 +623,6 @@ int eyemMatAt(EyemImage tpImage, EyemOcsIXY tpPoint)
return FUNC_OK; return FUNC_OK;
} }
//int eyemCopyRegion(EyemImage tpImage, EyemRotateRect tpRoi, EyemImage *tpDstImg)
//{
// CV_Assert(NULL != tpImage.vpImage);
//
// cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
//
//
// return FUNC_OK;
//}
int eyemNormalize(EyemImage &tpImage) int eyemNormalize(EyemImage &tpImage)
{ {
CV_Assert(NULL != tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage);
...@@ -676,4 +664,44 @@ int eyemNormalize(EyemImage &tpImage) ...@@ -676,4 +664,44 @@ int eyemNormalize(EyemImage &tpImage)
memcpy(tpImage.vpImage, image.data, _Size); memcpy(tpImage.vpImage, image.data, _Size);
return FUNC_OK; return FUNC_OK;
}
int eyemScaleImage(EyemImage tpImage, EyemImage *tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
return FUNC_OK;
}
int eyemScaleImageMax(EyemImage tpImage, EyemImage *tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
return FUNC_OK;
}
int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, EyemImage *tpDstImg, int iInterMethod = 1)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
double matx[6];
cv::Mat matM = cv::Mat(2, 3, CV_64F, matx);
matM.at<double>(0, 0) = 1.0;
matM.at<double>(0, 1) = 0.0;
matM.at<double>(0, 2) = dShiftX;
matM.at<double>(1, 0) = 0.0;
matM.at<double>(1, 1) = 1.0;
matM.at<double>(1, 2) = dShiftY;
cv::Mat imageShift;
cv::warpAffine(image, imageShift, matM, image.size(), iInterMethod, 0);
return FUNC_OK;
} }
\ No newline at end of file \ No newline at end of file
#include "eyemSmooth.h" #include "eyemSmooth.h"
class NonlocalMeansFilterInvorker8u_SSE4 : public cv::ParallelLoopBody
{
private:
cv::Mat* im;
cv::Mat* dest;
int templeteWindowSizeX;
int templeteWindowSizeY;
int searchWindowSizeX;
int searchWindowSizeY;
float* w;
public:
NonlocalMeansFilterInvorker8u_SSE4(cv::Mat& src_, cv::Mat& dest_, int templeteWindowSizeX_, int templeteWindowSizeY_, int searchWindowSizeX_, int searchWindowSizeY_, float* weight)
: im(&src_), dest(&dest_), templeteWindowSizeX(templeteWindowSizeX_), templeteWindowSizeY(templeteWindowSizeY_), searchWindowSizeX(searchWindowSizeX_), searchWindowSizeY(searchWindowSizeY_), w(weight)
{
;
}
virtual void operator()(const cv::Range &r) const
{
const int tr_x = templeteWindowSizeX >> 1;
const int sr_x = searchWindowSizeX >> 1;
const int tr_y = templeteWindowSizeY >> 1;
const int sr_y = searchWindowSizeY >> 1;
const int cstep = im->cols - templeteWindowSizeX;
const int imstep = im->cols;
const int tD = templeteWindowSizeX*templeteWindowSizeY;
const float tdiv = 1.f / (float)(tD);//templete square div
__m128 mtdiv = _mm_set1_ps(tdiv);
if (dest->channels() == 3)
{
const int colorstep = im->size().area() / 3;
const int colorstep2 = colorstep * 2;
int CV_DECL_ALIGNED(16) buf[16];
const __m128i zero = _mm_setzero_si128();
for (int j = r.start; j < r.end; j++)
{
uchar* d = dest->ptr<uchar>(j);
const uchar* tprt_ = im->ptr<uchar>(sr_y + j) + sr_x;
const uchar* sptr2_ = im->ptr<uchar>(j);
for (int i = 0; i < dest->cols; i += 16)
{
__m128 mr0 = _mm_setzero_ps();
__m128 mr1 = _mm_setzero_ps();
__m128 mr2 = _mm_setzero_ps();
__m128 mr3 = _mm_setzero_ps();
__m128 mg0 = _mm_setzero_ps();
__m128 mg1 = _mm_setzero_ps();
__m128 mg2 = _mm_setzero_ps();
__m128 mg3 = _mm_setzero_ps();
__m128 mb0 = _mm_setzero_ps();
__m128 mb1 = _mm_setzero_ps();
__m128 mb2 = _mm_setzero_ps();
__m128 mb3 = _mm_setzero_ps();
__m128 mtweight0 = _mm_setzero_ps();
__m128 mtweight1 = _mm_setzero_ps();
__m128 mtweight2 = _mm_setzero_ps();
__m128 mtweight3 = _mm_setzero_ps();
//search loop
const uchar* tprt = tprt_ + i;
const uchar* sptr2 = sptr2_ + i;
for (int l = searchWindowSizeY; l--;)
{
const uchar* sptr = sptr2 + imstep*(l);
for (int k = searchWindowSizeX; k--;)
{
uchar* t = (uchar*)tprt;
uchar* s = (uchar*)(sptr + k);
//colorstep
__m128i me0 = _mm_setzero_si128();
__m128i me1 = _mm_setzero_si128();
for (int n = templeteWindowSizeY; n--;)
{
for (int m = templeteWindowSizeX; m--;)
{
// computing color L2 norm
__m128i ms = _mm_loadu_si128((__m128i*)s);
__m128i mt = _mm_loadu_si128((__m128i*)t);
ms = _mm_add_epi8(_mm_subs_epu8(ms, mt), _mm_subs_epu8(mt, ms));
__m128i s0 = _mm_unpacklo_epi8(ms, zero);
__m128i s1 = _mm_unpackhi_epi8(ms, zero);
me0 = _mm_adds_epu16(me0, s0);
me1 = _mm_adds_epu16(me1, s1);
ms = _mm_loadu_si128((__m128i*)(s + colorstep));
mt = _mm_loadu_si128((__m128i*)(t + colorstep));
ms = _mm_add_epi8(_mm_subs_epu8(ms, mt), _mm_subs_epu8(mt, ms));
s0 = _mm_unpacklo_epi8(ms, zero);
s1 = _mm_unpackhi_epi8(ms, zero);
me0 = _mm_adds_epu16(me0, s0);
me1 = _mm_adds_epu16(me1, s1);
ms = _mm_loadu_si128((__m128i*)(s + colorstep2));
mt = _mm_loadu_si128((__m128i*)(t + colorstep2));
ms = _mm_add_epi8(_mm_subs_epu8(ms, mt), _mm_subs_epu8(mt, ms));
s0 = _mm_unpacklo_epi8(ms, zero);
s1 = _mm_unpackhi_epi8(ms, zero);
me0 = _mm_adds_epu16(me0, s0);
me1 = _mm_adds_epu16(me1, s1);
s++, t++;
}
t += cstep;
s += cstep;
}
__m128i mme0 = _mm_unpacklo_epi16(me0, zero);
__m128i mme1 = _mm_unpackhi_epi16(me0, zero);
__m128i mme2 = _mm_unpacklo_epi16(me1, zero);
__m128i mme3 = _mm_unpackhi_epi16(me1, zero);
_mm_store_si128((__m128i*)(buf), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme0))));
_mm_store_si128((__m128i*)(buf + 4), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme1))));
_mm_store_si128((__m128i*)(buf + 8), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme2))));
_mm_store_si128((__m128i*)(buf + 12), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme3))));
const uchar* ss = sptr2 + imstep*(tr_y + l) + (tr_x + k);
const __m128i sc0 = _mm_loadu_si128((__m128i*)(ss));
const __m128i sc1 = _mm_loadu_si128((__m128i*)(ss + colorstep));
const __m128i sc2 = _mm_loadu_si128((__m128i*)(ss + colorstep2));
__m128i sr0 = _mm_unpacklo_epi8(sc0, zero);
__m128i sr1 = _mm_unpackhi_epi16(sr0, zero);
sr0 = _mm_unpacklo_epi16(sr0, zero);
__m128i sr2 = _mm_unpackhi_epi8(sc0, zero);
__m128i sr3 = _mm_unpackhi_epi16(sr2, zero);
sr2 = _mm_unpacklo_epi16(sr2, zero);
__m128i sg0 = _mm_unpacklo_epi8(sc1, zero);
__m128i sg1 = _mm_unpackhi_epi16(sg0, zero);
sg0 = _mm_unpacklo_epi16(sg0, zero);
__m128i sg2 = _mm_unpackhi_epi8(sc1, zero);
__m128i sg3 = _mm_unpackhi_epi16(sg2, zero);
sg2 = _mm_unpacklo_epi16(sg2, zero);
__m128i sb0 = _mm_unpacklo_epi8(sc2, zero);
__m128i sb1 = _mm_unpackhi_epi16(sb0, zero);
sb0 = _mm_unpacklo_epi16(sb0, zero);
__m128i sb2 = _mm_unpackhi_epi8(sc2, zero);
__m128i sb3 = _mm_unpackhi_epi16(sb2, zero);
sb2 = _mm_unpacklo_epi16(sb2, zero);
__m128 www = _mm_set_ps(w[buf[3]], w[buf[2]], w[buf[1]], w[buf[0]]);
mr0 = _mm_add_ps(mr0, _mm_mul_ps(www, _mm_cvtepi32_ps(sr0)));
mg0 = _mm_add_ps(mg0, _mm_mul_ps(www, _mm_cvtepi32_ps(sg0)));
mb0 = _mm_add_ps(mb0, _mm_mul_ps(www, _mm_cvtepi32_ps(sb0)));
mtweight0 = _mm_add_ps(mtweight0, www);
www = _mm_set_ps(w[buf[7]], w[buf[6]], w[buf[5]], w[buf[4]]);
mr1 = _mm_add_ps(mr1, _mm_mul_ps(www, _mm_cvtepi32_ps(sr1)));
mg1 = _mm_add_ps(mg1, _mm_mul_ps(www, _mm_cvtepi32_ps(sg1)));
mb1 = _mm_add_ps(mb1, _mm_mul_ps(www, _mm_cvtepi32_ps(sb1)));
mtweight1 = _mm_add_ps(mtweight1, www);
www = _mm_set_ps(w[buf[11]], w[buf[10]], w[buf[9]], w[buf[8]]);
mr2 = _mm_add_ps(mr2, _mm_mul_ps(www, _mm_cvtepi32_ps(sr2)));
mg2 = _mm_add_ps(mg2, _mm_mul_ps(www, _mm_cvtepi32_ps(sg2)));
mb2 = _mm_add_ps(mb2, _mm_mul_ps(www, _mm_cvtepi32_ps(sb2)));
mtweight2 = _mm_add_ps(mtweight2, www);
www = _mm_set_ps(w[buf[15]], w[buf[14]], w[buf[13]], w[buf[12]]);
mr3 = _mm_add_ps(mr3, _mm_mul_ps(www, _mm_cvtepi32_ps(sr3)));
mg3 = _mm_add_ps(mg3, _mm_mul_ps(www, _mm_cvtepi32_ps(sg3)));
mb3 = _mm_add_ps(mb3, _mm_mul_ps(www, _mm_cvtepi32_ps(sb3)));
mtweight3 = _mm_add_ps(mtweight3, www);
}
}
mr0 = _mm_div_ps(mr0, mtweight0);
mr1 = _mm_div_ps(mr1, mtweight1);
mr2 = _mm_div_ps(mr2, mtweight2);
mr3 = _mm_div_ps(mr3, mtweight3);
__m128i a = _mm_packus_epi16(_mm_packs_epi32(_mm_cvtps_epi32(mr0), _mm_cvtps_epi32(mr1)), _mm_packs_epi32(_mm_cvtps_epi32(mr2), _mm_cvtps_epi32(mr3)));
mg0 = _mm_div_ps(mg0, mtweight0);
mg1 = _mm_div_ps(mg1, mtweight1);
mg2 = _mm_div_ps(mg2, mtweight2);
mg3 = _mm_div_ps(mg3, mtweight3);
__m128i b = _mm_packus_epi16(_mm_packs_epi32(_mm_cvtps_epi32(mg0), _mm_cvtps_epi32(mg1)), _mm_packs_epi32(_mm_cvtps_epi32(mg2), _mm_cvtps_epi32(mg3)));
mb0 = _mm_div_ps(mb0, mtweight0);
mb1 = _mm_div_ps(mb1, mtweight1);
mb2 = _mm_div_ps(mb2, mtweight2);
mb3 = _mm_div_ps(mb3, mtweight3);
__m128i c = _mm_packus_epi16(_mm_packs_epi32(_mm_cvtps_epi32(mb0), _mm_cvtps_epi32(mb1)), _mm_packs_epi32(_mm_cvtps_epi32(mb2), _mm_cvtps_epi32(mb3)));
//sse4///
const __m128i mask1 = _mm_setr_epi8(0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5);
const __m128i mask2 = _mm_setr_epi8(5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10);
const __m128i mask3 = _mm_setr_epi8(10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15);
const __m128i bmask1 = _mm_setr_epi8(0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0);
const __m128i bmask2 = _mm_setr_epi8(255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255);
a = _mm_shuffle_epi8(a, mask1);
b = _mm_shuffle_epi8(b, mask2);
c = _mm_shuffle_epi8(c, mask3);
_mm_stream_si128((__m128i*)(d), _mm_blendv_epi8(c, _mm_blendv_epi8(a, b, bmask1), bmask2));
_mm_stream_si128((__m128i*)(d + 16), _mm_blendv_epi8(b, _mm_blendv_epi8(a, c, bmask2), bmask1));
_mm_stream_si128((__m128i*)(d + 32), _mm_blendv_epi8(c, _mm_blendv_epi8(b, a, bmask2), bmask1));
d += 48;
}//i
}//j
}
else if (dest->channels() == 1)
{
int CV_DECL_ALIGNED(16) buf[16];
const __m128i zero = _mm_setzero_si128();
for (int j = r.start; j < r.end; j++)
{
uchar* d = dest->ptr<uchar>(j);
for (int i = 0; i < dest->cols; i += 16)
{
__m128 mvalue0 = _mm_setzero_ps();
__m128 mvalue1 = _mm_setzero_ps();
__m128 mvalue2 = _mm_setzero_ps();
__m128 mvalue3 = _mm_setzero_ps();
__m128 mtweight0 = _mm_setzero_ps();
__m128 mtweight1 = _mm_setzero_ps();
__m128 mtweight2 = _mm_setzero_ps();
__m128 mtweight3 = _mm_setzero_ps();
//search loop
uchar* tprt = im->ptr<uchar>(sr_y + j) + (sr_x + i);
uchar* sptr2 = im->ptr<uchar>(j) + (i);
for (int l = searchWindowSizeY; l--;)
{
uchar* sptr = sptr2 + imstep*(l);
for (int k = searchWindowSizeX; k--;)
{
//templete loop
__m128i me0 = _mm_setzero_si128();
__m128i me1 = _mm_setzero_si128();
uchar* t = tprt;
uchar* s = sptr + k;
for (int n = templeteWindowSizeY; n--;)
{
for (int m = templeteWindowSizeX; m--;)
{
// computing color L2 norm
__m128i ms = _mm_loadu_si128((__m128i*)s);
__m128i mt = _mm_loadu_si128((__m128i*)t);
ms = _mm_add_epi8(_mm_subs_epu8(ms, mt), _mm_subs_epu8(mt, ms));
__m128i s0 = _mm_unpacklo_epi8(ms, zero);
__m128i s1 = _mm_unpackhi_epi8(ms, zero);
me0 = _mm_adds_epu16(me0, s0);
me1 = _mm_adds_epu16(me1, s1);
s++, t++;
}
t += cstep;
s += cstep;
}
__m128i mme0 = _mm_unpacklo_epi16(me0, zero);
__m128i mme1 = _mm_unpackhi_epi16(me0, zero);
__m128i mme2 = _mm_unpacklo_epi16(me1, zero);
__m128i mme3 = _mm_unpackhi_epi16(me1, zero);
_mm_store_si128((__m128i*)(buf), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme0))));
_mm_store_si128((__m128i*)(buf + 4), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme1))));
_mm_store_si128((__m128i*)(buf + 8), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme2))));
_mm_store_si128((__m128i*)(buf + 12), _mm_cvtps_epi32(_mm_mul_ps(mtdiv, _mm_cvtepi32_ps(mme3))));
const __m128i sc = _mm_loadu_si128((__m128i*)(sptr2 + imstep*(tr_y + l) + tr_x + k));
__m128i s0 = _mm_unpacklo_epi8(sc, zero);
__m128i s1 = _mm_unpackhi_epi16(s0, zero);
s0 = _mm_unpacklo_epi16(s0, zero);
__m128i s2 = _mm_unpackhi_epi8(sc, zero);
__m128i s3 = _mm_unpackhi_epi16(s2, zero);
s2 = _mm_unpacklo_epi16(s2, zero);
__m128 www = _mm_set_ps(w[buf[3]], w[buf[2]], w[buf[1]], w[buf[0]]);
mvalue0 = _mm_add_ps(mvalue0, _mm_mul_ps(www, _mm_cvtepi32_ps(s0)));
mtweight0 = _mm_add_ps(mtweight0, www);
www = _mm_set_ps(w[buf[7]], w[buf[6]], w[buf[5]], w[buf[4]]);
mvalue1 = _mm_add_ps(mvalue1, _mm_mul_ps(www, _mm_cvtepi32_ps(s1)));
mtweight1 = _mm_add_ps(mtweight1, www);
www = _mm_set_ps(w[buf[11]], w[buf[10]], w[buf[9]], w[buf[8]]);
mvalue2 = _mm_add_ps(mvalue2, _mm_mul_ps(www, _mm_cvtepi32_ps(s2)));
mtweight2 = _mm_add_ps(mtweight2, www);
www = _mm_set_ps(w[buf[15]], w[buf[14]], w[buf[13]], w[buf[12]]);
mvalue3 = _mm_add_ps(mvalue3, _mm_mul_ps(www, _mm_cvtepi32_ps(s3)));
mtweight3 = _mm_add_ps(mtweight3, www);
}
}
//weight normalization
_mm_stream_si128((__m128i*)(d), _mm_packus_epi16(
_mm_packs_epi32(_mm_cvtps_epi32(_mm_div_ps(mvalue0, mtweight0)), _mm_cvtps_epi32(_mm_div_ps(mvalue1, mtweight1))),
_mm_packs_epi32(_mm_cvtps_epi32(_mm_div_ps(mvalue2, mtweight2)), _mm_cvtps_epi32(_mm_div_ps(mvalue3, mtweight3)))));
d += 16;
}//i
}//j
}
}
};
static void nonLocalMeansFilter_SSE(cv::Mat& src, cv::Mat& dest, cv::Size templeteWindowSize, cv::Size searchWindowSize, double h, double sigma, int borderType)
{
if (dest.empty())dest = cv::Mat::zeros(src.size(), src.type());
const int bbx = (templeteWindowSize.width >> 1) + (searchWindowSize.width >> 1);
const int bby = (templeteWindowSize.height >> 1) + (searchWindowSize.height >> 1);
// const int D = searchWindowSize*searchWindowSize;
int dpad;
int spad;
//create large size image for bounding box;
if (src.depth() == CV_8U)
{
dpad = (16 - src.cols % 16) % 16;
spad = (16 - (src.cols + 2 * bbx) % 16) % 16;
}
cv::Mat dst = cv::Mat::zeros(cv::Size(src.cols + dpad, src.rows), dest.type());
cv::Mat im;
copyMakeBorder(src, im, bby, bby, bbx, bbx + spad, borderType);
//weight computation;
std::vector<float> weight(256 * src.channels());
weight.resize(256);
float* w = &weight[0];
const double gauss_sd = (sigma == 0.0) ? h : sigma;
double gauss_color_coeff = -(1.0 / (double)(src.channels()))*(1.0 / (h*h));
for (int i = 0; i < 256 * src.channels(); i++)
{
double v = std::exp(std::max(i*i - 2.0*gauss_sd*gauss_sd, 0.0)*gauss_color_coeff);
w[i] = (float)v;
}
NonlocalMeansFilterInvorker8u_SSE4 body(im, dst, templeteWindowSize.width, templeteWindowSize.height, searchWindowSize.width, searchWindowSize.height, w);
cv::parallel_for_(cv::Range(0, dst.rows), body);
cv::Mat(dst(cv::Rect(0, 0, dest.cols, dest.rows))).copyTo(dest);
}
int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg) int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg)
{ {
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
...@@ -12,6 +361,16 @@ int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstIm ...@@ -12,6 +361,16 @@ int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstIm
return FUNC_OK; return FUNC_OK;
} }
int eyemNonLocalMeansFilter(EyemImage tpImage)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
return FUNC_OK;
}
int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg) int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg)
{ {
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
...@@ -34,4 +393,61 @@ int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg) ...@@ -34,4 +393,61 @@ int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg)
cv::Mat dst; cv::Mat dst;
cv::medianBlur(image, dst, kSize); cv::medianBlur(image, dst, kSize);
return FUNC_OK; return FUNC_OK;
}
int eyemShockFilter(EyemImage tpImage, int kSize, double dSigma, double dBlend, const int iIter, EyemImage *tpDstImg)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
//仅支持单通道灰度图像
cv::Mat imageGray;
int incn = image.channels();
if (incn > 3) {
cv::cvtColor(image, imageGray, cv::COLOR_BGRA2GRAY);
}
else if (incn == 3) {
cv::cvtColor(image, imageGray, cv::COLOR_BGR2GRAY);
}
else {
imageGray = image;
}
cv::Mat dest = imageGray.clone();
//转float类型
imageGray.convertTo(imageGray, CV_32F);
//迭代恢复
const int sigma = std::min(31, (int)dSigma);
for (int i = 0; i < iIter; i++)
{
cv::Mat eigen;
cv::cornerEigenValsAndVecs(imageGray, eigen, sigma, 3);
std::vector<cv::Mat> esplit(6);
cv::split(eigen, esplit);
cv::Mat x = esplit[2]; cv::Mat y = esplit[3];
cv::Mat gxx, gyy, gxy;
cv::Sobel(imageGray, gxx, CV_32F, 2, 0, kSize);
cv::Sobel(imageGray, gyy, CV_32F, 0, 2, kSize);
cv::Sobel(imageGray, gxy, CV_32F, 1, 1, kSize);
cv::Mat gvv = x.mul(x).mul(gxx) + 2 * x.mul(y).mul(gxy) + y.mul(y).mul(gyy);
cv::Mat mask;
cv::compare(gvv, 0, mask, cv::CMP_LT);
cv::Mat di, ero;
cv::erode(dest, ero, cv::Mat());
cv::dilate(dest, di, cv::Mat());
di.copyTo(ero, mask);
cv::addWeighted(dest, dBlend, ero, 1.0 - dBlend, 0.0, dest);
}
cv::Mat dst;
dest.convertTo(dst, CV_8U);
return FUNC_OK;
} }
\ No newline at end of file \ No newline at end of file
此文件太大,无法显示。
此文件太大,无法显示。
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!