Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ReelCounter
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 933d1e47
由
cuiya
编写于
2019-03-21 12:49:35 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
FeedCounter_v1
1 个父辈
60a3f895
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
20 行删除
AccImage/ImageUtil.cs
Demo/MainForm.designer.cs
AccImage/ImageUtil.cs
查看文件 @
933d1e4
...
...
@@ -13,6 +13,7 @@ namespace Acc.Img
{
public
static
bool
selectB
=
false
;
public
static
bool
pngB
=
false
;
/// <summary>
/// 读取图片,,支持格式*.raw,*.bmp;*.gif;*.jpg;*.png
/// </summary>
...
...
@@ -25,6 +26,7 @@ namespace Acc.Img
{
if
(
imagePath
.
ToLower
().
EndsWith
(
".raw"
))
{
pngB
=
false
;
Bitmap
[]
images
=
ReadRaw
(
imagePath
);
if
(
images
!=
null
)
{
...
...
@@ -33,7 +35,8 @@ namespace Acc.Img
}
else
{
image
=
Image
.
FromFile
(
imagePath
);
pngB
=
true
;
image
=
Image
.
FromFile
(
imagePath
);
}
}
catch
(
Exception
)
{
...
...
@@ -146,7 +149,6 @@ namespace Acc.Img
}
}
}
//srcBlob.Area += (int)(srcBlob.Area * 0.2);
for
(
int
i
=
0
;
i
<
blobList
.
Count
;
i
++)
{
if
(
srcBlob
.
Area
<
blobList
[
i
].
Area
)
...
...
@@ -211,15 +213,22 @@ namespace Acc.Img
Mat
imageMat
=
BitmapConverter
.
ToMat
(
new
Bitmap
(
image
));
Mat
grayMat
=
BitmapConverter
.
ToMat
(
new
Bitmap
(
image
));
Cv2
.
CvtColor
(
grayMat
,
grayMat
,
ColorConversionCodes
.
RGBA2RGB
);
Cv2
.
Threshold
(
imageMat
,
imageMat
,
0
,
255
,
ThresholdTypes
.
Binary
);
if
(
pngB
)
{
Cv2
.
Threshold
(
imageMat
,
imageMat
,
70
,
255
,
ThresholdTypes
.
Binary
);
}
else
{
Cv2
.
Threshold
(
imageMat
,
imageMat
,
0
,
255
,
ThresholdTypes
.
Binary
);
}
List
<
CvBlob
>
blobList
=
GetBlobs
(
imageMat
,
thresh
,
inv
);
int
itemArea
=
(
itemFeature
+
23
)
*
3
/
5
;
if
(
itemArea
<=
0
)
{
itemArea
=
3
;
}
int
totalCount
=
CountBlobs
(
blobList
,
itemArea
,
ref
gray
Mat
);
image
=
BitmapConverter
.
ToBitmap
(
gray
Mat
);
int
totalCount
=
CountBlobs
(
blobList
,
itemArea
,
ref
image
Mat
);
image
=
BitmapConverter
.
ToBitmap
(
image
Mat
);
return
totalCount
;
}
...
...
@@ -510,18 +519,43 @@ namespace Acc.Img
else
{
//全局二值化
Cv2
.
Threshold
(
dst
,
dst
,
0
,
255
,
ThresholdTypes
.
Binary
);
if
(
pngB
)
{
Cv2
.
Threshold
(
dst
,
dst
,
70
,
255
,
ThresholdTypes
.
Binary
);
}
else
{
Cv2
.
Threshold
(
dst
,
dst
,
0
,
255
,
ThresholdTypes
.
Binary
);
}
}
if
(
inv
)
{
Cv2
.
Threshold
(
dst
,
dst
,
0
,
150
,
ThresholdTypes
.
BinaryInv
);
if
(
pngB
)
{
Cv2
.
Threshold
(
dst
,
dst
,
70
,
150
,
ThresholdTypes
.
BinaryInv
);
}
else
{
Cv2
.
Threshold
(
dst
,
dst
,
0
,
150
,
ThresholdTypes
.
BinaryInv
);
}
}
}
else
{
Cv2
.
Threshold
(
dst
,
dst
,
0
,
255
,
ThresholdTypes
.
Binary
);
Cv2
.
Threshold
(
dst
,
dst
,
0
,
150
,
ThresholdTypes
.
BinaryInv
);
if
(
pngB
)
{
Cv2
.
Threshold
(
dst
,
dst
,
70
,
255
,
ThresholdTypes
.
Binary
);
Cv2
.
Threshold
(
dst
,
dst
,
70
,
150
,
ThresholdTypes
.
BinaryInv
);
}
else
{
Cv2
.
Threshold
(
dst
,
dst
,
0
,
255
,
ThresholdTypes
.
Binary
);
Cv2
.
Threshold
(
dst
,
dst
,
0
,
150
,
ThresholdTypes
.
BinaryInv
);
}
}
//if (thresh == -1)
//{
...
...
@@ -551,10 +585,9 @@ namespace Acc.Img
{
Cv2
.
CvtColor
(
imageMat
,
imageMat
,
ColorConversionCodes
.
RGBA2BGR
);
//Cv2.CvtColor(imageMat, imageMat, ColorConversionCodes.RGB2GRAY);
Mat
dst
=
Threshhold
(
imageMat
,
thresh
,
inv
);
Mat
dst
=
Threshhold
(
imageMat
,
thresh
,
inv
);
Mat
k1
=
Mat
.
Ones
(
new
OpenCvSharp
.
Size
(
1
,
1
),
MatType
.
CV_8UC1
);
Cv2
.
MorphologyEx
(
dst
,
dst
,
MorphTypes
.
Open
,
k1
);
CvBlobs
blobs
=
new
CvBlobs
();
blobs
.
Label
(
dst
);
List
<
CvBlob
>
blobList
=
blobs
.
Values
.
Where
(
b
=>
b
.
Area
>
0
).
ToList
();
...
...
Demo/MainForm.designer.cs
查看文件 @
933d1e4
...
...
@@ -103,7 +103,7 @@
// buttonOpen
//
this
.
buttonOpen
.
Location
=
new
System
.
Drawing
.
Point
(
17
,
11
);
this
.
buttonOpen
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
buttonOpen
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
buttonOpen
.
Name
=
"buttonOpen"
;
this
.
buttonOpen
.
Size
=
new
System
.
Drawing
.
Size
(
100
,
29
);
this
.
buttonOpen
.
TabIndex
=
1
;
...
...
@@ -114,7 +114,7 @@
// buttonCount
//
this
.
buttonCount
.
Location
=
new
System
.
Drawing
.
Point
(
140
,
11
);
this
.
buttonCount
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
buttonCount
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
buttonCount
.
Name
=
"buttonCount"
;
this
.
buttonCount
.
Size
=
new
System
.
Drawing
.
Size
(
100
,
29
);
this
.
buttonCount
.
TabIndex
=
2
;
...
...
@@ -125,7 +125,7 @@
// buttonThesh
//
this
.
buttonThesh
.
Location
=
new
System
.
Drawing
.
Point
(
500
,
16
);
this
.
buttonThesh
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
buttonThesh
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
buttonThesh
.
Name
=
"buttonThesh"
;
this
.
buttonThesh
.
Size
=
new
System
.
Drawing
.
Size
(
100
,
29
);
this
.
buttonThesh
.
TabIndex
=
3
;
...
...
@@ -137,18 +137,18 @@
// textBoxThesh
//
this
.
textBoxThesh
.
Location
=
new
System
.
Drawing
.
Point
(
359
,
16
);
this
.
textBoxThesh
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
textBoxThesh
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
textBoxThesh
.
Name
=
"textBoxThesh"
;
this
.
textBoxThesh
.
Size
=
new
System
.
Drawing
.
Size
(
60
,
25
);
this
.
textBoxThesh
.
TabIndex
=
4
;
this
.
textBoxThesh
.
Text
=
"
3
0"
;
this
.
textBoxThesh
.
Text
=
"
7
0"
;
this
.
textBoxThesh
.
Visible
=
false
;
//
// checkBoxAutoThresh
//
this
.
checkBoxAutoThresh
.
AutoSize
=
true
;
this
.
checkBoxAutoThresh
.
Location
=
new
System
.
Drawing
.
Point
(
428
,
21
);
this
.
checkBoxAutoThresh
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
checkBoxAutoThresh
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
checkBoxAutoThresh
.
Name
=
"checkBoxAutoThresh"
;
this
.
checkBoxAutoThresh
.
Size
=
new
System
.
Drawing
.
Size
(
59
,
19
);
this
.
checkBoxAutoThresh
.
TabIndex
=
5
;
...
...
@@ -167,7 +167,7 @@
this
.
panel1
.
Controls
.
Add
(
this
.
labelCount
);
this
.
panel1
.
Controls
.
Add
(
this
.
labelTime
);
this
.
panel1
.
Location
=
new
System
.
Drawing
.
Point
(-
1
,
514
);
this
.
panel1
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
panel1
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
panel1
.
Name
=
"panel1"
;
this
.
panel1
.
Size
=
new
System
.
Drawing
.
Size
(
853
,
28
);
this
.
panel1
.
TabIndex
=
7
;
...
...
@@ -220,7 +220,7 @@
// textBoxFeature
//
this
.
textBoxFeature
.
Location
=
new
System
.
Drawing
.
Point
(
741
,
20
);
this
.
textBoxFeature
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
textBoxFeature
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
textBoxFeature
.
Name
=
"textBoxFeature"
;
this
.
textBoxFeature
.
Size
=
new
System
.
Drawing
.
Size
(
60
,
25
);
this
.
textBoxFeature
.
TabIndex
=
8
;
...
...
@@ -266,7 +266,7 @@
this
.
Controls
.
Add
(
this
.
buttonOpen
);
this
.
Controls
.
Add
(
this
.
imageBox
);
this
.
Icon
=
((
System
.
Drawing
.
Icon
)(
resources
.
GetObject
(
"$this.Icon"
)));
this
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
4
,
4
,
4
);
this
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
);
this
.
Name
=
"MainForm"
;
this
.
Text
=
"上海锐驰点料系统"
;
this
.
contextMenuStrip
.
ResumeLayout
(
false
);
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论