Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
AccAOI
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 90fb296f
由
SK
编写于
2019-06-21 17:10:33 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
Mark 搜索区域显示
1 个父辈
adc71ed4
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
146 行增加
和
31 行删除
AOI/AoiProject.cs
AOI/mark/AoiMarkMethod.cs
AccAOI/FrmAoiSetting.cs
AccAOI/control/AioMarkControl.Designer.cs
AccAOI/control/AioMarkControl.cs
ImageBox/AccImageBox.cs
ImageBox/ImageBox.cs
AOI/AoiProject.cs
查看文件 @
90fb296
...
@@ -74,7 +74,10 @@ namespace AOI
...
@@ -74,7 +74,10 @@ namespace AOI
resultImg
=
image
;
resultImg
=
image
;
return
resultBeans
;
return
resultBeans
;
}
}
/// <summary>
/// 保存项目
/// </summary>
/// <param name="filePath"></param>
public
void
Save
(
string
filePath
)
public
void
Save
(
string
filePath
)
{
{
Dictionary
<
string
,
string
>
projectMap
=
new
Dictionary
<
string
,
string
>();
Dictionary
<
string
,
string
>
projectMap
=
new
Dictionary
<
string
,
string
>();
...
@@ -95,7 +98,10 @@ namespace AOI
...
@@ -95,7 +98,10 @@ namespace AOI
projectMap
.
Add
(
"methodMap"
,
methodMapJson
);
projectMap
.
Add
(
"methodMap"
,
methodMapJson
);
JsonUtil
.
SerializeObjectToFile
(
projectMap
,
filePath
,
false
);
JsonUtil
.
SerializeObjectToFile
(
projectMap
,
filePath
,
false
);
}
}
/// <summary>
/// 加载项目
/// </summary>
/// <param name="filePath"></param>
public
void
Load
(
string
filePath
)
public
void
Load
(
string
filePath
)
{
{
Dictionary
<
string
,
string
>
projectMap
=
JsonUtil
.
DeserializeJsonToObjectFromFile
<
Dictionary
<
string
,
string
>>(
filePath
);
Dictionary
<
string
,
string
>
projectMap
=
JsonUtil
.
DeserializeJsonToObjectFromFile
<
Dictionary
<
string
,
string
>>(
filePath
);
...
...
AOI/mark/AoiMarkMethod.cs
查看文件 @
90fb296
...
@@ -16,9 +16,40 @@ namespace AOI
...
@@ -16,9 +16,40 @@ namespace AOI
public
class
AoiMarkMethod
:
AoiMethod
public
class
AoiMarkMethod
:
AoiMethod
{
{
/// <summary>
/// <summary>
///
搜索区域路径
///
放大RoiPath作为SearchPath
/// </summary>
/// </summary>
public
GraphicsPath
SearchPath
;
public
float
SearchPathZoom
=
2.0f
;
/// <summary>
/// 放大RoiPath作为SearchPath
/// </summary>
/// <param name="zoom">放大倍率</param>
/// <returns></returns>
public
GraphicsPath
GetSearchPath
()
{
if
(
RoiPath
!=
null
&&
SearchPathZoom
>
0
)
{
GraphicsPath
SearchPath
=
new
GraphicsPath
(
RoiPath
.
PathPoints
,
RoiPath
.
PathTypes
);
Matrix
matrix
=
new
Matrix
();
matrix
.
Scale
(
SearchPathZoom
,
SearchPathZoom
);
SearchPath
.
Transform
(
matrix
);
var
oldBounds
=
this
.
RoiPath
.
GetBounds
();
var
newBounds
=
SearchPath
.
GetBounds
();
var
oldCenterX
=
oldBounds
.
X
+
oldBounds
.
Width
/
2
;
var
oldCenterY
=
oldBounds
.
Y
+
oldBounds
.
Height
/
2
;
var
newCenterX
=
newBounds
.
X
+
newBounds
.
Width
/
2
;
var
newCenterY
=
newBounds
.
Y
+
newBounds
.
Height
/
2
;
matrix
.
Reset
();
matrix
.
Translate
(
oldCenterX
-
newCenterX
,
oldCenterY
-
newCenterY
);
SearchPath
.
Transform
(
matrix
);
return
SearchPath
;
}
return
RoiPath
;
}
/// <summary>
/// <summary>
/// 根据Mark点校正相机获取的图片
/// 根据Mark点校正相机获取的图片
...
@@ -44,6 +75,7 @@ namespace AOI
...
@@ -44,6 +75,7 @@ namespace AOI
//标准图中的Mart区域
//标准图中的Mart区域
Image
markImage
=
GetRoiImage
(
standardImage
,
RoiPath
,
needCut
);
Image
markImage
=
GetRoiImage
(
standardImage
,
RoiPath
,
needCut
);
//搜索区域
//搜索区域
var
SearchPath
=
GetSearchPath
();
Image
searchImage
=
GetRoiImage
(
imageToCheck
,
SearchPath
,
needCut
);
Image
searchImage
=
GetRoiImage
(
imageToCheck
,
SearchPath
,
needCut
);
if
(
markImage
!=
null
&&
searchImage
!=
null
)
if
(
markImage
!=
null
&&
searchImage
!=
null
)
{
{
...
...
AccAOI/FrmAoiSetting.cs
查看文件 @
90fb296
...
@@ -198,7 +198,7 @@ namespace AccAOI
...
@@ -198,7 +198,7 @@ namespace AccAOI
//Image threshImage = CutImage(imageBox1.Image, currPath);
//Image threshImage = CutImage(imageBox1.Image, currPath);
//cutImage = threshImage;
//cutImage = threshImage;
aoiControl
.
SetCurrPath
(
currPath
,
fals
e
);
aoiControl
.
SetCurrPath
(
currPath
,
tru
e
);
}
}
aoiControl
.
Show
();
aoiControl
.
Show
();
aoiControl
.
ShowAoiInfo
();
aoiControl
.
ShowAoiInfo
();
...
...
AccAOI/control/AioMarkControl.Designer.cs
查看文件 @
90fb296
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
private
void
InitializeComponent
()
private
void
InitializeComponent
()
{
{
this
.
flatLabel1
=
new
Asa
.
Theme
.
FlatLabel
();
this
.
flatLabel1
=
new
Asa
.
Theme
.
FlatLabel
();
this
.
flatTextSearch
=
new
Asa
.
Theme
.
FlatText
();
this
.
flatTextSearch
Zoom
=
new
Asa
.
Theme
.
FlatText
();
this
.
flatLabel2
=
new
Asa
.
Theme
.
FlatLabel
();
this
.
flatLabel2
=
new
Asa
.
Theme
.
FlatLabel
();
this
.
lblResult
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
lblResult
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
btnTest
=
new
Asa
.
Theme
.
FlatButton
();
this
.
btnTest
=
new
Asa
.
Theme
.
FlatButton
();
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
// panParam
// panParam
//
//
this
.
panParam
.
Controls
.
Add
(
this
.
flatLabel2
);
this
.
panParam
.
Controls
.
Add
(
this
.
flatLabel2
);
this
.
panParam
.
Controls
.
Add
(
this
.
flatTextSearch
);
this
.
panParam
.
Controls
.
Add
(
this
.
flatTextSearch
Zoom
);
this
.
panParam
.
Controls
.
Add
(
this
.
flatLabel1
);
this
.
panParam
.
Controls
.
Add
(
this
.
flatLabel1
);
//
//
// panResult
// panResult
...
@@ -58,15 +58,15 @@
...
@@ -58,15 +58,15 @@
this
.
flatLabel1
.
TabIndex
=
0
;
this
.
flatLabel1
.
TabIndex
=
0
;
this
.
flatLabel1
.
Text
=
"搜索区域:"
;
this
.
flatLabel1
.
Text
=
"搜索区域:"
;
//
//
// flatTextSearch
// flatTextSearch
Zoom
//
//
this
.
flatTextSearch
.
Font
=
new
System
.
Drawing
.
Font
(
"宋体"
,
9F
);
this
.
flatTextSearch
Zoom
.
Font
=
new
System
.
Drawing
.
Font
(
"宋体"
,
9F
);
this
.
flatTextSearch
.
Inside
=
false
;
this
.
flatTextSearch
Zoom
.
Inside
=
false
;
this
.
flatTextSearch
.
Location
=
new
System
.
Drawing
.
Point
(
175
,
50
);
this
.
flatTextSearch
Zoom
.
Location
=
new
System
.
Drawing
.
Point
(
175
,
50
);
this
.
flatTextSearch
.
Name
=
"flatTextSearch
"
;
this
.
flatTextSearch
Zoom
.
Name
=
"flatTextSearchZoom
"
;
this
.
flatTextSearch
.
Size
=
new
System
.
Drawing
.
Size
(
95
,
30
);
this
.
flatTextSearch
Zoom
.
Size
=
new
System
.
Drawing
.
Size
(
95
,
30
);
this
.
flatTextSearch
.
TabIndex
=
1
;
this
.
flatTextSearch
Zoom
.
TabIndex
=
1
;
this
.
flatTextSearch
.
Text
=
"2"
;
this
.
flatTextSearch
Zoom
.
Text
=
"2"
;
//
//
// flatLabel2
// flatLabel2
//
//
...
@@ -116,7 +116,7 @@
...
@@ -116,7 +116,7 @@
#
endregion
#
endregion
private
Asa
.
Theme
.
FlatLabel
flatLabel2
;
private
Asa
.
Theme
.
FlatLabel
flatLabel2
;
private
Asa
.
Theme
.
FlatText
flatTextSearch
;
private
Asa
.
Theme
.
FlatText
flatTextSearch
Zoom
;
private
Asa
.
Theme
.
FlatLabel
flatLabel1
;
private
Asa
.
Theme
.
FlatLabel
flatLabel1
;
private
System
.
Windows
.
Forms
.
Label
lblResult
;
private
System
.
Windows
.
Forms
.
Label
lblResult
;
private
Asa
.
Theme
.
FlatButton
btnTest
;
private
Asa
.
Theme
.
FlatButton
btnTest
;
...
...
AccAOI/control/AioMarkControl.cs
查看文件 @
90fb296
...
@@ -8,6 +8,8 @@ using System.Text;
...
@@ -8,6 +8,8 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
using
System.Windows.Forms
;
using
AOI
;
using
AOI
;
using
System.Threading
;
using
System.Drawing.Drawing2D
;
namespace
AccAOI.control
namespace
AccAOI.control
{
{
...
@@ -19,11 +21,19 @@ namespace AccAOI.control
...
@@ -19,11 +21,19 @@ namespace AccAOI.control
}
}
public
override
AoiMethod
GetAoiInfo
()
public
override
AoiMethod
GetAoiInfo
()
{
{
if
(
currPath
!=
null
)
if
(
this
.
AoiInfo
is
AoiMarkMethod
)
{
{
this
.
AoiInfo
.
RoiPath
=
currPath
;
AoiMarkMethod
method
=
(
AoiMarkMethod
)
AoiInfo
;
float
.
TryParse
(
flatTextSearchZoom
.
Text
,
out
float
zoom
);
method
.
SearchPathZoom
=
zoom
;
if
(
currPath
!=
null
)
{
method
.
RoiPath
=
currPath
;
}
AoiInfo
=
method
;
}
}
return
base
.
GetAoiInfo
()
;
return
AoiInfo
;
}
}
private
void
btnTest_Click
(
object
sender
,
EventArgs
e
)
private
void
btnTest_Click
(
object
sender
,
EventArgs
e
)
...
@@ -34,6 +44,7 @@ namespace AccAOI.control
...
@@ -34,6 +44,7 @@ namespace AccAOI.control
Image
result
=
mark
.
FixImage
(
FrmAoiSetting
.
Img
,
FrmAoiSetting
.
Img
);
Image
result
=
mark
.
FixImage
(
FrmAoiSetting
.
Img
,
FrmAoiSetting
.
Img
);
if
(
result
==
null
)
if
(
result
==
null
)
{
{
this
.
aoiImage
.
Image
=
null
;
lblResult
.
ForeColor
=
Color
.
Red
;
lblResult
.
ForeColor
=
Color
.
Red
;
lblResult
.
Text
=
"Mark区域无效"
;
lblResult
.
Text
=
"Mark区域无效"
;
}
}
...
@@ -46,5 +57,45 @@ namespace AccAOI.control
...
@@ -46,5 +57,45 @@ namespace AccAOI.control
}
}
}
}
public
override
void
UpdateImage
()
{
if
(!
IsShowOk
)
{
return
;
}
if
(
Monitor
.
TryEnter
(
UpdateLock
))
{
try
{
Image
BaseImage
=
GetImg
();
if
(
BaseImage
==
null
||
currPath
==
null
)
{
return
;
}
GetAoiInfo
();
AoiMarkMethod
markMethod
=
(
AoiMarkMethod
)
AoiInfo
;
GraphicsPath
searchPath
=
markMethod
.
GetSearchPath
();
BImageBox
.
ShowPath
(
searchPath
,
Color
.
Yellow
);
GC
.
Collect
();
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"UpdateImage出错:"
+
ex
.
ToString
());
}
finally
{
Monitor
.
Exit
(
UpdateLock
);
}
}
else
{
Console
.
WriteLine
(
"UpdateImage执行失败,未得到锁"
);
}
}
}
}
}
}
ImageBox/AccImageBox.cs
查看文件 @
90fb296
...
@@ -732,6 +732,7 @@ namespace Acc.ImageBox
...
@@ -732,6 +732,7 @@ namespace Acc.ImageBox
this
.
Cursor
=
cursor
;
this
.
Cursor
=
cursor
;
}
}
private
void
StartResize
(
PointF
anchor
)
private
void
StartResize
(
PointF
anchor
)
{
{
CancelEventArgs
e
;
CancelEventArgs
e
;
...
...
ImageBox/ImageBox.cs
查看文件 @
90fb296
...
@@ -86,6 +86,10 @@ namespace Acc.ImageBox
...
@@ -86,6 +86,10 @@ namespace Acc.ImageBox
private
GraphicsPath
_selectionRegion
=
new
GraphicsPath
();
private
GraphicsPath
_selectionRegion
=
new
GraphicsPath
();
private
GraphicsPath
_pathToShow
;
private
Color
_pathColor
;
private
bool
_shortcutsEnabled
;
private
bool
_shortcutsEnabled
;
private
bool
_showPixelGrid
;
private
bool
_showPixelGrid
;
...
@@ -1537,6 +1541,7 @@ namespace Acc.ImageBox
...
@@ -1537,6 +1541,7 @@ namespace Acc.ImageBox
{
{
if
(
value
==
null
)
{
if
(
value
==
null
)
{
value
=
new
GraphicsPath
();
value
=
new
GraphicsPath
();
_pathToShow
=
null
;
}
}
_selectionRegion
=
value
;
_selectionRegion
=
value
;
this
.
OnSelectionRegionChanged
(
EventArgs
.
Empty
);
this
.
OnSelectionRegionChanged
(
EventArgs
.
Empty
);
...
@@ -2643,7 +2648,7 @@ namespace Acc.ImageBox
...
@@ -2643,7 +2648,7 @@ namespace Acc.ImageBox
/// </summary>
/// </summary>
public
virtual
void
SelectNone
()
public
virtual
void
SelectNone
()
{
{
this
.
SelectionRegion
=
n
ew
GraphicsPath
()
;
this
.
SelectionRegion
=
n
ull
;
}
}
/// <summary>
/// <summary>
...
@@ -3161,10 +3166,25 @@ namespace Acc.ImageBox
...
@@ -3161,10 +3166,25 @@ namespace Acc.ImageBox
/// </param>
/// </param>
protected
virtual
void
DrawSelection
(
PaintEventArgs
e
)
protected
virtual
void
DrawSelection
(
PaintEventArgs
e
)
{
{
DrawPath
(
e
.
Graphics
,
this
.
SelectionRegion
,
true
,
this
.
SelectionColor
);
if
(
_pathToShow
!=
null
)
{
DrawPath
(
e
.
Graphics
,
this
.
_pathToShow
,
false
,
this
.
_pathColor
);
}
}
e
.
Graphics
.
SetClip
(
this
.
GetInsideViewPort
(
true
));
/// <summary>
/// 画路径
/// </summary>
/// <param name="g"></param>
/// <param name="path"></param>
/// <param name="needFill"></param>
/// <param name="color"></param>
private
void
DrawPath
(
Graphics
g
,
GraphicsPath
path
,
bool
needFill
,
Color
color
)
{
g
.
SetClip
(
this
.
GetInsideViewPort
(
true
));
GraphicsPath
newPath
=
new
GraphicsPath
(
this
.
SelectionRegion
.
PathPoints
,
this
.
SelectionRegion
.
PathTypes
);
GraphicsPath
newPath
=
new
GraphicsPath
(
path
.
PathPoints
,
path
.
PathTypes
);
Matrix
matrix
=
new
Matrix
();
Matrix
matrix
=
new
Matrix
();
matrix
.
Scale
((
float
)
this
.
ZoomFactor
,
(
float
)
this
.
ZoomFactor
);
matrix
.
Scale
((
float
)
this
.
ZoomFactor
,
(
float
)
this
.
ZoomFactor
);
newPath
.
Transform
(
matrix
);
newPath
.
Transform
(
matrix
);
...
@@ -3176,21 +3196,26 @@ namespace Acc.ImageBox
...
@@ -3176,21 +3196,26 @@ namespace Acc.ImageBox
matrix
.
Translate
(
offsetX
,
offsetY
);
matrix
.
Translate
(
offsetX
,
offsetY
);
newPath
.
Transform
(
matrix
);
newPath
.
Transform
(
matrix
);
//rect = this.GetOffsetRectangle(this.SelectionRegion);
if
(
needFill
)
using
(
Brush
brush
=
new
SolidBrush
(
Color
.
FromArgb
(
128
,
this
.
SelectionColor
)))
{
{
e
.
Graphics
.
FillPath
(
brush
,
newPath
);
using
(
Brush
brush
=
new
SolidBrush
(
Color
.
FromArgb
(
128
,
color
)))
{
g
.
FillPath
(
brush
,
newPath
);
}
}
}
using
(
Pen
pen
=
new
Pen
(
this
.
SelectionC
olor
))
using
(
Pen
pen
=
new
Pen
(
c
olor
))
{
{
//e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
g
.
DrawPath
(
pen
,
newPath
);
e
.
Graphics
.
DrawPath
(
pen
,
newPath
);
}
}
e
.
Graphics
.
ResetClip
();
g
.
ResetClip
();
}
public
void
ShowPath
(
GraphicsPath
path
,
Color
color
)
{
_pathToShow
=
path
;
_pathColor
=
color
;
}
}
/// <summary>
/// <summary>
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论