Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ReelCounter
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit b3eb7a97
由
SK
编写于
2019-03-06 12:53:58 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
保存当前图片
1 个父辈
3229c272
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
74 行增加
和
6 行删除
AccImage/ImageUtil.cs
Demo/MainForm.cs
Demo/MainForm.designer.cs
AccImage/ImageUtil.cs
查看文件 @
b3eb7a9
...
@@ -141,6 +141,39 @@ namespace Acc.Img
...
@@ -141,6 +141,39 @@ namespace Acc.Img
return
totalCount
;
return
totalCount
;
}
}
private
static
void
FindCours
(
Mat
srcMat
,
Mat
threshMat
)
{
Mat
[]
contours
=
null
;
Mat
hierarchy
=
new
Mat
();
Cv2
.
FindContours
(
threshMat
,
out
contours
,
hierarchy
,
RetrievalModes
.
External
,
ContourApproximationModes
.
ApproxSimple
);
Mat
linePic
=
Mat
.
Zeros
(
threshMat
.
Rows
,
threshMat
.
Cols
,
MatType
.
CV_8UC3
);
int
contoursSize
=
contours
.
Length
;
for
(
int
index
=
0
;
index
<
contoursSize
;
index
++)
{
//Cv2.DrawContours(linePic, contours, index, Scalar.RandomColor());
//找出完整包含轮廓的最小矩形
//Rect rect = Cv2.BoundingRect(contours[index]);
RotatedRect
rect
=
Cv2
.
MinAreaRect
(
contours
[
index
]);
double
area
=
Cv2
.
ContourArea
(
contours
[
index
]);
if
(
rect
.
Size
.
Height
<
100
||
rect
.
Size
.
Width
<
100
)
{
continue
;
}
//Cv2.Rectangle(originalImg, rect, Scalar.Red);
Point2f
[]
pf
=
rect
.
Points
();
OpenCvSharp
.
Point
[]
ps
=
new
OpenCvSharp
.
Point
[
pf
.
Length
];
for
(
int
i
=
0
;
i
<
pf
.
Length
;
i
++)
{
ps
[
i
]
=
new
OpenCvSharp
.
Point
(
pf
[
i
].
X
,
pf
[
i
].
Y
);
}
Cv2
.
Line
(
srcMat
,
ps
[
0
],
ps
[
1
],
Scalar
.
Red
);
Cv2
.
Line
(
srcMat
,
ps
[
1
],
ps
[
2
],
Scalar
.
Red
);
Cv2
.
Line
(
srcMat
,
ps
[
2
],
ps
[
3
],
Scalar
.
Red
);
Cv2
.
Line
(
srcMat
,
ps
[
0
],
ps
[
3
],
Scalar
.
Red
);
}
}
...
...
Demo/MainForm.cs
查看文件 @
b3eb7a9
...
@@ -156,5 +156,30 @@ namespace Acc.Demo
...
@@ -156,5 +156,30 @@ namespace Acc.Demo
labelFeature
.
Text
=
"特征值:"
+
feature
+
""
;
labelFeature
.
Text
=
"特征值:"
+
feature
+
""
;
textBoxFeature
.
Text
=
feature
+
""
;
textBoxFeature
.
Text
=
feature
+
""
;
}
}
private
void
保存当前图片
ToolStripMenuItem_Click
(
object
sender
,
EventArgs
e
)
{
using
(
FileDialog
dialog
=
new
SaveFileDialog
())
{
dialog
.
Filter
=
"图片 (*.raw,*.bmp;*.gif;*.jpeg;*.jpg;*.png)|*.raw;*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|RAW (*.raw)|*.raw|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*"
;
dialog
.
DefaultExt
=
"png"
;
//保存对话框是否记忆上次打开的目录
dialog
.
RestoreDirectory
=
true
;
if
(
dialog
.
ShowDialog
(
this
)
==
DialogResult
.
OK
)
{
try
{
string
imagePath
=
dialog
.
FileName
;
imageBox
.
Image
.
Save
(
imagePath
);
}
catch
(
Exception
ex
)
{
MessageBox
.
Show
(
ex
.
Message
,
this
.
Text
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
}
}
}
}
}
}
}
}
Demo/MainForm.designer.cs
查看文件 @
b3eb7a9
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
this
.
labelTime
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
labelTime
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
textBoxFeature
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
textBoxFeature
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
label1
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label1
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
保存当前图片
ToolStripMenuItem
=
new
System
.
Windows
.
Forms
.
ToolStripMenuItem
();
this
.
contextMenuStrip
.
SuspendLayout
();
this
.
contextMenuStrip
.
SuspendLayout
();
this
.
panel1
.
SuspendLayout
();
this
.
panel1
.
SuspendLayout
();
this
.
SuspendLayout
();
this
.
SuspendLayout
();
...
@@ -70,35 +71,36 @@
...
@@ -70,35 +71,36 @@
this
.
打开图片
ToolStripMenuItem
,
this
.
打开图片
ToolStripMenuItem
,
this
.
原图
ToolStripMenuItem
,
this
.
原图
ToolStripMenuItem
,
this
.
元件特征
ToolStripMenuItem
,
this
.
元件特征
ToolStripMenuItem
,
this
.
计数
ToolStripMenuItem
});
this
.
计数
ToolStripMenuItem
,
this
.
保存当前图片
ToolStripMenuItem
});
this
.
contextMenuStrip
.
Name
=
"contextMenuStrip"
;
this
.
contextMenuStrip
.
Name
=
"contextMenuStrip"
;
this
.
contextMenuStrip
.
Size
=
new
System
.
Drawing
.
Size
(
1
49
,
92
);
this
.
contextMenuStrip
.
Size
=
new
System
.
Drawing
.
Size
(
1
81
,
136
);
//
//
// 打开图片ToolStripMenuItem
// 打开图片ToolStripMenuItem
//
//
this
.
打开图片
ToolStripMenuItem
.
Name
=
"打开图片ToolStripMenuItem"
;
this
.
打开图片
ToolStripMenuItem
.
Name
=
"打开图片ToolStripMenuItem"
;
this
.
打开图片
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
48
,
22
);
this
.
打开图片
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
22
);
this
.
打开图片
ToolStripMenuItem
.
Text
=
"打开图片"
;
this
.
打开图片
ToolStripMenuItem
.
Text
=
"打开图片"
;
this
.
打开图片
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
打开图片
ToolStripMenuItem_Click
);
this
.
打开图片
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
打开图片
ToolStripMenuItem_Click
);
//
//
// 原图ToolStripMenuItem
// 原图ToolStripMenuItem
//
//
this
.
原图
ToolStripMenuItem
.
Name
=
"原图ToolStripMenuItem"
;
this
.
原图
ToolStripMenuItem
.
Name
=
"原图ToolStripMenuItem"
;
this
.
原图
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
48
,
22
);
this
.
原图
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
22
);
this
.
原图
ToolStripMenuItem
.
Text
=
"重新加载"
;
this
.
原图
ToolStripMenuItem
.
Text
=
"重新加载"
;
this
.
原图
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
原图
ToolStripMenuItem_Click
);
this
.
原图
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
原图
ToolStripMenuItem_Click
);
//
//
// 元件特征ToolStripMenuItem
// 元件特征ToolStripMenuItem
//
//
this
.
元件特征
ToolStripMenuItem
.
Name
=
"元件特征ToolStripMenuItem"
;
this
.
元件特征
ToolStripMenuItem
.
Name
=
"元件特征ToolStripMenuItem"
;
this
.
元件特征
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
48
,
22
);
this
.
元件特征
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
22
);
this
.
元件特征
ToolStripMenuItem
.
Text
=
"获取元件特征"
;
this
.
元件特征
ToolStripMenuItem
.
Text
=
"获取元件特征"
;
this
.
元件特征
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
元件特征
ToolStripMenuItem_Click
);
this
.
元件特征
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
元件特征
ToolStripMenuItem_Click
);
//
//
// 计数ToolStripMenuItem
// 计数ToolStripMenuItem
//
//
this
.
计数
ToolStripMenuItem
.
Name
=
"计数ToolStripMenuItem"
;
this
.
计数
ToolStripMenuItem
.
Name
=
"计数ToolStripMenuItem"
;
this
.
计数
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
48
,
22
);
this
.
计数
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
22
);
this
.
计数
ToolStripMenuItem
.
Text
=
"计数"
;
this
.
计数
ToolStripMenuItem
.
Text
=
"计数"
;
this
.
计数
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
计数
ToolStripMenuItem_Click
);
this
.
计数
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
计数
ToolStripMenuItem_Click
);
//
//
...
@@ -223,6 +225,13 @@
...
@@ -223,6 +225,13 @@
this
.
label1
.
TabIndex
=
9
;
this
.
label1
.
TabIndex
=
9
;
this
.
label1
.
Text
=
"元件特征:"
;
this
.
label1
.
Text
=
"元件特征:"
;
//
//
// 保存当前图片ToolStripMenuItem
//
this
.
保存当前图片
ToolStripMenuItem
.
Name
=
"保存当前图片ToolStripMenuItem"
;
this
.
保存当前图片
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
180
,
22
);
this
.
保存当前图片
ToolStripMenuItem
.
Text
=
"保存当前图片"
;
this
.
保存当前图片
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
保存当前图片
ToolStripMenuItem_Click
);
//
// MainForm
// MainForm
//
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
...
@@ -267,6 +276,7 @@
...
@@ -267,6 +276,7 @@
private
System
.
Windows
.
Forms
.
ToolStripMenuItem
打开图片
ToolStripMenuItem
;
private
System
.
Windows
.
Forms
.
ToolStripMenuItem
打开图片
ToolStripMenuItem
;
private
System
.
Windows
.
Forms
.
Label
label1
;
private
System
.
Windows
.
Forms
.
Label
label1
;
private
System
.
Windows
.
Forms
.
ToolStripMenuItem
计数
ToolStripMenuItem
;
private
System
.
Windows
.
Forms
.
ToolStripMenuItem
计数
ToolStripMenuItem
;
private
System
.
Windows
.
Forms
.
ToolStripMenuItem
保存当前图片
ToolStripMenuItem
;
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论