Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
CarerayImage
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 11b2d5ab
由
刘韬
编写于
2022-01-07 15:14:23 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
cbdaf239
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
145 行增加
和
5 行删除
CarerayImage/CarerayImage.csproj
CarerayImage/ONNXAlgoMatch.cs
CarerayImage/XrayImage.cs
CarerayImage/eyemLib.cs
CarerayImage/CarerayImage.csproj
查看文件 @
11b2d5a
...
...
@@ -21,8 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<DocumentationFile>bin\Debug\Asa.CarerayImage.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
...
@@ -51,6 +50,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ONNXAlgoMatch.cs" />
<Compile Include="eyemLib.cs" />
<Compile Include="haobo.cs" />
<Compile Include="HaoboSDK\HBI_FPD_DLL.cs" />
...
...
CarerayImage/ONNXAlgoMatch.cs
0 → 100644
查看文件 @
11b2d5a
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
System.Text
;
using
System.Threading.Tasks
;
using
static
Asa
.
eyemLib
;
namespace
Asa
{
/// <summary>
/// ONNX算法匹配
/// </summary>
public
class
ONNXAlgoMatch
{
static
Dictionary
<
Bitmap
,
float
[
]>
dictFeatures
=
new
Dictionary
<
Bitmap
,
float
[
]>
();
static
ONNXAlgoMatch
()
{
string
onnxfile
=
"./darknet/ec_model.onnx"
;
int
flag
=
eyemInitONNXModel
(
onnxfile
);
if
(
flag
!=
0
)
{
throw
new
Exception
(
$
"加载ONNX算法模型文件失败!-{onnxfile}"
);
}
string
featurePath
=
"./darknet/feature.te"
;
if
(!
File
.
Exists
(
featurePath
))
throw
new
Exception
(
$
"加载ONNX算法匹配文件失败!-{featurePath}"
);
BinaryFormatter
bf
=
new
BinaryFormatter
();
using
(
Stream
stream
=
new
FileStream
(
featurePath
,
FileMode
.
Open
,
FileAccess
.
Read
))
{
dictFeatures
=
(
Dictionary
<
Bitmap
,
float
[
]>
)
bf
.
Deserialize
(
stream
);
}
}
/// <summary>
/// 匹配算法PID
/// </summary>
/// <param name="fileName"></param>
/// <param name="ShrinkOffset"></param>
/// <param name="matchDeg">匹配百分比</param>
/// <returns></returns>
public
static
string
MatchPID
(
string
fileName
,
int
ShrinkOffset
,
out
float
matchDeg
)
{
int
flag
=
eyemImageRead
(
fileName
,
-
1
,
out
EyemImage
image
);
if
(
flag
!=
0
||
image
.
iDepth
!=
2
||
image
.
iChannels
!=
3
)
{
throw
new
Exception
(
"文件类型错误!"
);
}
var
tpRoi
=
new
EyemRect
();
tpRoi
.
iXs
=
0
+
ShrinkOffset
;
tpRoi
.
iYs
=
0
+
ShrinkOffset
;
tpRoi
.
iWidth
=
image
.
iWidth
-
ShrinkOffset
*
2
;
tpRoi
.
iHeight
=
image
.
iHeight
-
ShrinkOffset
*
2
;
matchDeg
=
0
;
flag
=
eyemAchvMatchMat
(
image
,
tpRoi
,
out
EyemImage
extractMat
);
if
(
extractMat
.
ucpImage
==
IntPtr
.
Zero
)
{
throw
new
Exception
(
"获取源图特征部分失败!"
);
}
//提取特征
float
[]
fFeature
=
new
float
[
512
];
eyemExtractWithONNX
(
extractMat
,
fFeature
);
eyemImageFree
(
ref
extractMat
);
eyemImageFree
(
ref
image
);
//匹配最大值
Dictionary
<
int
,
float
>
dictMatchDeg
=
new
Dictionary
<
int
,
float
>();
foreach
(
var
item
in
dictFeatures
)
{
float
simDeg
=
calcSimilarity
(
item
.
Value
.
Take
(
512
).
ToArray
(),
fFeature
);
var
k
=
(
int
)
item
.
Value
[
512
];
if
(!
dictMatchDeg
.
ContainsKey
(
k
))
dictMatchDeg
.
Add
(
k
,
simDeg
);
}
var
predict
=
dictMatchDeg
.
OrderBy
(
p
=>
p
.
Value
);
var
last
=
predict
.
Last
();
string
label
=
"PID"
+
last
.
Key
.
ToString
().
PadLeft
(
3
,
'0'
);
matchDeg
=
last
.
Value
;
return
label
;
}
}
}
CarerayImage/XrayImage.cs
查看文件 @
11b2d5a
...
...
@@ -407,6 +407,16 @@ namespace Asa
device
.
SaveRAW
(
filePath
);
}
/// <summary>
/// 设置处理级别
/// </summary>
/// <param name="pl">
/// pl>2.0就用你设置的值,pl<=2.0就等于默认值2.0,,一般来说离线点料机pl=2.0,在线点料机pl=4.0
/// </param>
/// <returns></returns>
public
static
int
setProcessLevel
(
double
pl
)
{
return
eyemLib
.
setProcessLevel
(
pl
);
}
/// <summary>
/// 校准平板
/// </summary>
/// <param name="mode">1:暗场校准,2亮场校准</param>
...
...
CarerayImage/eyemLib.cs
查看文件 @
11b2d5a
...
...
@@ -48,14 +48,15 @@ namespace Asa
//[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
//internal static extern int eyemCountObjectIrregularParts(EyemImage tpSrcImg, EyemRect tpRoi, string fileName, double dOffset, string strType, int iMaxArea, int iWinSize, ref string pNumObj, out EyemImage tpDstImg);
//[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
//internal static extern int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, string fileName, ref string pNumObj, out EyemImage tpDstImg);
//[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
//internal static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, string fileName, string ccTplName, IntPtr hModelIDs, ref string pNumObj, out EyemImage tpDstImg);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
public
static
extern
void
loadImage2Mem
(
string
key
,
EyemImage
tpImage
);
...
...
@@ -93,6 +94,47 @@ namespace Asa
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
internal
static
extern
int
eyemAchvMatchMat
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
out
EyemImage
tpDstImg
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
internal
static
extern
int
setProcessLevel
(
double
pl
);
#
region
ONNX
识别网络
/// <summary>
/// 初始化ONNX模型(10.0)
/// </summary>
/// <param name="extractorModelPath">模型路径</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
internal
static
extern
int
eyemInitONNXModel
(
string
extractorModelPath
);
/// <summary>
/// 特征提取器
/// </summary>
/// <param name="tpImage">图像(128X128)</param>
/// <param name="fFeatures">特征</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
internal
static
extern
int
eyemExtractWithONNX
(
EyemImage
tpImage
,
[
MarshalAs
(
UnmanagedType
.
LPArray
)]
float
[]
fFeatures
);
/// <summary>
/// 特征匹配
/// </summary>
/// <param name="lhs">向量一</param>
/// <param name="rhs">向量二</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
internal
static
extern
float
calcSimilarity
([
MarshalAs
(
UnmanagedType
.
LPArray
)]
float
[]
lhs
,
[
MarshalAs
(
UnmanagedType
.
LPArray
)]
float
[]
rhs
);
/// <summary>
/// 对图像进行采样生成训练样本
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="iSize">尺寸128(最大224)</param>
/// <param name="ccClassName">类名</param>
/// <param name="ccToPath">保存路径</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
internal
static
extern
int
eyemTrainImageSampler
(
EyemImage
tpImage
,
int
iSize
,
string
ccClassName
,
string
ccToPath
,
out
EyemImage
tpMatchImg
,
out
EyemImage
tpDstImg
);
#
endregion
// 日志回调
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论