Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit c28b0fea
由
张士柳
编写于
2021-07-12 16:11:41 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
87a1305d
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
97 行增加
和
44 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/EyemLibDemo.cs
eyemLib/eyemDataCode.cpp
eyemLib/eyemDataCode.h
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemMisc.cpp
eyemLib/eyemMisc.h
eyemLib/nnDetector.cpp
eyemLib/nnDetector.h
eyemLib-Sharp/EyemLib.cs
查看文件 @
c28b0fe
...
@@ -1021,18 +1021,18 @@ namespace eyemLib_Sharp
...
@@ -1021,18 +1021,18 @@ namespace eyemLib_Sharp
#
endregion
#
endregion
#
region
项目
#
region
项目
//普通器件
//普通器件
(仍采用旧的算法)
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemCountObject
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
double
dOffset
,
int
iMinArea
,
int
iMaxArea
,
int
iWinSize
,
ref
string
pNumObj
,
out
EyemImage
tpDstImg
);
private
static
extern
int
eyemCountObject
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
[
MarshalAs
(
UnmanagedType
.
LPArray
)]
int
[]
ipReelNum
,
out
EyemImage
tpDstImg
);
//异型器件
//异型器件
(新版本新算法)
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemCountObjectIrregularParts
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
string
strType
,
ref
string
pNumObj
,
out
EyemImage
tpDstImg
);
private
static
extern
int
eyemCountObjectIrregularParts
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
string
strType
,
[
MarshalAs
(
UnmanagedType
.
LPArray
)]
int
[]
ipReelNum
,
out
EyemImage
tpDstImg
);
//普通器件(新版本)
//普通器件(新版本
新算法
)
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemCountObjectE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
ref
string
pNumObj
,
out
EyemImage
tpDstImg
);
private
static
extern
int
eyemCountObjectE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
[
MarshalAs
(
UnmanagedType
.
LPArray
)]
int
[]
ipReelNum
,
out
EyemImage
tpDstImg
);
//异型器件(新版本)
//异型器件(新版本
模板匹配
)
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemCountObjectIrregularPartsE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
string
ccTplName
,
IntPtr
hModelID
,
ref
string
pNumObj
,
out
EyemImage
tpDstImg
);
private
static
extern
int
eyemCountObjectIrregularPartsE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
fileName
,
string
ccTplName
,
IntPtr
hModelID
,
[
MarshalAs
(
UnmanagedType
.
LPArray
)]
int
[]
ipReelNum
,
out
EyemImage
tpDstImg
);
//创建模板匹配模型
//创建模板匹配模型
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemCreateTemplateModel
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
double
dMinScore
,
string
ccTplName
);
private
static
extern
int
eyemCreateTemplateModel
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
double
dMinScore
,
string
ccTplName
);
...
@@ -1129,6 +1129,7 @@ namespace eyemLib_Sharp
...
@@ -1129,6 +1129,7 @@ namespace eyemLib_Sharp
//记录日志
//记录日志
private
static
void
EyemLib_OnNewLogCallback
(
string
msg
)
private
static
void
EyemLib_OnNewLogCallback
(
string
msg
)
{
{
//算法里输出的一切日志都会在这里
logcpp
.
WriteLog
(
"["
+
Thread
.
CurrentThread
.
ManagedThreadId
.
ToString
(
"X16"
)
+
"]"
+
msg
);
logcpp
.
WriteLog
(
"["
+
Thread
.
CurrentThread
.
ManagedThreadId
.
ToString
(
"X16"
)
+
"]"
+
msg
);
}
}
...
@@ -1363,14 +1364,13 @@ namespace eyemLib_Sharp
...
@@ -1363,14 +1364,13 @@ namespace eyemLib_Sharp
//flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg);
//flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg);
string
pNumObj
=
""
;
int
[]
ipReelNum
=
new
int
[
4
]
;
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
//获取用于制作模板的图像
//获取用于制作模板的图像
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//if (bitmap != null)
//{
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
...
@@ -1423,10 +1423,10 @@ namespace eyemLib_Sharp
...
@@ -1423,10 +1423,10 @@ namespace eyemLib_Sharp
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref tpDstImg);
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_LOWCONTRAST_PARTS"
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_LOWCONTRAST_PARTS"
//eyemCountObject(image, tpRoi, file.Replace(".png", ""),
35, 0, 100, 5, ref pNumObj
, out tpDstImg);
//eyemCountObject(image, tpRoi, file.Replace(".png", ""),
ipReelNum
, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LONG_PARTS", ref pNumObj
, out tpDstImg);
eyemCountObjectIrregularParts
(
image
,
tpRoi
,
file
.
Replace
(
".png"
,
""
),
"IP_LARGE_PARTS"
,
ipReelNum
,
out
tpDstImg
);
eyemCountObjectE
(
image
,
tpRoi
,
fileName
,
ref
pNumObj
,
out
tpDstImg
);
//eyemCountObjectE(image, tpRoi, fileName, ipReelNum
, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID,
ref pNumObj
, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID,
ipReelNum
, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//移除模板
//移除模板
...
@@ -1435,8 +1435,8 @@ namespace eyemLib_Sharp
...
@@ -1435,8 +1435,8 @@ namespace eyemLib_Sharp
Bitmap
bitmap
=
eyemCvtToBitmap
(
tpDstImg
);
Bitmap
bitmap
=
eyemCvtToBitmap
(
tpDstImg
);
if
(
bitmap
!=
null
)
if
(
bitmap
!=
null
)
{
{
bitmap
.
Save
(
"D:\\ResOut\\"
+
file
);
//
bitmap.Save("D:\\ResOut\\" + file);
//
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
bitmap
.
Save
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
+
"\\ResOut\\"
+
file
);
}
}
//< 解码测试
//< 解码测试
...
@@ -1449,16 +1449,19 @@ namespace eyemLib_Sharp
...
@@ -1449,16 +1449,19 @@ namespace eyemLib_Sharp
// Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
// Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
//}
//}
//hObject.Dispose();
//hObject.Dispose();
//flag = eyemDetectAndDecodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
//flag = eyemDetectAndDecodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
//flag = eyemDetectAndDecodeBarcodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
//flag = eyemDetectAndDecodeBarcodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
string
strReelNum
=
""
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
strReelNum
+=
ipReelNum
[
i
].
ToString
()
+
","
;
}
sw
.
Stop
();
sw
.
Stop
();
Console
.
WriteLine
(
file
+
"--->"
+
"耗时:"
+
sw
.
ElapsedMilliseconds
.
ToString
()
+
"
毫秒"
+
",结果:"
+
pNumObj
);
Console
.
WriteLine
(
file
+
"--->"
+
"耗时:"
+
sw
.
ElapsedMilliseconds
.
ToString
()
+
"
ms"
+
",结果:"
+
strReelNum
);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//if (bitmap != null)
//{
//{
// bitmap.Save("D:\\ResOut\\" + file);
// bitmap.Save("D:\\ResOut\\" + file);
...
@@ -1498,7 +1501,7 @@ namespace eyemLib_Sharp
...
@@ -1498,7 +1501,7 @@ namespace eyemLib_Sharp
tpRoi
.
iHeight
=
image
.
iHeight
-
100
;
tpRoi
.
iHeight
=
image
.
iHeight
-
100
;
//
//
string
pNumObj
=
""
;
int
[]
pNumObj
=
new
int
[
4
]
;
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
//获取用于制作模板的图像
//获取用于制作模板的图像
...
@@ -1537,7 +1540,7 @@ namespace eyemLib_Sharp
...
@@ -1537,7 +1540,7 @@ namespace eyemLib_Sharp
eyemImageFree
(
ref
tpDstImg
);
eyemImageFree
(
ref
tpDstImg
);
//点料
//点料
eyemCountObjectIrregularPartsE
(
image
,
tpRoi
,
file
.
Replace
(
".png"
,
""
),
selectModel
.
Split
(
new
char
[]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
)[
0
],
hModelID
,
ref
pNumObj
,
out
tpDstImg
);
eyemCountObjectIrregularPartsE
(
image
,
tpRoi
,
file
.
Replace
(
".png"
,
""
),
selectModel
.
Split
(
new
char
[]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
)[
0
],
hModelID
,
pNumObj
,
out
tpDstImg
);
//测试移除模板
//测试移除模板
//eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
...
...
eyemLib-Sharp/EyemLibDemo.cs
查看文件 @
c28b0fe
using
Microsoft.Win32.SafeHandles
;
using
System
;
using
System
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Drawing.Imaging
;
...
@@ -323,8 +319,41 @@ namespace eyemLib_Sharp
...
@@ -323,8 +319,41 @@ namespace eyemLib_Sharp
//释放图像资源
//释放图像资源
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
void
eyemImageFree
(
ref
EyemImage
tpImage
);
private
static
extern
void
eyemImageFree
(
ref
EyemImage
tpImage
);
// 设定日志回调
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
void
setLogCallback
(
TCallBack
cb
);
#
endregion
#
endregion
// 日志
public
delegate
void
TCallBack
(
string
msg
);
public
static
TCallBack
sld
=
new
TCallBack
(
TLogCallback
);
public
static
event
TCallBack
OnNewLogCallback
;
public
static
void
TLogCallback
(
string
msg
)
{
OnNewLogCallback
?.
Invoke
(
msg
);
}
//程序启动时初始化一次
public
static
void
Init
()
{
setLogCallback
(
sld
);
OnNewLogCallback
+=
new
TCallBack
(
EyemLib_OnNewLogCallback
);
}
//程序结束时释放
public
static
void
Free
()
{
setLogCallback
(
null
);
sld
=
null
;
}
//记录算法日志
private
static
void
EyemLib_OnNewLogCallback
(
string
msg
)
{
//算法里输出的一切日志都会在这里
}
//例程
//例程
public
static
void
eyeyTestTemplateModelMethod
(
string
fileName
)
public
static
void
eyeyTestTemplateModelMethod
(
string
fileName
)
{
{
...
@@ -355,7 +384,6 @@ namespace eyemLib_Sharp
...
@@ -355,7 +384,6 @@ namespace eyemLib_Sharp
#
endregion
#
endregion
}
}
#
region
EyemImage
与
Bitmap
相互转换
#
region
EyemImage
与
Bitmap
相互转换
public
static
Bitmap
eyemCvtToBitmap
(
EyemImage
tpImage
)
public
static
Bitmap
eyemCvtToBitmap
(
EyemImage
tpImage
)
{
{
...
...
eyemLib/eyemDataCode.cpp
查看文件 @
c28b0fe
...
@@ -516,8 +516,10 @@ int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject,
...
@@ -516,8 +516,10 @@ int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject,
{
{
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
())
{
logger
.
t
(
"__eyemDetectAndDecodeUseNN__:图像文件不存在"
);
return
FUNC_IMAGE_NOT_EXIST
;
return
FUNC_IMAGE_NOT_EXIST
;
}
}
logger
.
t
(
"__eyemDetectAndDecodeUseNN__:开始识别并解码二维码"
);
//识别并解码
//识别并解码
std
::
vector
<
cv
::
Rect
>
points
;
std
::
vector
<
cv
::
Rect
>
__points
;
std
::
vector
<
cv
::
Rect
>
points
;
std
::
vector
<
cv
::
Rect
>
__points
;
auto
results
=
detector
->
detectAndDecode
(
image
,
points
,
__points
);
auto
results
=
detector
->
detectAndDecode
(
image
,
points
,
__points
);
...
@@ -569,6 +571,7 @@ int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject,
...
@@ -569,6 +571,7 @@ int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject,
//}
//}
#pragma endregion
#pragma endregion
logger
.
t
(
"__eyemDetectAndDecodeUseNN__:输出结果"
);
//解码结果
//解码结果
std
::
vector
<
EyemBarCode
>
*
tpResults
=
new
std
::
vector
<
EyemBarCode
>
();
std
::
vector
<
EyemBarCode
>
*
tpResults
=
new
std
::
vector
<
EyemBarCode
>
();
for
(
int
n
=
0
;
n
<
results
.
size
();
n
++
)
{
for
(
int
n
=
0
;
n
<
results
.
size
();
n
++
)
{
...
...
eyemLib/eyemDataCode.h
查看文件 @
c28b0fe
...
@@ -5,6 +5,13 @@
...
@@ -5,6 +5,13 @@
#ifndef __EYEM_DATACODE_H
#ifndef __EYEM_DATACODE_H
#define __EYEM_DATACODE_H
#define __EYEM_DATACODE_H
#ifdef _WIN32
#include <io.h>
#include <Windows.h>
#elif __linux__
#include <sys/stat.h>
#endif
#include "eyemLib.h"
#include "eyemLib.h"
#include "nnDetector.h"
#include "nnDetector.h"
...
@@ -12,6 +19,8 @@ std::mutex mtx;
...
@@ -12,6 +19,8 @@ std::mutex mtx;
cv
::
Ptr
<
NNDetector
>
detector
;
cv
::
Ptr
<
NNDetector
>
detector
;
extern
Logger
logger
;
//预处理区域
//预处理区域
struct
WaitArea
struct
WaitArea
{
{
...
...
eyemLib/eyemLib.h
查看文件 @
c28b0fe
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
#ifndef __EYEM_LIB_H
#ifndef __EYEM_LIB_H
#define __EYEM_LIB_H
#define __EYEM_LIB_H
#include <Windows.h>
#include <opencv.hpp>
#include <opencv.hpp>
...
@@ -662,7 +661,7 @@ extern "C" {
...
@@ -662,7 +661,7 @@ extern "C" {
// 函数接口
// 函数接口
EXPORTS
int
eyemEdgesPixel
(
EyemImage
tpImage
,
double
dThresh
);
EXPORTS
int
eyemEdgesPixel
(
EyemImage
tpImage
,
double
dThresh
);
EXPORTS
int
eyemEdgesSubpixel
(
EyemImage
tpImage
,
IntPtr
*
hObject
,
EyemOcsDXY
**
tpEdges
,
int
iFilter
,
int
iLow
,
int
iHigh
);
EXPORTS
int
eyemEdgesSubpixel
(
EyemImage
tpImage
,
IntPtr
*
hObject
,
EyemOcsDXY
**
tpEdges
,
int
iFilter
,
int
iLow
,
int
iHigh
);
EXPORTS
int
eyemSkeleton
(
EyemImage
tpImage
,
cv
::
Mat
&
skeleton
);
EXPORTS
int
eyemSkeleton
(
EyemImage
tpImage
,
EyemImage
&
skeleton
);
EXPORTS
int
eyemSobelAmp
(
EyemImage
tpImage
,
EyemImage
&
ImaAmp
);
EXPORTS
int
eyemSobelAmp
(
EyemImage
tpImage
,
EyemImage
&
ImaAmp
);
EXPORTS
int
eyemAutoCanny
(
EyemImage
tpImage
,
float
dSigma
=
0
.
33
);
EXPORTS
int
eyemAutoCanny
(
EyemImage
tpImage
,
float
dSigma
=
0
.
33
);
...
@@ -799,8 +798,8 @@ typedef struct {
...
@@ -799,8 +798,8 @@ typedef struct {
double
dAngle
;
// 角度
double
dAngle
;
// 角度
int
iCenterX
;
// y坐标
int
iCenterX
;
// y坐标
int
iCenterY
;
// y坐标
int
iCenterY
;
// y坐标
LPSTR
lpszType
;
// 码类型
char
*
lpszType
;
// 码类型
LPSTR
lpszText
;
// 码内容
char
*
lpszText
;
// 码内容
}
EyemBarCode
;
}
EyemBarCode
;
typedef
struct
{
typedef
struct
{
...
@@ -810,7 +809,7 @@ typedef struct {
...
@@ -810,7 +809,7 @@ typedef struct {
int
iWidth
;
// 图像内存X方向大小
int
iWidth
;
// 图像内存X方向大小
int
iHeight
;
// 图像内存Y方向大小
int
iHeight
;
// 图像内存Y方向大小
double
dMatchDeg
;
// 匹配度
double
dMatchDeg
;
// 匹配度
LPSTR
lpszName
;
// 名称
char
*
lpszName
;
// 名称
}
EyemModelID
;
}
EyemModelID
;
...
@@ -822,13 +821,13 @@ extern "C" {
...
@@ -822,13 +821,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
eyemCountObject
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
fileName
,
LPSTR
*
lpszNumObj
,
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
,
LPSTR
*
lpsz
ReelNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemCountObjectE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
fileName
,
int
*
ip
ReelNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemCountObjectIrregularParts
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
fileName
,
const
char
*
ccSubType
,
LPSTR
*
lpszNumObj
,
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
,
LPSTR
*
lpsz
ReelNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemCountObjectIrregularPartsE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
fileName
,
const
char
*
ccTplName
,
IntPtr
hModelID
,
int
*
ip
ReelNum
,
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
);
EXPORTS
int
eyemMatchTemplateModel
(
EyemImage
tpImage
,
IntPtr
hModelID
,
LPSTR
*
lpszTplName
);
EXPORTS
int
eyemMatchTemplateModel
(
EyemImage
tpImage
,
IntPtr
hModelID
,
char
*
*
lpszTplName
);
EXPORTS
int
eyemInitModel
(
const
char
*
ccTplName
,
IntPtr
*
hModelID
);
EXPORTS
int
eyemInitModel
(
const
char
*
ccTplName
,
IntPtr
*
hModelID
);
EXPORTS
int
eyemAchvModelByName
(
const
char
*
ccTplName
,
IntPtr
hModelID
,
EyemModelID
&
tpModelID
);
EXPORTS
int
eyemAchvModelByName
(
const
char
*
ccTplName
,
IntPtr
hModelID
,
EyemModelID
&
tpModelID
);
EXPORTS
int
eyemInsertModel
(
IntPtr
hModelID
,
const
char
*
ccTplName
);
EXPORTS
int
eyemInsertModel
(
IntPtr
hModelID
,
const
char
*
ccTplName
);
...
...
eyemLib/eyemLib.rc
查看文件 @
c28b0fe
此文件类型无法预览
eyemLib/eyemMisc.cpp
查看文件 @
c28b0fe
此文件的差异被折叠,
点击展开。
eyemLib/eyemMisc.h
查看文件 @
c28b0fe
...
@@ -5,17 +5,12 @@
...
@@ -5,17 +5,12 @@
#ifndef __EYEM_MISC_H
#ifndef __EYEM_MISC_H
#define __EYEM_MISC_H
#define __EYEM_MISC_H
#include <io.h>
#include <fstream>
#include <direct.h>
#include "eyemLib.h"
#include "eyemLib.h"
#include <tbb\tbb.h>
#include <tbb\tbb.h>
extern
Logger
logger
;
constexpr
double
c
=
PI
/
180
.;
constexpr
double
c
=
PI
/
180
.;
extern
Logger
logger
;
extern
int
killProcessID
;
extern
int
killProcessID
;
#endif
/* __EYEM_MISC_H */
#endif
/* __EYEM_MISC_H */
eyemLib/nnDetector.cpp
查看文件 @
c28b0fe
...
@@ -48,6 +48,7 @@ std::vector<std::string> NNDetector::detectAndDecode(cv::InputArray img, std::ve
...
@@ -48,6 +48,7 @@ std::vector<std::string> NNDetector::detectAndDecode(cv::InputArray img, std::ve
if
(
img
.
cols
()
<=
20
||
img
.
rows
()
<=
20
)
{
if
(
img
.
cols
()
<=
20
||
img
.
rows
()
<=
20
)
{
return
std
::
vector
<
std
::
string
>
();
return
std
::
vector
<
std
::
string
>
();
}
}
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__:开始图像格式转换"
);
cv
::
Mat
input
;
cv
::
Mat
input
;
int
incn
=
img
.
channels
();
int
incn
=
img
.
channels
();
if
(
incn
==
4
)
{
if
(
incn
==
4
)
{
...
@@ -59,14 +60,20 @@ std::vector<std::string> NNDetector::detectAndDecode(cv::InputArray img, std::ve
...
@@ -59,14 +60,20 @@ std::vector<std::string> NNDetector::detectAndDecode(cv::InputArray img, std::ve
else
{
else
{
input
=
img
.
getMat
();
input
=
img
.
getMat
();
}
}
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__:图像格式转换完成"
);
_mtx
.
lock
();
_mtx
.
lock
();
//识别
//识别
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__:开始识别二维码"
);
std
::
vector
<
cv
::
Rect
>
bboxes
=
p
->
detect
(
input
);
std
::
vector
<
cv
::
Rect
>
bboxes
=
p
->
detect
(
input
);
for
(
auto
&
bbox
:
bboxes
)
{
for
(
auto
&
bbox
:
bboxes
)
{
__points
.
push_back
(
bbox
);
__points
.
push_back
(
bbox
);
}
}
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__:识别二维码结束"
);
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__:开始解码"
);
//解码
//解码
std
::
vector
<
std
::
string
>
results
=
p
->
decode
(
input
,
bboxes
,
points
);
std
::
vector
<
std
::
string
>
results
=
p
->
decode
(
input
,
bboxes
,
points
);
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__:解码完成"
);
_mtx
.
unlock
();
_mtx
.
unlock
();
return
results
;
return
results
;
}
}
...
@@ -77,12 +84,14 @@ std::vector<cv::Rect> NNDetector::Impl::detect(const cv::Mat& img) {
...
@@ -77,12 +84,14 @@ std::vector<cv::Rect> NNDetector::Impl::detect(const cv::Mat& img) {
std
::
vector
<
std
::
string
>
NNDetector
::
Impl
::
decode
(
const
cv
::
Mat
&
img
,
std
::
vector
<
cv
::
Rect
>&
bboxes
,
std
::
vector
<
cv
::
Rect
>&
points
)
{
std
::
vector
<
std
::
string
>
NNDetector
::
Impl
::
decode
(
const
cv
::
Mat
&
img
,
std
::
vector
<
cv
::
Rect
>&
bboxes
,
std
::
vector
<
cv
::
Rect
>&
points
)
{
if
(
bboxes
.
size
()
==
0
)
{
if
(
bboxes
.
size
()
==
0
)
{
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:未识别到二维码"
);
return
std
::
vector
<
std
::
string
>
();
return
std
::
vector
<
std
::
string
>
();
}
}
std
::
vector
<
std
::
string
>
decode_results
;
std
::
vector
<
std
::
string
>
decode_results
;
//限定框,防止越界
//限定框,防止越界
for
(
auto
&
bbox
:
bboxes
)
{
for
(
auto
&
bbox
:
bboxes
)
{
if
(
bbox
.
height
>
1000
||
bbox
.
width
>
1000
)
{
if
(
bbox
.
height
>
1000
||
bbox
.
width
>
1000
)
{
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:识别尺寸太大,判断不是二维码"
);
continue
;
continue
;
}
}
float
padding_w
=
0.1
f
,
padding_h
=
0.1
f
;
float
padding_w
=
0.1
f
,
padding_h
=
0.1
f
;
...
@@ -95,10 +104,12 @@ std::vector<std::string> NNDetector::Impl::decode(const cv::Mat& img, std::vecto
...
@@ -95,10 +104,12 @@ std::vector<std::string> NNDetector::Impl::decode(const cv::Mat& img, std::vecto
int
end_x
=
cv
::
min
(
bbox
.
br
().
x
+
padx
,
img
.
cols
-
1
);
int
end_x
=
cv
::
min
(
bbox
.
br
().
x
+
padx
,
img
.
cols
-
1
);
int
end_y
=
cv
::
min
(
bbox
.
br
().
y
+
pady
,
img
.
rows
-
1
);
int
end_y
=
cv
::
min
(
bbox
.
br
().
y
+
pady
,
img
.
rows
-
1
);
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
::
cvtColor
(
cropped_img
,
cropped_img
,
cv
::
COLOR_BGR2GRAY
);
cv
::
cvtColor
(
cropped_img
,
cropped_img
,
cv
::
COLOR_BGR2GRAY
);
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
::
Mat
scaled_img
=
cv
::
Mat
scaled_img
=
...
@@ -109,12 +120,14 @@ std::vector<std::string> NNDetector::Impl::decode(const cv::Mat& img, std::vecto
...
@@ -109,12 +120,14 @@ std::vector<std::string> NNDetector::Impl::decode(const cv::Mat& img, std::vecto
auto
ret
=
decodeImage
(
scaled_img
,
result
,
false
,
0
,
_points
);
auto
ret
=
decodeImage
(
scaled_img
,
result
,
false
,
0
,
_points
);
if
(
ret
!=
-
1
)
{
if
(
ret
!=
-
1
)
{
//恢复真实尺度
//恢复真实尺度
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:恢复真实尺度"
);
for
(
auto
&
_point
:
_points
)
{
for
(
auto
&
_point
:
_points
)
{
_point
.
x
=
cvRound
((
float
)
_point
.
x
/
cur_scale
);
_point
.
x
=
cvRound
((
float
)
_point
.
x
/
cur_scale
);
_point
.
x
+=
crop_roi
.
tl
().
x
;
_point
.
x
+=
crop_roi
.
tl
().
x
;
_point
.
y
=
cvRound
((
float
)
_point
.
y
/
cur_scale
);
_point
.
y
=
cvRound
((
float
)
_point
.
y
/
cur_scale
);
_point
.
y
+=
crop_roi
.
tl
().
y
;
_point
.
y
+=
crop_roi
.
tl
().
y
;
}
}
logger
.
t
(
"__eyemDetectAndDecodeUseNN__detectAndDecode__decode__:解码成功"
);
cv
::
Rect
br
=
cv
::
boundingRect
(
_points
);
cv
::
Rect
br
=
cv
::
boundingRect
(
_points
);
points
.
push_back
(
br
);
points
.
push_back
(
br
);
decode_results
.
push_back
(
result
);
decode_results
.
push_back
(
result
);
...
...
eyemLib/nnDetector.h
查看文件 @
c28b0fe
...
@@ -7,6 +7,9 @@
...
@@ -7,6 +7,9 @@
#include "opencv2/core.hpp"
#include "opencv2/core.hpp"
#include "libdecode.h"
#include "libdecode.h"
#include "eyemLib.h"
extern
Logger
logger
;
class
NNDetector
{
class
NNDetector
{
public
:
public
:
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论