Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
AccAOI
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit f2064c27
由
LN
编写于
2019-06-20 09:36:44 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
界面显示修改
1 个父辈
1fad1fd0
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
256 行增加
和
109 行删除
AOI/AoiMethod.cs
AOI/rgb/AoiMethodRgb.cs
AccAOI/FrmAoiSetting.cs
AccAOI/control/ABaseControl.Designer.cs
AccAOI/control/ABaseControl.cs
AccAOI/control/AoiBlobControl.Designer.cs
AccAOI/control/AoiBlobControl.cs
AccAOI/control/AoiRgbControl.Designer.cs
AccAOI/control/AoiRgbControl.cs
AOI/AoiMethod.cs
查看文件 @
f2064c2
...
...
@@ -48,13 +48,20 @@ namespace AOI
var
bounds
=
path
.
GetBounds
();
if
(
bounds
.
Width
>
0
&&
bounds
.
Height
>
0
)
{
Bitmap
mask
=
new
Bitmap
(
img
.
Width
,
img
.
Height
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
mask
))
try
{
var
br
=
new
TextureBrush
(
img
);
g
.
FillPath
(
br
,
path
);
Bitmap
mask
=
new
Bitmap
(
img
.
Width
,
img
.
Height
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
mask
))
{
var
br
=
new
TextureBrush
(
img
);
g
.
FillPath
(
br
,
path
);
}
return
mask
;
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
.
ToString
());
}
return
mask
;
}
}
return
null
;
...
...
AOI/rgb/AoiMethodRgb.cs
查看文件 @
f2064c2
...
...
@@ -13,6 +13,16 @@ namespace AOI
/// </summary>
public
class
AoiMethodRgb
:
AoiMethod
{
public
AoiMethodRgb
()
{
minR
=
0
;
minG
=
0
;
minB
=
0
;
maxR
=
255
;
maxG
=
255
;
maxB
=
255
;
}
public
int
minR
{
get
;
set
;
}
public
int
maxR
{
get
;
set
;
}
public
int
minG
{
get
;
set
;
}
...
...
AccAOI/FrmAoiSetting.cs
查看文件 @
f2064c2
...
...
@@ -15,7 +15,7 @@ namespace AccAOI
public
partial
class
FrmAoiSetting
:
Asa
.
Theme
.
FlatForm
{
private
control
.
ABaseControl
aoiControl
=
null
;
public
Image
Img
=
null
;
public
static
Image
Img
=
null
;
private
AoiProject
Project
=
null
;
public
FrmAoiSetting
()
{
...
...
@@ -40,6 +40,13 @@ namespace AccAOI
comType
.
ItemAdd
(
"斑点分析"
);
comType
.
ItemAdd
(
"颜色抽取"
);
comType
.
Text
=
"Mark点设置"
;
string
defaultImg
=
"F:\\电路板图片\\照片 2创建于2019年4月19日 11_34_53.jpg"
;
if
(
System
.
IO
.
File
.
Exists
(
defaultImg
))
{
//读取图片内容
Img
=
(
Image
)
Image
.
FromFile
(
defaultImg
).
Clone
();
imageBox1
.
Image
=
Img
;
}
}
private
void
btnOpenImage_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -57,7 +64,7 @@ namespace AccAOI
string
fileName
=
openDialog
.
FileName
;
//读取图片内容
this
.
Img
=
(
Image
)
Image
.
FromFile
(
fileName
).
Clone
();
Img
=
(
Image
)
Image
.
FromFile
(
fileName
).
Clone
();
imageBox1
.
Image
=
Img
;
}
...
...
@@ -83,7 +90,7 @@ namespace AccAOI
return
;
}
string
fileName
=
openDialog
.
FileName
;
Project
=
new
AoiProject
(
this
.
Img
);
Project
=
new
AoiProject
(
Img
);
Project
.
Load
(
fileName
);
ShowPorject
();
...
...
@@ -113,14 +120,14 @@ namespace AccAOI
private
void
btnNewAoi_Click
(
object
sender
,
EventArgs
e
)
{
if
(
this
.
Img
==
null
)
if
(
Img
==
null
)
{
MessageBox
.
Show
(
"清先打开图片"
);
return
;
}
if
(
this
.
Project
==
null
)
{
Project
=
new
AoiProject
(
this
.
Img
);
Project
=
new
AoiProject
(
Img
);
}
if
(
comType
.
Text
.
Equals
(
""
))
{
...
...
@@ -177,8 +184,6 @@ namespace AccAOI
aoiControl
.
TitleName
=
method
.
MethodName
;
aoiControl
.
TopLevel
=
false
;
aoiControl
.
Parent
=
panAoi
;
aoiControl
.
Show
();
aoiControl
.
ShowAoiInfo
();
if
(
method
.
RoiPath
!=
null
)
{
...
...
@@ -186,10 +191,11 @@ namespace AccAOI
imageBox1
.
SelectionRegion
=
method
.
RoiPath
;
Image
threshImage
=
CutImage
(
imageBox1
.
Image
,
currPath
);
cutImage
=
threshImage
;
aoiControl
.
currPath
=
currPath
;
aoiControl
.
SetImage
(
threshImage
);
aoiControl
.
SetCurrPath
(
currPath
,
false
);
}
aoiControl
.
Show
();
aoiControl
.
ShowAoiInfo
();
}
private
void
SaveCurrAoi
()
{
...
...
@@ -263,7 +269,7 @@ namespace AccAOI
{
try
{
if
(
imageBox1
.
Image
==
null
||
this
.
Img
==
null
||
aoiControl
==
null
)
if
(
imageBox1
.
Image
==
null
||
Img
==
null
||
aoiControl
==
null
)
{
return
;
}
...
...
@@ -283,9 +289,8 @@ namespace AccAOI
currPath
=
imageBox1
.
SelectionRegion
;
Image
threshImage
=
CutImage
(
imageBox1
.
Image
,
currPath
);
cutImage
=
threshImage
;
aoiControl
.
currPath
=
currPath
;
aoiControl
.
SetImage
(
threshImage
);
aoiControl
.
SetCurrPath
(
currPath
);
}
catch
(
Exception
ex
)
{
...
...
@@ -293,25 +298,31 @@ namespace AccAOI
}
private
Image
CutImage
(
Image
src
,
GraphicsPath
path
)
{
var
bounds
=
path
.
GetBounds
();
Bitmap
b
=
new
Bitmap
(
src
.
Width
,
src
.
Height
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
b
))
{
var
br
=
new
TextureBrush
(
src
);
g
.
FillPath
(
br
,
path
);
}
if
(
bounds
.
Width
>
0
&&
bounds
.
Height
>
0
)
try
{
Bitmap
result
=
new
Bitmap
((
int
)
bounds
.
Width
,
(
int
)
bounds
.
Height
);
var
srcRect
=
bounds
;
var
dstRect
=
new
RectangleF
(
0
,
0
,
bounds
.
Width
,
bounds
.
Height
);
bounds
.
Location
=
System
.
Drawing
.
Point
.
Empty
;
using
(
Graphics
g
=
Graphics
.
FromImage
(
result
))
var
bounds
=
path
.
GetBounds
();
Bitmap
b
=
new
Bitmap
(
src
.
Width
,
src
.
Height
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
b
))
{
var
br
=
new
TextureBrush
(
src
);
g
.
FillPath
(
br
,
path
);
}
if
(
bounds
.
Width
>
0
&&
bounds
.
Height
>
0
)
{
Bitmap
result
=
new
Bitmap
((
int
)
bounds
.
Width
,
(
int
)
bounds
.
Height
);
var
srcRect
=
bounds
;
var
dstRect
=
new
RectangleF
(
0
,
0
,
bounds
.
Width
,
bounds
.
Height
);
bounds
.
Location
=
System
.
Drawing
.
Point
.
Empty
;
g
.
DrawImage
(
b
,
dstRect
,
srcRect
,
GraphicsUnit
.
Pixel
);
using
(
Graphics
g
=
Graphics
.
FromImage
(
result
))
{
bounds
.
Location
=
System
.
Drawing
.
Point
.
Empty
;
g
.
DrawImage
(
b
,
dstRect
,
srcRect
,
GraphicsUnit
.
Pixel
);
}
return
result
;
}
return
result
;
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"CutImage出错:"
+
ex
.
ToString
());
}
return
null
;
...
...
AccAOI/control/ABaseControl.Designer.cs
查看文件 @
f2064c2
...
...
@@ -30,8 +30,6 @@ namespace AccAOI.control
/// </summary>
private
void
InitializeComponent
()
{
this
.
aoiImage
=
new
Cyotek
.
Windows
.
Forms
.
ImageBox
();
this
.
btnYuan
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnSetArea
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnClearArea
=
new
Asa
.
Theme
.
FlatButton
();
this
.
panResult
=
new
Asa
.
Theme
.
FlatPanel
();
...
...
@@ -39,34 +37,16 @@ namespace AccAOI.control
this
.
panAreaSet
=
new
Asa
.
Theme
.
FlatPanel
();
this
.
panAreaImage
=
new
Asa
.
Theme
.
FlatPanel
();
this
.
panControl
=
new
Asa
.
Theme
.
FlatPanel
();
this
.
btnImgType
=
new
Asa
.
Theme
.
FlatButton
();
this
.
aoiImage
=
new
Cyotek
.
Windows
.
Forms
.
ImageBox
();
this
.
panAreaSet
.
SuspendLayout
();
this
.
SuspendLayout
();
//
// aoiImage
//
this
.
aoiImage
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)(((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
aoiImage
.
Location
=
new
System
.
Drawing
.
Point
(
9
,
53
);
this
.
aoiImage
.
Name
=
"aoiImage"
;
this
.
aoiImage
.
Size
=
new
System
.
Drawing
.
Size
(
288
,
182
);
this
.
aoiImage
.
TabIndex
=
2
;
//
// btnYuan
//
this
.
btnYuan
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnYuan
.
Inside
=
false
;
this
.
btnYuan
.
Location
=
new
System
.
Drawing
.
Point
(
108
,
274
);
this
.
btnYuan
.
Name
=
"btnYuan"
;
this
.
btnYuan
.
Size
=
new
System
.
Drawing
.
Size
(
90
,
30
);
this
.
btnYuan
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
btnYuan
.
TabIndex
=
8
;
this
.
btnYuan
.
Text
=
"椭圆"
;
this
.
btnYuan
.
Click
+=
new
System
.
EventHandler
(
this
.
btnYuan_Click
);
//
// btnSetArea
//
this
.
btnSetArea
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnSetArea
.
Inside
=
false
;
this
.
btnSetArea
.
Location
=
new
System
.
Drawing
.
Point
(
1
2
,
274
);
this
.
btnSetArea
.
Location
=
new
System
.
Drawing
.
Point
(
1
04
,
30
);
this
.
btnSetArea
.
Name
=
"btnSetArea"
;
this
.
btnSetArea
.
Size
=
new
System
.
Drawing
.
Size
(
90
,
30
);
this
.
btnSetArea
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
...
...
@@ -95,7 +75,7 @@ namespace AccAOI.control
this
.
panResult
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
491
);
this
.
panResult
.
Name
=
"panResult"
;
this
.
panResult
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
6
,
30
,
6
,
6
);
this
.
panResult
.
Size
=
new
System
.
Drawing
.
Size
(
298
,
197
);
this
.
panResult
.
Size
=
new
System
.
Drawing
.
Size
(
298
,
330
);
this
.
panResult
.
TabIndex
=
5
;
this
.
panResult
.
Text
=
"结果判断"
;
//
...
...
@@ -115,6 +95,8 @@ namespace AccAOI.control
//
this
.
panAreaSet
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)(((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
panAreaSet
.
Controls
.
Add
(
this
.
btnImgType
);
this
.
panAreaSet
.
Controls
.
Add
(
this
.
btnSetArea
);
this
.
panAreaSet
.
Inside
=
false
;
this
.
panAreaSet
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
244
);
this
.
panAreaSet
.
Name
=
"panAreaSet"
;
...
...
@@ -144,18 +126,37 @@ namespace AccAOI.control
this
.
panControl
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
panControl
.
Name
=
"panControl"
;
this
.
panControl
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
6
,
30
,
6
,
6
);
this
.
panControl
.
Size
=
new
System
.
Drawing
.
Size
(
30
8
,
696
);
this
.
panControl
.
Size
=
new
System
.
Drawing
.
Size
(
30
9
,
829
);
this
.
panControl
.
TabIndex
=
0
;
this
.
panControl
.
Text
=
"斑点分析"
;
//
// btnImgType
//
this
.
btnImgType
.
ImageSize
=
new
System
.
Drawing
.
Size
(
0
,
0
);
this
.
btnImgType
.
Inside
=
false
;
this
.
btnImgType
.
Location
=
new
System
.
Drawing
.
Point
(
9
,
30
);
this
.
btnImgType
.
Name
=
"btnImgType"
;
this
.
btnImgType
.
Size
=
new
System
.
Drawing
.
Size
(
90
,
30
);
this
.
btnImgType
.
StateColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))),
((
int
)(((
byte
)(
30
)))));
this
.
btnImgType
.
TabIndex
=
8
;
this
.
btnImgType
.
Text
=
"原图"
;
this
.
btnImgType
.
Click
+=
new
System
.
EventHandler
(
this
.
btnImgType_Click
);
//
// aoiImage
//
this
.
aoiImage
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)(((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Left
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
aoiImage
.
Location
=
new
System
.
Drawing
.
Point
(
9
,
53
);
this
.
aoiImage
.
Name
=
"aoiImage"
;
this
.
aoiImage
.
Size
=
new
System
.
Drawing
.
Size
(
288
,
182
);
this
.
aoiImage
.
TabIndex
=
2
;
//
// ABaseControl
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
BackColor
=
System
.
Drawing
.
SystemColors
.
ActiveCaptionText
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
312
,
700
);
this
.
Controls
.
Add
(
this
.
btnYuan
);
this
.
Controls
.
Add
(
this
.
btnSetArea
);
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
312
,
833
);
this
.
Controls
.
Add
(
this
.
btnClearArea
);
this
.
Controls
.
Add
(
this
.
panResult
);
this
.
Controls
.
Add
(
this
.
panParam
);
...
...
@@ -165,6 +166,7 @@ namespace AccAOI.control
this
.
Controls
.
Add
(
this
.
panControl
);
this
.
FormBorderStyle
=
System
.
Windows
.
Forms
.
FormBorderStyle
.
None
;
this
.
Name
=
"ABaseControl"
;
this
.
panAreaSet
.
ResumeLayout
(
false
);
this
.
ResumeLayout
(
false
);
}
...
...
@@ -177,7 +179,7 @@ namespace AccAOI.control
protected
Asa
.
Theme
.
FlatPanel
panParam
;
protected
Asa
.
Theme
.
FlatPanel
panResult
;
public
ImageBox
aoiImage
;
private
Asa
.
Theme
.
FlatButton
btn
Yuan
;
p
ublic
Asa
.
Theme
.
FlatPanel
panControl
;
private
Asa
.
Theme
.
FlatButton
btn
ImgType
;
p
rivate
Asa
.
Theme
.
FlatPanel
panControl
;
}
}
AccAOI/control/ABaseControl.cs
查看文件 @
f2064c2
...
...
@@ -24,35 +24,40 @@ namespace AccAOI.control
get
{
return
panControl
.
Text
;
}
set
{
panControl
.
Text
=
value
;
}
}
protected
object
UpdateLock
=
""
;
public
Image
GetImg
()
{
if
(
this
.
Parent
!=
null
&&
this
.
Parent
is
FrmAoiSetting
)
{
return
((
FrmAoiSetting
)
this
.
Parent
).
Img
;
}
return
null
;
return
FrmAoiSetting
.
Img
;
}
internal
bool
IsShowOk
=
false
;
/// <summary>
/// 区域类型,1=矩形,2=圆形
/// </summary>
public
int
AreaType
=
1
;
/// <summary>
/// 显示的图片类型,1=原图,2=效果图
/// </summary>
public
int
ShowImageType
=
2
;
/// <summary>
/// 区域信息
/// </summary>
p
ublic
GraphicsPath
currPath
=
null
;
p
rotected
GraphicsPath
currPath
=
null
;
public
ImageBox
BImageBox
;
public
AoiMethod
AoiInfo
;
/// <summary>
/// 未处理的小图
/// </summary>
protected
Image
Base
Image
=
null
;
public
void
SetCurrPath
(
GraphicsPath
path
)
protected
Image
Cut
Image
=
null
;
public
void
SetCurrPath
(
GraphicsPath
path
,
bool
isUpdate
=
true
)
{
this
.
currPath
=
path
;
UpdateImage
();
if
(
isUpdate
)
{
UpdateImage
();
}
}
public
virtual
void
UpdateImage
()
...
...
@@ -61,8 +66,9 @@ namespace AccAOI.control
}
public
virtual
void
ShowAoiInfo
()
{
}
public
virtual
AoiMethod
GetAoiInfo
()
IsShowOk
=
true
;
}
public
virtual
AoiMethod
GetAoiInfo
()
{
return
AoiInfo
;
}
...
...
@@ -70,13 +76,13 @@ namespace AccAOI.control
private
void
btnSetArea_Click
(
object
sender
,
EventArgs
e
)
{
AreaType
=
1
;
panAreaSet
.
Text
=
"区域设置
-
矩形"
;
panAreaSet
.
Text
=
"区域设置
-
矩形"
;
}
private
void
btnYuan_Click
(
object
sender
,
EventArgs
e
)
{
AreaType
=
2
;
panAreaSet
.
Text
=
"区域设置
-
椭圆"
;
panAreaSet
.
Text
=
"区域设置
-
椭圆"
;
}
private
void
btnClearArea_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -85,5 +91,21 @@ namespace AccAOI.control
this
.
aoiImage
.
Image
=
null
;
}
private
void
btnImgType_Click
(
object
sender
,
EventArgs
e
)
{
if
(
btnImgType
.
Text
.
Equals
(
"原图"
))
{
ShowImageType
=
1
;
btnImgType
.
Text
=
"效果图"
;
panAreaImage
.
Text
=
"区域图 - 原图"
;
}
else
{
ShowImageType
=
2
;
btnImgType
.
Text
=
"原图"
;
panAreaImage
.
Text
=
"区域图像 - 效果图"
;
}
UpdateImage
();
}
}
}
AccAOI/control/AoiBlobControl.Designer.cs
查看文件 @
f2064c2
...
...
@@ -126,6 +126,7 @@
this
.
txtminArea
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtminArea
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtminArea
.
TabIndex
=
17
;
this
.
txtminArea
.
Text
=
"0"
;
//
// txtmaxArea
//
...
...
@@ -136,6 +137,7 @@
this
.
txtmaxArea
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtmaxArea
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtmaxArea
.
TabIndex
=
18
;
this
.
txtmaxArea
.
Text
=
"-1"
;
//
// flatLabel5
//
...
...
@@ -164,6 +166,7 @@
this
.
txtmaxNum
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtmaxNum
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtmaxNum
.
TabIndex
=
22
;
this
.
txtmaxNum
.
Text
=
"-1"
;
//
// txtminNum
//
...
...
@@ -174,6 +177,7 @@
this
.
txtminNum
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtminNum
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtminNum
.
TabIndex
=
21
;
this
.
txtminNum
.
Text
=
"0"
;
//
// flatLabel6
//
...
...
AccAOI/control/AoiBlobControl.cs
查看文件 @
f2064c2
...
...
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using
System.Windows.Forms
;
using
AOI
;
using
OpenCvSharp.Blob
;
using
System.Threading
;
namespace
AccAOI.control
{
...
...
@@ -30,7 +31,7 @@ namespace AccAOI.control
{
if
(
this
.
AoiInfo
is
AoiBlobMethod
)
{
MethodBlob
=
(
AoiBlobMethod
)
AoiInfo
;
MethodBlob
=
(
AoiBlobMethod
)
AoiInfo
;
if
(
MethodBlob
.
thresh
<
0
)
{
trackBarThresh
.
Value
=
0
;
...
...
@@ -45,6 +46,9 @@ namespace AccAOI.control
txtminArea
.
Text
=
MethodBlob
.
minArea
.
ToString
();
txtmaxNum
.
Text
=
MethodBlob
.
maxNum
.
ToString
();
txtminNum
.
Text
=
MethodBlob
.
minNum
.
ToString
();
IsShowOk
=
true
;
UpdateImage
();
}
}
...
...
@@ -77,17 +81,53 @@ namespace AccAOI.control
}
public
override
void
UpdateImage
()
{
if
(
BaseImage
==
null
)
if
(
!
IsShowOk
)
{
return
;
}
GetAoiInfo
();
Image
outImage
=
null
;
List
<
CvBlob
>
list
=
new
List
<
CvBlob
>();
float
result
=
MethodBlob
.
GetBlobNum
(
BaseImage
,
out
outImage
,
out
list
);
if
(
Monitor
.
TryEnter
(
UpdateLock
))
{
try
{
Image
BaseImage
=
GetImg
();
if
(
BaseImage
==
null
||
currPath
==
null
)
{
return
;
}
GetAoiInfo
();
Image
cutImage
,
dstCutImage
=
null
;
List
<
CvBlob
>
list
=
new
List
<
CvBlob
>();
float
result
=
MethodBlob
.
GetBlobNum
(
BaseImage
,
out
cutImage
,
out
dstCutImage
,
out
list
);
if
(
cutImage
!=
null
&&
dstCutImage
!=
null
)
{
txtNumResult
.
Text
=
result
.
ToString
();
if
(
ShowImageType
.
Equals
(
1
))
{
this
.
aoiImage
.
Image
=
cutImage
;
this
.
CutImage
=
dstCutImage
;
}
else
{
this
.
aoiImage
.
Image
=
dstCutImage
;
this
.
CutImage
=
cutImage
;
}
}
GC
.
Collect
();
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"UpdateImage出错:"
+
ex
.
ToString
());
}
finally
{
Monitor
.
Exit
(
UpdateLock
);
}
}
else
{
Console
.
WriteLine
(
"UpdateImage执行失败,未得到锁"
);
}
txtNumResult
.
Text
=
result
.
ToString
();
this
.
aoiImage
.
Image
=
outImage
;
}
private
void
btnUpdate_Click
(
object
sender
,
EventArgs
e
)
...
...
AccAOI/control/AoiRgbControl.Designer.cs
查看文件 @
f2064c2
...
...
@@ -88,11 +88,6 @@
this
.
panResult
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
688
);
this
.
panResult
.
Size
=
new
System
.
Drawing
.
Size
(
298
,
131
);
//
// panControl
//
this
.
panControl
.
Size
=
new
System
.
Drawing
.
Size
(
308
,
826
);
this
.
panControl
.
Text
=
"颜色抽取"
;
//
// flatLabel5
//
this
.
flatLabel5
.
Inside
=
false
;
...
...
@@ -149,6 +144,7 @@
this
.
txtMaxR
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtMaxR
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtMaxR
.
TabIndex
=
26
;
this
.
txtMaxR
.
Text
=
"255"
;
this
.
txtMaxR
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
txtMinR_TextChanged
);
//
// txtMinR
...
...
@@ -160,6 +156,7 @@
this
.
txtMinR
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtMinR
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtMinR
.
TabIndex
=
25
;
this
.
txtMinR
.
Text
=
"0"
;
this
.
txtMinR
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
txtMinR_TextChanged
);
//
// flatLabel2
...
...
@@ -189,6 +186,7 @@
this
.
txtMaxG
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtMaxG
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtMaxG
.
TabIndex
=
30
;
this
.
txtMaxG
.
Text
=
"255"
;
this
.
txtMaxG
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
txtMinR_TextChanged
);
//
// txtMinG
...
...
@@ -200,6 +198,7 @@
this
.
txtMinG
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtMinG
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtMinG
.
TabIndex
=
29
;
this
.
txtMinG
.
Text
=
"0"
;
this
.
txtMinG
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
txtMinR_TextChanged
);
//
// flatLabel6
...
...
@@ -230,6 +229,7 @@
this
.
txtMaxB
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtMaxB
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtMaxB
.
TabIndex
=
34
;
this
.
txtMaxB
.
Text
=
"255"
;
this
.
txtMaxB
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
txtMinR_TextChanged
);
//
// txtMinB
...
...
@@ -241,6 +241,7 @@
this
.
txtMinB
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
txtMinB
.
Size
=
new
System
.
Drawing
.
Size
(
74
,
30
);
this
.
txtMinB
.
TabIndex
=
33
;
this
.
txtMinB
.
Text
=
"0"
;
this
.
txtMinB
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
txtMinR_TextChanged
);
//
// flatLabel8
...
...
@@ -368,7 +369,6 @@
this
.
Controls
.
Add
(
this
.
flatLabel3
);
this
.
Name
=
"AoiRgbControl"
;
this
.
TitleName
=
"颜色抽取"
;
this
.
Controls
.
SetChildIndex
(
this
.
panControl
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
aoiImage
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
panParam
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
panResult
,
0
);
...
...
AccAOI/control/AoiRgbControl.cs
查看文件 @
f2064c2
...
...
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using
System.Windows.Forms
;
using
AOI
;
using
Asa.Theme
;
using
System.Threading
;
namespace
AccAOI.control
{
...
...
@@ -24,12 +25,12 @@ namespace AccAOI.control
if
(
this
.
AoiInfo
is
AoiMethodRgb
)
{
methodRgb
=
(
AoiMethodRgb
)
AoiInfo
;
//
txtMinR.Text = methodRgb.minR.ToString();
//
txtMaxR.Text = methodRgb.maxR.ToString();
//
txtMinG.Text = methodRgb.minG.ToString();
//
txtMaxG.Text = methodRgb.maxG.ToString();
//
txtMaxB.Text = methodRgb.maxB.ToString();
//
txtMinB.Text = methodRgb.minB.ToString();
txtMinR
.
Text
=
methodRgb
.
minR
.
ToString
();
txtMaxR
.
Text
=
methodRgb
.
maxR
.
ToString
();
txtMinG
.
Text
=
methodRgb
.
minG
.
ToString
();
txtMaxG
.
Text
=
methodRgb
.
maxG
.
ToString
();
txtMaxB
.
Text
=
methodRgb
.
maxB
.
ToString
();
txtMinB
.
Text
=
methodRgb
.
minB
.
ToString
();
SetTbValue
(
tbMinR
,
methodRgb
.
minR
);
SetTbValue
(
tbMaxR
,
methodRgb
.
maxR
);
SetTbValue
(
tbMinG
,
methodRgb
.
minG
);
...
...
@@ -38,6 +39,9 @@ namespace AccAOI.control
SetTbValue
(
tbMinB
,
methodRgb
.
minB
);
txtminRate
.
Text
=
methodRgb
.
minRate
.
ToString
();
txtmaxRate
.
Text
=
methodRgb
.
maxRate
.
ToString
();
IsShowOk
=
true
;
UpdateImage
();
}
}
...
...
@@ -74,17 +78,54 @@ namespace AccAOI.control
public
override
void
UpdateImage
()
{
if
(
BaseImage
==
null
)
if
(
!
IsShowOk
)
{
return
;
}
GetAoiInfo
();
Image
cutImg
=
null
;
Image
dstCutImg
=
null
;
float
rate
=
methodRgb
.
GetRate
(
BaseImage
,
out
cutImg
,
out
dstCutImg
);
txtRate
.
Text
=
rate
.
ToString
();
this
.
aoiImage
.
Image
=
cutImg
;
if
(
Monitor
.
TryEnter
(
UpdateLock
))
{
try
{
Image
BaseImage
=
GetImg
();
if
(
BaseImage
==
null
||
currPath
==
null
)
{
return
;
}
GetAoiInfo
();
Image
cutImg
=
null
;
Image
dstCutImg
=
null
;
float
rate
=
methodRgb
.
GetRate
(
BaseImage
,
out
cutImg
,
out
dstCutImg
);
if
(
cutImg
!=
null
&&
dstCutImg
!=
null
)
{
txtRate
.
Text
=
rate
.
ToString
();
if
(
ShowImageType
.
Equals
(
1
))
{
this
.
aoiImage
.
Image
=
cutImg
;
this
.
CutImage
=
dstCutImg
;
}
else
{
this
.
aoiImage
.
Image
=
dstCutImg
;
this
.
CutImage
=
cutImg
;
}
}
GC
.
Collect
();
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"UpdateImage出错:"
+
ex
.
ToString
());
}
finally
{
Monitor
.
Exit
(
UpdateLock
);
}
}
else
{
Console
.
WriteLine
(
"UpdateImage执行失败,未得到锁"
);
}
}
private
void
btnUpdate_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -134,6 +175,7 @@ namespace AccAOI.control
return
;
}
text
.
Text
=
value
.
ToString
();
UpdateImage
();
}
private
void
SetTbValue
(
TrackBar
tb
,
int
value
)
{
...
...
@@ -141,7 +183,16 @@ namespace AccAOI.control
{
return
;
}
tb
.
Value
=
value
;
if
(
value
<
tb
.
Minimum
)
{
tb
.
Value
=
tb
.
Minimum
;
}
else
if
(
value
>
tb
.
Maximum
)
{
tb
.
Value
=
tb
.
Maximum
;
}
else
{
tb
.
Value
=
value
;
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论