Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ReelCounter
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 38889d63
由
SK
编写于
2019-03-21 15:22:11 +0800
浏览文件
选项
浏览文件
标签
下载
差异文件
merge
2 个父辈
c2c05934
933d1e47
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
11 行删除
AccImage/ImageUtil.cs
Demo/MainForm.designer.cs
AccImage/ImageUtil.cs
查看文件 @
38889d6
...
@@ -13,6 +13,7 @@ namespace Acc.Img
...
@@ -13,6 +13,7 @@ namespace Acc.Img
{
{
public
static
bool
selectB
=
false
;
public
static
bool
selectB
=
false
;
public
static
bool
pngB
=
false
;
/// <summary>
/// <summary>
/// 读取图片,,支持格式*.raw,*.bmp;*.gif;*.jpg;*.png
/// 读取图片,,支持格式*.raw,*.bmp;*.gif;*.jpg;*.png
/// </summary>
/// </summary>
...
@@ -25,6 +26,7 @@ namespace Acc.Img
...
@@ -25,6 +26,7 @@ namespace Acc.Img
{
{
if
(
imagePath
.
ToLower
().
EndsWith
(
".raw"
))
if
(
imagePath
.
ToLower
().
EndsWith
(
".raw"
))
{
{
pngB
=
false
;
Bitmap
[]
images
=
ReadRaw
(
imagePath
);
Bitmap
[]
images
=
ReadRaw
(
imagePath
);
if
(
images
!=
null
)
if
(
images
!=
null
)
{
{
...
@@ -33,7 +35,8 @@ namespace Acc.Img
...
@@ -33,7 +35,8 @@ namespace Acc.Img
}
}
else
else
{
{
image
=
Image
.
FromFile
(
imagePath
);
pngB
=
true
;
image
=
Image
.
FromFile
(
imagePath
);
}
}
}
catch
(
Exception
)
}
catch
(
Exception
)
{
{
...
@@ -146,7 +149,6 @@ namespace Acc.Img
...
@@ -146,7 +149,6 @@ namespace Acc.Img
}
}
}
}
}
}
//srcBlob.Area += (int)(srcBlob.Area * 0.2);
for
(
int
i
=
0
;
i
<
blobList
.
Count
;
i
++)
for
(
int
i
=
0
;
i
<
blobList
.
Count
;
i
++)
{
{
if
(
srcBlob
.
Area
<
blobList
[
i
].
Area
)
if
(
srcBlob
.
Area
<
blobList
[
i
].
Area
)
...
@@ -211,15 +213,22 @@ namespace Acc.Img
...
@@ -211,15 +213,22 @@ namespace Acc.Img
Mat
imageMat
=
BitmapConverter
.
ToMat
(
new
Bitmap
(
image
));
Mat
imageMat
=
BitmapConverter
.
ToMat
(
new
Bitmap
(
image
));
Mat
grayMat
=
BitmapConverter
.
ToMat
(
new
Bitmap
(
image
));
Mat
grayMat
=
BitmapConverter
.
ToMat
(
new
Bitmap
(
image
));
Cv2
.
CvtColor
(
grayMat
,
grayMat
,
ColorConversionCodes
.
RGBA2RGB
);
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
);
List
<
CvBlob
>
blobList
=
GetBlobs
(
imageMat
,
thresh
,
inv
);
int
itemArea
=
(
itemFeature
+
23
)
*
3
/
5
;
int
itemArea
=
(
itemFeature
+
23
)
*
3
/
5
;
if
(
itemArea
<=
0
)
if
(
itemArea
<=
0
)
{
{
itemArea
=
3
;
itemArea
=
3
;
}
}
int
totalCount
=
CountBlobs
(
blobList
,
itemArea
,
ref
gray
Mat
);
int
totalCount
=
CountBlobs
(
blobList
,
itemArea
,
ref
image
Mat
);
image
=
BitmapConverter
.
ToBitmap
(
gray
Mat
);
image
=
BitmapConverter
.
ToBitmap
(
image
Mat
);
return
totalCount
;
return
totalCount
;
}
}
...
@@ -510,18 +519,43 @@ namespace Acc.Img
...
@@ -510,18 +519,43 @@ namespace Acc.Img
else
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
)
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
else
{
{
Cv2
.
Threshold
(
dst
,
dst
,
0
,
255
,
ThresholdTypes
.
Binary
);
if
(
pngB
)
Cv2
.
Threshold
(
dst
,
dst
,
0
,
150
,
ThresholdTypes
.
BinaryInv
);
{
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)
//if (thresh == -1)
//{
//{
...
@@ -551,10 +585,9 @@ namespace Acc.Img
...
@@ -551,10 +585,9 @@ namespace Acc.Img
{
{
Cv2
.
CvtColor
(
imageMat
,
imageMat
,
ColorConversionCodes
.
RGBA2BGR
);
Cv2
.
CvtColor
(
imageMat
,
imageMat
,
ColorConversionCodes
.
RGBA2BGR
);
//Cv2.CvtColor(imageMat, imageMat, ColorConversionCodes.RGB2GRAY);
//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
);
Mat
k1
=
Mat
.
Ones
(
new
OpenCvSharp
.
Size
(
1
,
1
),
MatType
.
CV_8UC1
);
Cv2
.
MorphologyEx
(
dst
,
dst
,
MorphTypes
.
Open
,
k1
);
Cv2
.
MorphologyEx
(
dst
,
dst
,
MorphTypes
.
Open
,
k1
);
CvBlobs
blobs
=
new
CvBlobs
();
CvBlobs
blobs
=
new
CvBlobs
();
blobs
.
Label
(
dst
);
blobs
.
Label
(
dst
);
List
<
CvBlob
>
blobList
=
blobs
.
Values
.
Where
(
b
=>
b
.
Area
>
0
).
ToList
();
List
<
CvBlob
>
blobList
=
blobs
.
Values
.
Where
(
b
=>
b
.
Area
>
0
).
ToList
();
...
...
Demo/MainForm.designer.cs
查看文件 @
38889d6
此文件的差异被折叠,
点击展开。
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论