Commit 2fc4e743 张士柳

1 个父辈 6c7e636f
...@@ -36,6 +36,15 @@ namespace eyemLib_Sharp ...@@ -36,6 +36,15 @@ namespace eyemLib_Sharp
image = eyemCvtToEyemImage(bitmap); image = eyemCvtToEyemImage(bitmap);
} }
/// <summary> /// <summary>
/// EyemImage转Bitmap格式图像
/// </summary>
/// <returns></returns>
public Bitmap ToBitmap()
{
return null;
}
/// <summary>
/// 隐式转换成EyemImage /// 隐式转换成EyemImage
/// </summary> /// </summary>
/// <param name="operand"></param> /// <param name="operand"></param>
......
...@@ -37,6 +37,37 @@ ...@@ -37,6 +37,37 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseVSHostingProcess>true</UseVSHostingProcess> <UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseV455|AnyCPU'">
<OutputPath>..\x64\ReleaseV455\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_V455|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\x64\Debug_V455\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_V420Qisda|AnyCPU'">
<OutputPath>..\x64\Release_V420Qisda\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
......
...@@ -12,30 +12,72 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eyemLib-Sharp", "eyemLib-Sh ...@@ -12,30 +12,72 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eyemLib-Sharp", "eyemLib-Sh
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_V455|Any CPU = Debug_V455|Any CPU
Debug_V455|x64 = Debug_V455|x64
Debug_V455|x86 = Debug_V455|x86
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Debug|x86 = Debug|x86 Debug|x86 = Debug|x86
Release_V420Qisda|Any CPU = Release_V420Qisda|Any CPU
Release_V420Qisda|x64 = Release_V420Qisda|x64
Release_V420Qisda|x86 = Release_V420Qisda|x86
Release_V455|Any CPU = Release_V455|Any CPU
Release_V455|x64 = Release_V455|x64
Release_V455|x86 = Release_V455|x86
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64 Release|x64 = Release|x64
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug_V455|Any CPU.ActiveCfg = Debug_V455|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug_V455|x64.ActiveCfg = Debug_V455|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug_V455|x64.Build.0 = Debug_V455|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug_V455|x86.ActiveCfg = Debug_V455|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug_V455|x86.Build.0 = Debug_V455|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|Any CPU.ActiveCfg = Debug|Win32 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|Any CPU.ActiveCfg = Debug|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x64.ActiveCfg = Debug|x64 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x64.ActiveCfg = Debug|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x64.Build.0 = Debug|x64 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x64.Build.0 = Debug|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x86.ActiveCfg = Debug|Win32 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x86.ActiveCfg = Debug|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x86.Build.0 = Debug|Win32 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Debug|x86.Build.0 = Debug|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V420Qisda|Any CPU.ActiveCfg = Release_V420Qisda|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V420Qisda|x64.ActiveCfg = Release_V420Qisda|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V420Qisda|x64.Build.0 = Release_V420Qisda|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V420Qisda|x86.ActiveCfg = Release_V420Qisda|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V420Qisda|x86.Build.0 = Release_V420Qisda|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V455|Any CPU.ActiveCfg = ReleaseV455|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V455|x64.ActiveCfg = ReleaseV455|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V455|x64.Build.0 = ReleaseV455|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V455|x86.ActiveCfg = ReleaseV455|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release_V455|x86.Build.0 = ReleaseV455|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|Any CPU.ActiveCfg = Release|Win32 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|Any CPU.ActiveCfg = Release|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x64.ActiveCfg = Release|x64 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x64.ActiveCfg = Release|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x64.Build.0 = Release|x64 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x64.Build.0 = Release|x64
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x86.ActiveCfg = Release|Win32 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x86.ActiveCfg = Release|Win32
{33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x86.Build.0 = Release|Win32 {33D5F550-C799-4B05-8E14-ACA390DF5442}.Release|x86.Build.0 = Release|Win32
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug_V455|Any CPU.ActiveCfg = Debug_V455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug_V455|Any CPU.Build.0 = Debug_V455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug_V455|x64.ActiveCfg = Debug_V455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug_V455|x64.Build.0 = Debug_V455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug_V455|x86.ActiveCfg = Debug_V455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug_V455|x86.Build.0 = Debug_V455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x64.ActiveCfg = Debug|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x64.ActiveCfg = Debug|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x64.Build.0 = Debug|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x64.Build.0 = Debug|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x86.ActiveCfg = Debug|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x86.ActiveCfg = Debug|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x86.Build.0 = Debug|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Debug|x86.Build.0 = Debug|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V420Qisda|Any CPU.ActiveCfg = Release_V420Qisda|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V420Qisda|Any CPU.Build.0 = Release_V420Qisda|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V420Qisda|x64.ActiveCfg = Release_V420Qisda|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V420Qisda|x64.Build.0 = Release_V420Qisda|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V420Qisda|x86.ActiveCfg = Release_V420Qisda|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V420Qisda|x86.Build.0 = Release_V420Qisda|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V455|Any CPU.ActiveCfg = ReleaseV455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V455|Any CPU.Build.0 = ReleaseV455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V455|x64.ActiveCfg = ReleaseV455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V455|x64.Build.0 = ReleaseV455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V455|x86.ActiveCfg = ReleaseV455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release_V455|x86.Build.0 = ReleaseV455|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|Any CPU.ActiveCfg = Release|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|Any CPU.Build.0 = Release|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|Any CPU.Build.0 = Release|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|x64.ActiveCfg = Release|Any CPU {C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|x64.ActiveCfg = Release|Any CPU
......
...@@ -6,7 +6,7 @@ int AZONNXWrapper::init(const std::string& model_path) ...@@ -6,7 +6,7 @@ int AZONNXWrapper::init(const std::string& model_path)
//加载并初始化网络 //加载并初始化网络
net_ = cv::dnn::readNetFromONNX(model_path); net_ = cv::dnn::readNetFromONNX(model_path);
net_.setPreferableBackend(cv::dnn::Backend::DNN_BACKEND_OPENCV); net_.setPreferableBackend(cv::dnn::Backend::DNN_BACKEND_OPENCV);
net_.setPreferableTarget(cv::dnn::Target::DNN_TARGET_CPU); net_.setPreferableTarget(cv::dnn::Target::DNN_TARGET_OPENCL);
return 0; return 0;
} }
return -1; return -1;
...@@ -25,7 +25,7 @@ float* AZONNXWrapper::forward(cv::Mat img, cv::Scalar mean, cv::Scalar std) ...@@ -25,7 +25,7 @@ float* AZONNXWrapper::forward(cv::Mat img, cv::Scalar mean, cv::Scalar std)
cv::cvtColor(img, input, cv::COLOR_BGR2RGB); cv::cvtColor(img, input, cv::COLOR_BGR2RGB);
} }
else { else {
input = img.clone(); img.copyTo(input);
} }
//转float类型 //转float类型
input.convertTo(input, CV_32F, 1 / 255.); input.convertTo(input, CV_32F, 1 / 255.);
...@@ -51,4 +51,53 @@ AZONNXWrapper::~AZONNXWrapper() ...@@ -51,4 +51,53 @@ AZONNXWrapper::~AZONNXWrapper()
{ {
delete[] predictions; delete[] predictions;
predictions = NULL; predictions = NULL;
}
int AZONNXWrapperEx::init(const std::string& model_path)
{
if (!model_path.empty()) {
//加载并初始化网络
net_ = cv::dnn::readNetFromONNX(model_path);
net_.setPreferableBackend(cv::dnn::Backend::DNN_BACKEND_OPENCV);
net_.setPreferableTarget(cv::dnn::Target::DNN_TARGET_CPU);
return 0;
}
return -1;
}
cv::Mat AZONNXWrapperEx::forward(cv::Mat& img)
{
CV_Assert(!img.empty());
//图像预处理,仅支持单通道
cv::Mat input;
int incn = img.channels();
if (incn > 1) {
cv::cvtColor(img, input, cv::COLOR_BGR2GRAY);
}
else {
img.copyTo(input);
}
//转float类型
input.convertTo(input, CV_32F, 1 / 255.);
//设定输出
cv::Mat blob = cv::dnn::blobFromImage(input);
net_.setInput(blob);
//推理
cv::Mat predicts = net_.forward();
//获取结果
std::vector<cv::Mat> blobs;
cv::dnn::imagesFromBlob(predicts, blobs);
cv::split(blobs[0], blobs);
//显示
cv::Mat mask = blobs[1] > 0;
return mask;
}
AZONNXWrapperEx::AZONNXWrapperEx() {
}
AZONNXWrapperEx::~AZONNXWrapperEx()
{
} }
\ No newline at end of file \ No newline at end of file
...@@ -21,4 +21,15 @@ private: ...@@ -21,4 +21,15 @@ private:
cv::dnn::Net net_; cv::dnn::Net net_;
}; };
class AZONNXWrapperEx
{
public:
AZONNXWrapperEx();
~AZONNXWrapperEx();
int init(const std::string& model_path);
cv::Mat forward(cv::Mat& img);
private:
cv::dnn::Net net_;
};
#endif/* __AZONNXWRAPPER_H */ #endif/* __AZONNXWRAPPER_H */
...@@ -994,7 +994,6 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double ...@@ -994,7 +994,6 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double
//执行二值化操作 //执行二值化操作
cv::threshold(image, binary, dThresh, dMaxVal, iLightDark); cv::threshold(image, binary, dThresh, dMaxVal, iLightDark);
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels(); tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸 //内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t); int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存 //分配初始化内存
...@@ -1004,7 +1003,6 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double ...@@ -1004,7 +1003,6 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double
memset(tpDstImg->vpImage, 0, _Size); memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据 //拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size); memcpy(tpDstImg->vpImage, binary.data, _Size);
return FUNC_OK; return FUNC_OK;
} }
...@@ -1022,7 +1020,6 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b ...@@ -1022,7 +1020,6 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b
CV_Assert(dR != 0); CV_Assert(dR != 0);
} }
iType &= cv::THRESH_MASK; iType &= cv::THRESH_MASK;
cv::Mat thresh; cv::Mat thresh;
{ {
cv::Mat mean, sqmean, variance, stddev, sqrtVarianceMeanSum; cv::Mat mean, sqmean, variance, stddev, sqrtVarianceMeanSum;
...@@ -1057,7 +1054,6 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b ...@@ -1057,7 +1054,6 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b
} }
cv::Mat dst(src.size(), CV_8U); cv::Mat dst(src.size(), CV_8U);
cv::Mat mask; cv::Mat mask;
switch (iType) switch (iType)
{ {
...@@ -1081,37 +1077,27 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b ...@@ -1081,37 +1077,27 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b
default: default:
break; break;
} }
//输出图像 //输出图像
{ tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels();
tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels(); //内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//内存尺寸 //分配内存
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t); tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
//分配内存 return FUNC_NOT_ENOUGH_MEM;
tpDstImg->vpImage = (uint8_t *)malloc(_Size); memset(tpDstImg->vpImage, 0, _Size);
if (NULL == tpDstImg->vpImage) //拷贝数据
return FUNC_NOT_ENOUGH_MEM; memcpy(tpDstImg->vpImage, dst.data, _Size);
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, dst.data, _Size);
}
return FUNC_OK; return FUNC_OK;
} }
int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, int iType, EyemImage *tpDstImg) int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, int iType, EyemImage *tpDstImg)
{ {
CV_Assert(MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels) == MAKETYPE(tpPreImg.iDepth, tpPreImg.iChannels)); CV_Assert(MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels) == MAKETYPE(tpPreImg.iDepth, tpPreImg.iChannels));
cv::Mat image = cv::Mat(tpSrcImg.iHeight, tpSrcImg.iWidth, MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels), tpSrcImg.vpImage).clone(); cv::Mat image = cv::Mat(tpSrcImg.iHeight, tpSrcImg.iWidth, MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels), tpSrcImg.vpImage).clone();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
cv::Mat imagePre, variance; cv::Mat imagePre, variance;
cv::Mat thresh; cv::Mat thresh;
{ {
...@@ -1136,37 +1122,29 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, ...@@ -1136,37 +1122,29 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset,
} }
cv::Mat binary, showMat; cv::Mat binary, showMat;
cv::compare(variance, cv::Mat::ones(imagePre.size(), imagePre.type())*dOffset, binary, cv::CMP_GT); cv::compare(variance, cv::Mat::ones(imagePre.size(), imagePre.type())*dOffset, binary, cv::CMP_GT);
//输出结果图像 //输出结果图像
{ if (NULL != tpDstImg->vpImage) {
if (NULL != tpDstImg->vpImage) { tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0;
tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0; //释放
//释放 free(tpDstImg->vpImage);
free(tpDstImg->vpImage); tpDstImg->vpImage = NULL;
tpDstImg->vpImage = NULL;
}
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
} }
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
return FUNC_OK; return FUNC_OK;
} }
int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int binMethod, EyemImage *tpDstImg) int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int binMethod, 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();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
...@@ -1215,31 +1193,23 @@ int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int b ...@@ -1215,31 +1193,23 @@ int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int b
cv::Mat binary; cv::Mat binary;
cv::threshold(image, binary, threshold, 255, iLightDark); cv::threshold(image, binary, threshold, 255, iLightDark);
//输出结果图像 //输出结果图像
{ if (NULL != tpDstImg->vpImage) {
if (NULL != tpDstImg->vpImage) { tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0;
tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0; //释放
//释放 free(tpDstImg->vpImage);
free(tpDstImg->vpImage); tpDstImg->vpImage = NULL;
tpDstImg->vpImage = NULL;
}
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
} }
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
return FUNC_OK; return FUNC_OK;
} }
......
...@@ -108,22 +108,20 @@ std::vector<std::string> CodeDetector::Impl::decode(const cv::Mat& img, std::vec ...@@ -108,22 +108,20 @@ std::vector<std::string> CodeDetector::Impl::decode(const cv::Mat& img, std::vec
logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:裁剪图像"); logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:裁剪图像");
cv::Rect crop_roi(crop_x_, crop_y_, end_x - crop_x_ + 1, end_y - crop_y_ + 1); cv::Rect crop_roi(crop_x_, crop_y_, end_x - crop_x_ + 1, end_y - crop_y_ + 1);
cv::Mat cropped_img = img(crop_roi); cv::Mat cropped_img = img(crop_roi);
//测试用
//cv::imwrite("21.png", cropped_img);
//转单通道 //转单通道
cv::cvtColor(cropped_img, cropped_img, cv::COLOR_BGR2GRAY); cv::cvtColor(cropped_img, cropped_img, cv::COLOR_BGR2GRAY);
logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:获取多尺度信息"); logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:获取多尺度信息");
auto scale_list = getScaleList(cropped_img.cols, cropped_img.rows); auto scale_list = getScaleList(cropped_img.cols, cropped_img.rows);
for (auto cur_scale : scale_list) { for (auto cur_scale : scale_list) {
//测试用
//cv::medianBlur(cropped_img, cropped_img, 3);
//缩放图像 //缩放图像
cv::Mat scaled_img = cv::Mat scaled_img =
processImageScale(cropped_img, cur_scale); processImageScale(cropped_img, cur_scale);
std::string result; std::string result;
//解码 //解码
logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:开始调用外部dll解码");
std::vector<cv::Point> _points; std::vector<cv::Point> _points;
auto ret = decodeImage(scaled_img, result, false, 0, _points); auto ret = decodeImage(scaled_img.clone(), result, false, 0, _points);
logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:调用外部dll解码完成");
if (ret != -1) { if (ret != -1) {
//恢复真实尺度 //恢复真实尺度
logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:恢复真实尺度"); logger.t("__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:恢复真实尺度");
...@@ -144,11 +142,11 @@ std::vector<std::string> CodeDetector::Impl::decode(const cv::Mat& img, std::vec ...@@ -144,11 +142,11 @@ std::vector<std::string> CodeDetector::Impl::decode(const cv::Mat& img, std::vec
return decode_results; return decode_results;
} }
std::vector<std::string> CodeDetector::detectAndDecodeBarcode(cv::InputArray img, cv::Mat &showMat, std::vector<cv::Point> &points) { std::vector<std::string> CodeDetector::detectAndDecodeBarcode(cv::Mat& img, cv::Mat &showMat, std::vector<cv::Point> &points) {
CV_Assert(!img.empty()); CV_Assert(!img.empty());
if (img.cols() <= 40 || img.rows() <= 40) { if (img.cols <= 40 || img.rows <= 40) {
return std::vector<std::string>(); return std::vector<std::string>();
} }
cv::Mat input; cv::Mat input;
...@@ -160,7 +158,7 @@ std::vector<std::string> CodeDetector::detectAndDecodeBarcode(cv::InputArray img ...@@ -160,7 +158,7 @@ std::vector<std::string> CodeDetector::detectAndDecodeBarcode(cv::InputArray img
cv::cvtColor(img, input, cv::COLOR_GRAY2BGR);//根据配置支持三通道图像 cv::cvtColor(img, input, cv::COLOR_GRAY2BGR);//根据配置支持三通道图像
} }
else { else {
input = img.getMat(); input = img;
} }
//检测 //检测
......
...@@ -22,7 +22,7 @@ public: ...@@ -22,7 +22,7 @@ public:
std::vector<std::string> detectAndDecode(cv::InputArray img, std::vector<std::string> detectAndDecode(cv::InputArray img,
std::vector<cv::Rect> &points = std::vector<cv::Rect>(), std::vector<cv::Rect> &allpoints = std::vector<cv::Rect>()); std::vector<cv::Rect> &points = std::vector<cv::Rect>(), std::vector<cv::Rect> &allpoints = std::vector<cv::Rect>());
std::vector<std::string> detectAndDecodeBarcode(cv::InputArray img, cv::Mat &showMat, std::vector<cv::Point> &points = std::vector<cv::Point>()); std::vector<std::string> detectAndDecodeBarcode(cv::Mat& img, cv::Mat &showMat, std::vector<cv::Point> &points = std::vector<cv::Point>());
std::mutex _mtx; std::mutex _mtx;
......
...@@ -135,7 +135,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine ...@@ -135,7 +135,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
filterK[2 * nFilterSize - n] = -1; filterK[2 * nFilterSize - n] = -1;
} }
cv::Mat whalf(cv::Size(2 * nFilterSize + 1, 1), CV_32FC1, filterK); cv::Mat whalf(cv::Size(2 * nFilterSize + 1, 1), CV_32FC1, filterK);
//线采样,采用双三次插值 //线采样,双线性插值
cv::Size szMap(2 * iCapLength + 1, iCapWidth + 1); cv::Size szMap(2 * iCapLength + 1, iCapWidth + 1);
//结果 //结果
std::vector<EyemOcsDXY> *tpResults = new std::vector<EyemOcsDXY>(); std::vector<EyemOcsDXY> *tpResults = new std::vector<EyemOcsDXY>();
......
...@@ -127,26 +127,21 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, ...@@ -127,26 +127,21 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
int eyemImageFromBitmap(void *vpScan0, int iWidth, int iHeight, int iDepth, int iChannels, EyemImage *tpImage) int eyemImageFromBitmap(void *vpScan0, int iWidth, int iHeight, int iDepth, int iChannels, EyemImage *tpImage)
{ {
cv::Mat image = cv::Mat(iHeight, iWidth, MAKETYPE(iDepth, iChannels), vpScan0).clone(); cv::Mat image = cv::Mat(iHeight, iWidth, MAKETYPE(iDepth, iChannels), vpScan0).clone();
//在这里重新创建 //在这里重新创建
if (NULL != tpImage->vpImage) { if (NULL != tpImage->vpImage) {
tpImage->iWidth = tpImage->iHeight = tpImage->iDepth = tpImage->iChannels = 0; tpImage->iWidth = tpImage->iHeight = tpImage->iDepth = tpImage->iChannels = 0;
free(tpImage->vpImage); free(tpImage->vpImage);
tpImage->vpImage = NULL; tpImage->vpImage = NULL;
} }
//图像信息 //图像信息
tpImage->iWidth = image.cols; tpImage->iHeight = image.rows; tpImage->iDepth = image.depth(); tpImage->iChannels = image.channels(); tpImage->iWidth = image.cols; tpImage->iHeight = image.rows; tpImage->iDepth = image.depth(); tpImage->iChannels = image.channels();
//内存尺寸 //内存尺寸
int _Size = tpImage->iWidth*tpImage->iHeight*tpImage->iChannels * sizeof(uint8_t); int _Size = tpImage->iWidth*tpImage->iHeight*tpImage->iChannels * sizeof(uint8_t);
//分配内存 //分配内存
tpImage->vpImage = (uint8_t *)malloc(_Size); tpImage->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpImage->vpImage) if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM; return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size); memset(tpImage->vpImage, 0, _Size);
//拷贝信息 //拷贝信息
memcpy(tpImage->vpImage, vpScan0, _Size); memcpy(tpImage->vpImage, vpScan0, _Size);
return FUNC_OK; return FUNC_OK;
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#include <opencv.hpp> #include <opencv.hpp>
#ifndef FILEVERSION #ifndef FILEVERSION
#define FILEVERSION "2.4.8.4" #ifdef VQISDA
#define FILEVERSION "2.4.9.5 (Only Qisda)"
#else
#define FILEVERSION "2.4.9.5"
#endif
#endif #endif
#ifndef COPYRIGHT #ifndef COPYRIGHT
...@@ -104,7 +108,7 @@ ...@@ -104,7 +108,7 @@
#ifndef NULL #ifndef NULL
#ifdef __cplusplus #ifdef __cplusplus
#define NULL 0 #define NULL 0
#else #else
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
...@@ -114,6 +118,10 @@ ...@@ -114,6 +118,10 @@
typedef intptr_t IntPtr; typedef intptr_t IntPtr;
#endif #endif
#ifndef BOOL
typedef int BOOL;
#endif
typedef unsigned int CvLabel; typedef unsigned int CvLabel;
typedef std::map<CvLabel, cv::Scalar> Palete; typedef std::map<CvLabel, cv::Scalar> Palete;
...@@ -728,6 +736,13 @@ extern "C" { ...@@ -728,6 +736,13 @@ extern "C" {
// 模板匹配(eyemMatchShapes.cpp) // 模板匹配(eyemMatchShapes.cpp)
// //
typedef struct {
float fCenterX; // 中心X坐标
float fCenterY; // 中心Y坐标
float fMatchScore; // 匹配分数
float fMatchAngle; // 匹配角度
} EyemTargetMatch;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -737,6 +752,9 @@ extern "C" { ...@@ -737,6 +752,9 @@ extern "C" {
EXPORTS int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize = 3, bool bL2gradient = false); EXPORTS int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize = 3, bool bL2gradient = false);
EXPORTS int eyemFindShapeModel(EyemImage tpImage, int iNumLevels, double dAngleStart, double dAngleExtent, double dAngleStep, double dMinContrast, double dContrast, double dGreediness, double dMinScore, bool bOptimization = true); EXPORTS int eyemFindShapeModel(EyemImage tpImage, int iNumLevels, double dAngleStart, double dAngleExtent, double dAngleStep, double dMinContrast, double dContrast, double dGreediness, double dMinScore, bool bOptimization = true);
EXPORTS int eyemMakeNCCModel(EyemImage tpImage, int iMinReduceArea);
EXPORTS int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, EyemTargetMatch *tpResults);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
...@@ -923,11 +941,13 @@ extern "C" { ...@@ -923,11 +941,13 @@ extern "C" {
EXPORTS int eyemInitNNDataCodeModel(const char *detectorConfigPath, const char *detectorModelPath, const char *superResolutionConfigPath, const char *superResolutionModelPath); EXPORTS int eyemInitNNDataCodeModel(const char *detectorConfigPath, const char *detectorModelPath, const char *superResolutionConfigPath, const char *superResolutionModelPath);
EXPORTS int eyemDetectAndDecodeBarcodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, EyemImage *tpDstImg); EXPORTS int eyemDetectAndDecodeBarcodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, EyemImage *tpDstImg);
EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject); EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject);
EXPORTS int eyemInitCounter(const char *extractorModelPath);
EXPORTS int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg); EXPORTS int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg); EXPORTS int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char * ccSubType, int *ipReelNum, EyemImage *tpDstImg); EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char * ccSubType, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char *ccTplName, IntPtr hModelID, int *ipReelNum, EyemImage *tpDstImg); EXPORTS int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char *ccTplName, IntPtr hModelID, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int iOptions[4], int *ipReelNum, EyemImage *tpDstImg); EXPORTS int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int iOptions[4], int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectUseNN(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg); EXPORTS int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg); EXPORTS int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char *ccTplName); EXPORTS int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char *ccTplName);
...@@ -947,7 +967,10 @@ extern "C" { ...@@ -947,7 +967,10 @@ extern "C" {
EXPORTS int eyemDrawCircle(EyemImage tpImage, EyemOcsDXYR tpCircle); EXPORTS int eyemDrawCircle(EyemImage tpImage, EyemOcsDXYR tpCircle);
EXPORTS int eyemDrawRectangle(EyemImage tpImag, EyemRect tpRect); EXPORTS int eyemDrawRectangle(EyemImage tpImag, EyemRect tpRect);
EXPORTS int eyemTrainImageSampler(EyemImage tpImage, int iSize, const char *ccClassName, const char *ccToPath, EyemImage *tpMatchImg, EyemImage *tpDstImg); EXPORTS int eyemTrainImageSampler(EyemImage tpImage, int iSize, const char *ccClassName, const char *ccToPath, EyemImage *tpMatchImg, EyemImage *tpDstImg);
EXPORTS int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, EyemImage *tpDstImg); EXPORTS int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, EyemImage* tpDstImg);
EXPORTS int eyemSIFTBasedMatch(EyemImage tpImage, EyemImage tpTargetImg, EyemImage tpMask, double dMinScore, EyemImage* tpDstImg);
EXPORTS int eyemAchvMaskImage(EyemImage tpImage, EyemImage *tpDstImg, EyemImage *tpPrevImg);
EXPORTS int eyemSplitMask(EyemImage tpImage, EyemImage tpMask, const char* ccToPath, const char* ccClassName);
#ifdef __cplusplus #ifdef __cplusplus
......
此文件类型无法预览
...@@ -81,6 +81,9 @@ ...@@ -81,6 +81,9 @@
<ClInclude Include="eyemFeatureExtractor.h"> <ClInclude Include="eyemFeatureExtractor.h">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="eyemNCCBasedMatch.h">
<Filter>源文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="eyemLib.cpp"> <ClCompile Include="eyemLib.cpp">
...@@ -158,6 +161,9 @@ ...@@ -158,6 +161,9 @@
<ClCompile Include="eyemFeatureExtractor.cpp"> <ClCompile Include="eyemFeatureExtractor.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="eyemNCCBasedMatch.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="eyemLib.rc"> <ResourceCompile Include="eyemLib.rc">
......
...@@ -625,17 +625,12 @@ int eyemMatAt(EyemImage tpImage, EyemOcsIXY tpPoint) ...@@ -625,17 +625,12 @@ int eyemMatAt(EyemImage tpImage, EyemOcsIXY tpPoint)
int eyemNormalize(EyemImage &tpImage) int eyemNormalize(EyemImage &tpImage)
{ {
CV_Assert(NULL != tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage);
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();
_free(tpImage); _free(tpImage);
if (image.channels() != 3) { if (image.channels() != 3) {
cv::cvtColor(image, image, cv::COLOR_BGRA2BGR); cv::cvtColor(image, image, cv::COLOR_BGRA2BGR);
} }
const int X = image.cols; const int Y = image.rows; const int X = image.cols; const int Y = image.rows;
//归一化 //归一化
cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range range)->void { cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range range)->void {
for (int y = range.start; y < range.end; y++) { for (int y = range.start; y < range.end; y++) {
...@@ -652,16 +647,13 @@ int eyemNormalize(EyemImage &tpImage) ...@@ -652,16 +647,13 @@ int eyemNormalize(EyemImage &tpImage)
}); });
//输出 //输出
tpImage.iWidth = image.cols; tpImage.iHeight = image.rows; tpImage.iDepth = image.depth(); tpImage.iChannels = image.channels(); tpImage.iWidth = image.cols; tpImage.iHeight = image.rows; tpImage.iDepth = image.depth(); tpImage.iChannels = image.channels();
int _Size = image.cols *image.rows *image.channels() * sizeof(uint8_t); int _Size = image.cols *image.rows *image.channels() * sizeof(uint8_t);
tpImage.vpImage = (uint8_t *)malloc(_Size); tpImage.vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpImage.vpImage) if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM; return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size); memset(tpImage.vpImage, 0, _Size);
//拷贝数据 //拷贝数据
memcpy(tpImage.vpImage, image.data, _Size); memcpy(tpImage.vpImage, image.data, _Size);
return FUNC_OK; return FUNC_OK;
} }
...@@ -720,9 +712,9 @@ bool eyemCheckBinary(EyemImage tpImage) ...@@ -720,9 +712,9 @@ bool eyemCheckBinary(EyemImage tpImage)
int bs = 16, b = (X*incn) / bs, stride = (int)image.step; int bs = 16, b = (X*incn) / bs, stride = (int)image.step;
for (int y = 0; y < Y; y++) for (int y = 0; y < Y; y++)
{ {
unsigned char *LinePS = image.data + y * stride; unsigned char *ptr = image.data + y * stride;
for (int x = 0; x < b * bs; x += bs) { for (int x = 0; x < b * bs; x += bs) {
__m128i SrcV = _mm_loadu_si128((__m128i *)(LinePS + x)); __m128i SrcV = _mm_loadu_si128((__m128i *)(ptr + x));
__m128i MaskW = _mm_cmpeq_epi8(SrcV, _mm_set1_epi8(255)); __m128i MaskW = _mm_cmpeq_epi8(SrcV, _mm_set1_epi8(255));
__m128i MaskB = _mm_cmpeq_epi8(SrcV, _mm_setzero_si128()); __m128i MaskB = _mm_cmpeq_epi8(SrcV, _mm_setzero_si128());
__m128i Mask = _mm_or_si128(MaskW, MaskB); __m128i Mask = _mm_or_si128(MaskW, MaskB);
...@@ -731,7 +723,7 @@ bool eyemCheckBinary(EyemImage tpImage) ...@@ -731,7 +723,7 @@ bool eyemCheckBinary(EyemImage tpImage)
} }
} }
for (int x = b * bs; x < X * incn; x++) { for (int x = b * bs; x < X * incn; x++) {
if ((LinePS[x] != 255) && (LinePS[x] != 0)) { if ((ptr[x] != 255) && (ptr[x] != 0)) {
return false; return false;
} }
} }
......
...@@ -74,7 +74,7 @@ double shape_based_matching::find_shape_model(cv::Mat tpImage, double minScore, ...@@ -74,7 +74,7 @@ double shape_based_matching::find_shape_model(cv::Mat tpImage, double minScore,
cv::Mat scoreMap(cv::Size(tpImage.cols, tpImage.rows), CV_64FC1, cv::Scalar(0)); cv::Mat scoreMap(cv::Size(tpImage.cols, tpImage.rows), CV_64FC1, cv::Scalar(0));
//基于ncc匹配 //基于shape匹配
long noOfCordinates = static_cast<int>(results.size()); long noOfCordinates = static_cast<int>(results.size());
double normMinScore = minScore / noOfCordinates; double normMinScore = minScore / noOfCordinates;
double normGreediness = (1 - greediness*minScore) / ((1.0 - greediness) / noOfCordinates); double normGreediness = (1 - greediness*minScore) / ((1.0 - greediness) / noOfCordinates);
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#define __EYEM_MISC_H #define __EYEM_MISC_H
#include <numeric> #include <numeric>
#include <tbb\tbb.h>
#include "eyemLib.h" #include "eyemLib.h"
#include <tbb\tbb.h> #include "azONNXWrapper.h"
constexpr double c = PI / 180.; constexpr double c = PI / 180.;
...@@ -17,4 +18,51 @@ extern double processLevel; ...@@ -17,4 +18,51 @@ extern double processLevel;
extern double fineTuning; extern double fineTuning;
extern std::map<std::string, EyemImage> imageMap; extern std::map<std::string, EyemImage> imageMap;
class PreSegtor {
public:
PreSegtor(const std::string& model_path);
PreSegtor() {};
//设置检测参数
cv::Mat extract(cv::InputArray img);
protected:
class Impl;
cv::Ptr<Impl> p;
};
class PreSegtor::Impl {
public:
Impl() {}
~Impl() {}
//提取
cv::Mat forward(cv::Mat& img);
//特征提取器
std::shared_ptr<AZONNXWrapperEx> extractor_;
};
PreSegtor::PreSegtor(const std::string& model_path)
{
p = cv::makePtr<PreSegtor::Impl>();
if (!model_path.empty()) {
p->extractor_ = std::make_shared<AZONNXWrapperEx>();
p->extractor_->init(model_path);
}
else {
p->extractor_ = NULL;
}
}
cv::Mat PreSegtor::extract(cv::InputArray img)
{
return p->forward(img.getMat());
}
cv::Mat PreSegtor::Impl::forward(cv::Mat& img)
{
return extractor_->forward(img);
}
cv::Ptr<PreSegtor> pSegtor;
#endif/* __EYEM_MISC_H */ #endif/* __EYEM_MISC_H */
#pragma once
//
// eyemNCCBasedMatchͷ
//
#ifndef __EYEM_NCCBASEDMATCH_H
#define __EYEM_NCCBASEDMATCH_H
#include "eyemLib.h"
class ncc_based_matching
{
public:
ncc_based_matching() {};
~ncc_based_matching(void);
int create_ncc_model(cv::Mat&, int iMinReduceArea);
int find_ncc_model(cv::Mat& tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, float* fCenterX, float* fCenterY, float* fMatchScore, float* fMatchAngle);
void draw_match_shapes();
private:
struct s_TemplData
{
std::vector<cv::Mat> vecPyramid;
std::vector<cv::Scalar> vecTemplMean;
std::vector<double> vecTemplNorm;
std::vector<double> vecInvArea;
std::vector<BOOL> vecResultEqual1;
BOOL bIsPatternLearned;
int iTopLayer;
void clear()
{
std::vector<cv::Mat>().swap(vecPyramid);
std::vector<double>().swap(vecTemplNorm);
std::vector<double>().swap(vecInvArea);
std::vector<cv::Scalar>().swap(vecTemplMean);
std::vector<BOOL>().swap(vecResultEqual1);
}
void resize(int iSize)
{
vecTemplMean.resize(iSize);
vecTemplNorm.resize(iSize, 0);
vecInvArea.resize(iSize, 1);
vecResultEqual1.resize(iSize, FALSE);
}
s_TemplData()
{
bIsPatternLearned = FALSE;
iTopLayer = 0;
}
};
struct s_MatchParameter
{
cv::Point2d pt;
double dMatchScore;
double dMatchAngle;
//Mat matRotatedSrc;
cv::Rect rectRoi;
double dAngleStart;
double dAngleEnd;
cv::RotatedRect rectR;
cv::Rect rectBounding;
BOOL bDelete;
double vecResult[3][3];//for subpixel
int iMaxScoreIndex;//for subpixel
BOOL bPosOnBorder;
cv::Point2d ptSubPixel;
double dNewAngle;
s_MatchParameter(cv::Point2f ptMinMax, double dScore, double dAngle)//, Mat matRotatedSrc = Mat ())
{
pt = ptMinMax;
dMatchScore = dScore;
dMatchAngle = dAngle;
bDelete = FALSE;
dNewAngle = 0.0;
bPosOnBorder = FALSE;
}
s_MatchParameter()
{
double dMatchScore = 0;
double dMatchAngle = 0;
}
~s_MatchParameter()
{
}
};
struct s_SingleTargetMatch
{
cv::Point2d ptLT, ptRT, ptRB, ptLB, ptCenter;
double dMatchedAngle;
double dMatchScore;
};
cv::Mat m_matSrc;
cv::Mat m_matDst;
cv::Mat showResult;
s_TemplData m_TemplData;
std::vector<s_SingleTargetMatch> m_vecSingleTargetData;
int getTopLayer(cv::Mat&, int);
void drawDashLine(cv::Mat& matDraw, cv::Point ptStart, cv::Point ptEnd, cv::Scalar color1 = cv::Scalar(0, 0, 255), cv::Scalar color2 = cv::Scalar::all(255));
void drawMarkCross(cv::Mat& matDraw, int iX, int iY, int iLength, cv::Scalar color, int iThickness);
static bool compareScoreBig2Small(const s_MatchParameter& lhs, const s_MatchParameter& rhs) { return lhs.dMatchScore > rhs.dMatchScore; }
static bool comparePtWithAngle(const std::pair<cv::Point2f, double>& lhs, const std::pair<cv::Point2f, double>& rhs) { return lhs.second < rhs.second; }
static bool compareMatchResultByScore(const s_SingleTargetMatch& lhs, const s_SingleTargetMatch& rhs) { return lhs.dMatchScore > rhs.dMatchScore; }
static bool compareMatchResultByPosX(const s_SingleTargetMatch& lhs, const s_SingleTargetMatch& rhs) { return lhs.ptCenter.x < rhs.ptCenter.x; }
void filterWithScore(std::vector<s_MatchParameter>* vec, double dScore);
void filterWithRotatedRect(std::vector<s_MatchParameter>* vec, int iMethod, double dMaxOverLap);
void sortPtWithCenter(std::vector<cv::Point2f>& vecSort);
cv::Point2f ptRotatePt2f(cv::Point2f ptInput, cv::Point2f ptOrg, double dAngle);
cv::Size bestRotationSize(cv::Size sizeSrc, cv::Size sizeDst, double dRAngle);
BOOL subPixEsimation(std::vector<s_MatchParameter>* vec, double* dNewX, double* dNewY, double* dNewAngle, double dAngleStep, int iMaxScoreIndex);
void getRotatedROI(cv::Mat& matSrc, cv::Size size, cv::Point2f ptLT, double dAngle, cv::Mat& matROI);
cv::Point nextMaxLoc(cv::Mat& matResult, cv::Point ptMaxLoc, double dMinValue, int iTemplateW, int iTemplateH, double& dMaxValue, double dMaxOverlap);
void m_matchTemplate(cv::Mat& matSrc, s_TemplData* pTemplData, cv::Mat& matResult, int iLayer);
void TM_CCOEFF_Denominator(cv::Mat& matSrc, s_TemplData* pTemplData, cv::Mat& matResult, int iLayer);
};
ncc_based_matching nbm;
#endif/* __EYEM_NCCBASEDMATCH_H */
\ No newline at end of file \ No newline at end of file
此文件太大,无法显示。
此文件太大,无法显示。
此文件类型无法预览
#ifdef _DEBUG #ifdef _DEBUG
//#pragma comment( lib, "IlmImfd.lib" ) #ifdef _V455
//#pragma comment( lib, "ippicvmt.lib" ) #pragma comment( lib, "opencv_world455d.lib" )
//#pragma comment( lib, "ippiwd.lib" ) #else
//#pragma comment( lib, "ittnotifyd.lib" )
//#pragma comment( lib, "libjasperd.lib" )
//#pragma comment( lib, "libjpeg-turbod.lib" )
//#pragma comment( lib, "libpngd.lib" )
//#pragma comment( lib, "libprotobufd.lib" )
//#pragma comment( lib, "libtiffd.lib" )
//#pragma comment( lib, "libwebpd.lib" )
//#pragma comment( lib, "quircd.lib" )
//#pragma comment( lib, "zlibd.lib" )
#pragma comment( lib, "opencv_world420d.lib" ) #pragma comment( lib, "opencv_world420d.lib" )
#endif
#else #else
//#pragma comment( lib, "IlmImf.lib" ) #ifdef _V455
//#pragma comment( lib, "ippicvmt.lib" ) #pragma comment( lib, "opencv_world455.lib" )
//#pragma comment( lib, "ippiw.lib" ) #else
//#pragma comment( lib, "ittnotify.lib" )
//#pragma comment( lib, "libjasper.lib" )
//#pragma comment( lib, "libjpeg-turbo.lib" )
//#pragma comment( lib, "libpng.lib" )
//#pragma comment( lib, "libprotobuf.lib" )
//#pragma comment( lib, "libtiff.lib" )
//#pragma comment( lib, "libwebp.lib" )
//#pragma comment( lib, "quirc.lib" )
//#pragma comment( lib, "zlib.lib" )
#pragma comment( lib, "opencv_world420.lib" ) #pragma comment( lib, "opencv_world420.lib" )
#endif #endif
#endif
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!