Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit e9d5142d
由
张士柳
编写于
2021-09-28 15:01:15 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
29630f64
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
474 行增加
和
329 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/Program.cs
eyemLib-Sharp/UnmanagedBitmap.cs
eyemLib-Sharp/eyemLib-Sharp.csproj
eyemLib/eyemBin.cpp
eyemLib/eyemLib.cpp
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemLib.vcxproj
eyemLib/eyemLib.vcxproj.filters
eyemLib/eyemMisc.cpp
eyemLib/eyemStopwatch.cpp
eyemLib/eyemStopwatch.h
eyemLib-Sharp/EyemLib.cs
查看文件 @
e9d5142
...
@@ -10,91 +10,6 @@ using System.IO;
...
@@ -10,91 +10,6 @@ using System.IO;
namespace
eyemLib_Sharp
namespace
eyemLib_Sharp
{
{
public
unsafe
class
EyemLib
{
#
region
枚举
//稳健估计方法
public
enum
ROBUST_METHOD
{
EYEM_DIST_USER
=
-
1
,
EYEM_DIST_L1
=
1
,
EYEM_DIST_L12
=
2
,
EYEM_DIST_FAIR
=
3
,
EYEM_DIST_WELSCH
=
4
,
EYEM_DIST_HUBER
=
5
,
EYEM_DIST_BISQUARE
=
6
,
EYEM_DIST_CAUCHY
=
7
,
EYEM_DIST_LOGISTIC
=
8
,
EYEM_DIST_ANDREWS
=
9
,
EYEM_DIST_ATLWORTH
=
10
}
//图像格式信息
enum
ColorConversionCodes
{
COLOR_BGR2BGRA
=
0
,
//!< add alpha channel to RGB or BGR image
COLOR_RGB2RGBA
=
COLOR_BGR2BGRA
,
COLOR_BGRA2BGR
=
1
,
//!< remove alpha channel from RGB or BGR image
COLOR_RGBA2RGB
=
COLOR_BGRA2BGR
,
COLOR_BGR2RGBA
=
2
,
//!< convert between RGB and BGR color spaces (with or without alpha channel)
COLOR_RGB2BGRA
=
COLOR_BGR2RGBA
,
COLOR_RGBA2BGR
=
3
,
COLOR_BGRA2RGB
=
COLOR_RGBA2BGR
,
COLOR_BGR2RGB
=
4
,
COLOR_RGB2BGR
=
COLOR_BGR2RGB
,
COLOR_BGRA2RGBA
=
5
,
COLOR_RGBA2BGRA
=
COLOR_BGRA2RGBA
,
COLOR_BGR2GRAY
=
6
,
//!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
COLOR_RGB2GRAY
=
7
,
COLOR_GRAY2BGR
=
8
,
COLOR_GRAY2RGB
=
COLOR_GRAY2BGR
,
COLOR_GRAY2BGRA
=
9
,
COLOR_GRAY2RGBA
=
COLOR_GRAY2BGRA
,
COLOR_BGRA2GRAY
=
10
,
COLOR_RGBA2GRAY
=
11
,
COLOR_BGR2XYZ
=
32
,
//!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
COLOR_RGB2XYZ
=
33
,
COLOR_XYZ2BGR
=
34
,
COLOR_XYZ2RGB
=
35
,
COLOR_BGR2HSV
=
40
,
//!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV
=
41
,
COLOR_BGR2Lab
=
44
,
//!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
COLOR_RGB2Lab
=
45
,
COLOR_BGR2Luv
=
50
,
//!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
COLOR_RGB2Luv
=
51
,
COLOR_BGR2HLS
=
52
,
//!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
COLOR_RGB2HLS
=
53
,
COLOR_HSV2BGR
=
54
,
//!< backward conversions to RGB/BGR
COLOR_HSV2RGB
=
55
,
COLOR_Lab2BGR
=
56
,
COLOR_Lab2RGB
=
57
,
COLOR_Luv2BGR
=
58
,
COLOR_Luv2RGB
=
59
,
COLOR_HLS2BGR
=
60
,
COLOR_HLS2RGB
=
61
,
COLOR_BGR2YUV
=
82
,
//!< convert between RGB/BGR and YUV
COLOR_RGB2YUV
=
83
,
COLOR_YUV2BGR
=
84
,
COLOR_YUV2RGB
=
85
,
};
#
endregion
#
region
结构体
#
region
结构体
// 图像信息
// 图像信息
[
StructLayout
(
LayoutKind
.
Sequential
)]
[
StructLayout
(
LayoutKind
.
Sequential
)]
...
@@ -105,6 +20,11 @@ namespace eyemLib_Sharp
...
@@ -105,6 +20,11 @@ namespace eyemLib_Sharp
public
int
iHeight
;
// 图像内存 y 方向大小
public
int
iHeight
;
// 图像内存 y 方向大小
public
int
iDepth
;
// 图像位深度(详见说明)
public
int
iDepth
;
// 图像位深度(详见说明)
public
int
iChannels
;
// 图像通道数
public
int
iChannels
;
// 图像通道数
public
static
implicit
operator
EyemImage
(
UnmanagedBitmap
v
)
{
return
v
.
Image
;
}
}
}
// 矩形定义
// 矩形定义
...
@@ -382,6 +302,19 @@ namespace eyemLib_Sharp
...
@@ -382,6 +302,19 @@ namespace eyemLib_Sharp
public
double
dVx
,
dVy
;
// 向量
public
double
dVx
,
dVy
;
// 向量
}
}
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
EyemBlobParams
{
public
bool
filterByArea
;
//斑点大小限制
public
int
minArea
,
maxArea
;
//最小面积/最大面积
public
bool
filterByCircularity
;
//斑点圆度限制
public
float
minCircularity
,
maxCircularity
;
//圆度最小/大限制
public
bool
filterByInertia
;
//斑点的惯性率限制
public
float
minInertiaRatio
,
maxInertiaRatio
;
//惯性率最小/大限制
public
bool
filterByConvexity
;
//斑点凸度限制
public
float
minConvexity
,
maxConvexity
;
//凸度最小/大限制
}
// 条码 解码结果
// 条码 解码结果
[
StructLayout
(
LayoutKind
.
Sequential
)]
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
EyemBarCode
public
struct
EyemBarCode
...
@@ -427,6 +360,89 @@ namespace eyemLib_Sharp
...
@@ -427,6 +360,89 @@ namespace eyemLib_Sharp
}
// 用于HSV颜色模型分割(H(0-180)、S(0-255)、V(0-255))
}
// 用于HSV颜色模型分割(H(0-180)、S(0-255)、V(0-255))
#
endregion
#
endregion
public
unsafe
class
EyemLib
{
#
region
枚举
//稳健估计方法
public
enum
ROBUST_METHOD
{
EYEM_DIST_USER
=
-
1
,
EYEM_DIST_L1
=
1
,
EYEM_DIST_L12
=
2
,
EYEM_DIST_FAIR
=
3
,
EYEM_DIST_WELSCH
=
4
,
EYEM_DIST_HUBER
=
5
,
EYEM_DIST_BISQUARE
=
6
,
EYEM_DIST_CAUCHY
=
7
,
EYEM_DIST_LOGISTIC
=
8
,
EYEM_DIST_ANDREWS
=
9
,
EYEM_DIST_ATLWORTH
=
10
}
//图像格式信息
enum
ColorConversionCodes
{
COLOR_BGR2BGRA
=
0
,
//!< add alpha channel to RGB or BGR image
COLOR_RGB2RGBA
=
COLOR_BGR2BGRA
,
COLOR_BGRA2BGR
=
1
,
//!< remove alpha channel from RGB or BGR image
COLOR_RGBA2RGB
=
COLOR_BGRA2BGR
,
COLOR_BGR2RGBA
=
2
,
//!< convert between RGB and BGR color spaces (with or without alpha channel)
COLOR_RGB2BGRA
=
COLOR_BGR2RGBA
,
COLOR_RGBA2BGR
=
3
,
COLOR_BGRA2RGB
=
COLOR_RGBA2BGR
,
COLOR_BGR2RGB
=
4
,
COLOR_RGB2BGR
=
COLOR_BGR2RGB
,
COLOR_BGRA2RGBA
=
5
,
COLOR_RGBA2BGRA
=
COLOR_BGRA2RGBA
,
COLOR_BGR2GRAY
=
6
,
//!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
COLOR_RGB2GRAY
=
7
,
COLOR_GRAY2BGR
=
8
,
COLOR_GRAY2RGB
=
COLOR_GRAY2BGR
,
COLOR_GRAY2BGRA
=
9
,
COLOR_GRAY2RGBA
=
COLOR_GRAY2BGRA
,
COLOR_BGRA2GRAY
=
10
,
COLOR_RGBA2GRAY
=
11
,
COLOR_BGR2XYZ
=
32
,
//!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
COLOR_RGB2XYZ
=
33
,
COLOR_XYZ2BGR
=
34
,
COLOR_XYZ2RGB
=
35
,
COLOR_BGR2HSV
=
40
,
//!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV
=
41
,
COLOR_BGR2Lab
=
44
,
//!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
COLOR_RGB2Lab
=
45
,
COLOR_BGR2Luv
=
50
,
//!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
COLOR_RGB2Luv
=
51
,
COLOR_BGR2HLS
=
52
,
//!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
COLOR_RGB2HLS
=
53
,
COLOR_HSV2BGR
=
54
,
//!< backward conversions to RGB/BGR
COLOR_HSV2RGB
=
55
,
COLOR_Lab2BGR
=
56
,
COLOR_Lab2RGB
=
57
,
COLOR_Luv2BGR
=
58
,
COLOR_Luv2RGB
=
59
,
COLOR_HLS2BGR
=
60
,
COLOR_HLS2RGB
=
61
,
COLOR_BGR2YUV
=
82
,
//!< convert between RGB/BGR and YUV
COLOR_RGB2YUV
=
83
,
COLOR_YUV2BGR
=
84
,
COLOR_YUV2RGB
=
85
,
};
#
endregion
#
region
通用
#
region
通用
...
@@ -593,7 +609,7 @@ namespace eyemLib_Sharp
...
@@ -593,7 +609,7 @@ namespace eyemLib_Sharp
/// <param name="tpDstImage">结果图像</param>
/// <param name="tpDstImage">结果图像</param>
/// <returns></returns>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemBinBlob
(
EyemImage
tpImage
,
out
BlobHandle
hObject
,
int
iAreaThr
s
,
out
EyemBinBlob
*
tpResult
,
out
int
ipNum
,
out
EyemImage
tpDstImage
);
private
static
extern
int
eyemBinBlob
(
EyemImage
tpImage
,
out
BlobHandle
hObject
,
EyemBlobParams
tpParam
s
,
out
EyemBinBlob
*
tpResult
,
out
int
ipNum
,
out
EyemImage
tpDstImage
);
/// <summary>
/// <summary>
/// 释放Blob资源
/// 释放Blob资源
/// </summary>
/// </summary>
...
@@ -1065,7 +1081,7 @@ namespace eyemLib_Sharp
...
@@ -1065,7 +1081,7 @@ namespace eyemLib_Sharp
#
region
测试专用接口
#
region
测试专用接口
//测试接口
//测试接口
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemHSVModel
tpHSVModel
,
out
EyemImage
tpDstImg
);
private
static
extern
int
eyemLibImpl
(
EyemImage
tpImage
,
out
EyemImage
tpDstImg
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemEdge1dRidgeDetection
(
EyemImage
tpImage
);
private
static
extern
int
eyemEdge1dRidgeDetection
(
EyemImage
tpImage
);
...
@@ -1132,6 +1148,9 @@ namespace eyemLib_Sharp
...
@@ -1132,6 +1148,9 @@ namespace eyemLib_Sharp
sw
.
Restart
();
sw
.
Restart
();
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
//UnmanagedBitmap umBitmap = new UnmanagedBitmap("D:\\算法测试图像\\circle_plate_04.png");
//return;
//flag = eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", "", "") & eyemInitNNDetector(".\\darknet\\detect-tiny-label.cfg", ".\\darknet\\detect-tiny-label.weights");
//flag = eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", "", "") & eyemInitNNDetector(".\\darknet\\detect-tiny-label.cfg", ".\\darknet\\detect-tiny-label.weights");
////红色分割
////红色分割
...
@@ -1149,36 +1168,36 @@ namespace eyemLib_Sharp
...
@@ -1149,36 +1168,36 @@ namespace eyemLib_Sharp
//tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 };
//tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//flag = eyemLibImpl(image,
tpHsvModel,
out tpDstImg);
//flag = eyemLibImpl(image, out tpDstImg);
EyemImage
templ
,
search
;
//
EyemImage templ, search;
flag
=
eyemImageRead
(
"D://批量测试图像//template.png"
,
-
1
,
out
templ
);
//
flag = eyemImageRead("D://批量测试图像//template.png", -1, out templ);
if
(
flag
!=
0
)
//
if (flag != 0)
{
//
{
Console
.
WriteLine
(
"读图失败!"
);
//
Console.WriteLine("读图失败!");
return
;
//
return;
}
//
}
flag
=
eyemImageRead
(
"D://批量测试图像//search1.png"
,
-
1
,
out
search
);
//
flag = eyemImageRead("D://批量测试图像//search1.png", -1, out search);
if
(
flag
!=
0
)
//
if (flag != 0)
{
//
{
Console
.
WriteLine
(
"读图失败!"
);
//
Console.WriteLine("读图失败!");
return
;
//
return;
}
//
}
flag
=
eyemMakeShapeModel
(
templ
,
100
,
10
);
//
flag = eyemMakeShapeModel(templ, 100, 10);
flag
=
eyemFindShapeModel
(
search
,
10
,
0
,
90
,
1
,
10
,
100
,
0.9
,
0.9
);
//
flag = eyemFindShapeModel(search, 10, 0, 90, 1, 10, 100, 0.9, 0.9);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//if (bitmap != null)
//{
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//}
sw
.
Stop
();
//
sw.Stop();
Console
.
WriteLine
(
"时间花费"
+
sw
.
ElapsedMilliseconds
.
ToString
());
//
Console.WriteLine("时间花费" + sw.ElapsedMilliseconds.ToString());
eyemImageFree
(
ref
templ
);
//
eyemImageFree(ref templ);
eyemImageFree
(
ref
search
);
//
eyemImageFree(ref search);
return
;
//
return;
//flag = eyemNormalize(ref image);
//flag = eyemNormalize(ref image);
...
@@ -1190,13 +1209,10 @@ namespace eyemLib_Sharp
...
@@ -1190,13 +1209,10 @@ namespace eyemLib_Sharp
//EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//flag = eyemMarkerTracing(image, tpHsvModel, ref tpCircle, out tpDstImg, false);
//flag = eyemMarkerTracing(image, tpHsvModel, ref tpCircle, out tpDstImg, false);
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref tpDstImg);
//sw.Stop();
//sw.Stop();
//Console.WriteLine("时间:" + sw.ElapsedMilliseconds.ToString());
//Console.WriteLine("时间:" + sw.ElapsedMilliseconds.ToString());
//flag = eyemEdge1dRidgeDetection(image);
//flag = eyemShockFilter(image, 9, 1.5, 0.5, 10, out tpDstImg);
//flag = eyemShockFilter(image, 9, 1.5, 0.5, 10, out tpDstImg);
//flag = eyemNonLocalMeansFilter(image, 7, 21, 3.0, -1);
//flag = eyemNonLocalMeansFilter(image, 7, 21, 3.0, -1);
...
@@ -1209,26 +1225,31 @@ namespace eyemLib_Sharp
...
@@ -1209,26 +1225,31 @@ namespace eyemLib_Sharp
//return;
//return;
#
region
Test
Blob
#
region
Test
Blob
//sw.Restart();
sw
.
Restart
();
//int ipNum;
EyemBlobParams
tpParams
=
new
EyemBlobParams
();
//BlobHandle hObject;
tpParams
.
filterByArea
=
true
;
tpParams
.
minArea
=
25
;
tpParams
.
maxArea
=
int
.
MaxValue
;
//EyemBinBlob* tpResults;
tpParams
.
filterByCircularity
=
false
;
tpParams
.
minCircularity
=
0.8F
;
tpParams
.
maxCircularity
=
float
.
MaxValue
;
//eyemBinBlob(image, out hObject, 100, out tpResults, out ipNum, out tpDstImg);
tpParams
.
filterByConvexity
=
false
;
tpParams
.
minConvexity
=
0.95F
;
tpParams
.
maxConvexity
=
float
.
MaxValue
;
//sw.Stop();
tpParams
.
filterByInertia
=
false
;
tpParams
.
minInertiaRatio
=
0.8F
;
tpParams
.
maxInertiaRatio
=
float
.
MaxValue
;
//for (int i = 0; i < ipNum; i++)
int
ipNum
;
//{
BlobHandle
hObject
;
// Console.WriteLine(tpResults[i].iArea);
EyemBinBlob
*
tpResults
;
//}
eyemBinBlob
(
image
,
out
hObject
,
tpParams
,
out
tpResults
,
out
ipNum
,
out
tpDstImg
);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
sw
.
Stop
();
//if (bitmap != null)
for
(
int
i
=
0
;
i
<
ipNum
;
i
++)
//{
{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
Console
.
WriteLine
(
tpResults
[
i
].
iArea
);
//}
}
//hObject.Dispose();
Bitmap
bitmap
=
eyemCvtToBitmap
(
tpDstImg
);
//eyemImageFree(ref tpDstImg);
if
(
bitmap
!=
null
)
//eyemImageFree(ref image);
{
//Console.WriteLine("时间-:" + sw.ElapsedMilliseconds.ToString());
bitmap
.
Save
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
+
"\\ResOut\\"
+
file
);
//return;
}
hObject
.
Dispose
();
eyemImageFree
(
ref
tpDstImg
);
eyemImageFree
(
ref
image
);
Console
.
WriteLine
(
"时间-:"
+
sw
.
ElapsedMilliseconds
.
ToString
());
return
;
#
endregion
#
endregion
#
region
Test
1D
Edge
#
region
Test
1D
Edge
...
@@ -1428,7 +1449,6 @@ namespace eyemLib_Sharp
...
@@ -1428,7 +1449,6 @@ namespace eyemLib_Sharp
//tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.vpImage = tpModelID.vpImage;
//tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.vpImage = tpModelID.vpImage;
//Bitmap bitmap = eyemCvtToBitmap(tpModeImg);
//Bitmap bitmap = eyemCvtToBitmap(tpModeImg);
//if (bitmap != null)
//if (bitmap != null)
//{
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
...
@@ -1439,7 +1459,7 @@ namespace eyemLib_Sharp
...
@@ -1439,7 +1459,7 @@ namespace eyemLib_Sharp
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_LOWCONTRAST_PARTS",IP_SQUARE_PARTS
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_LOWCONTRAST_PARTS",IP_SQUARE_PARTS
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_SMALL
_PARTS", ipReelNum, out tpDstImg);
eyemCountObjectIrregularParts
(
image
,
tpRoi
,
file
.
Replace
(
".png"
,
""
),
"IP_LARGE
_PARTS"
,
ipReelNum
,
out
tpDstImg
);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg);
...
@@ -1449,7 +1469,6 @@ namespace eyemLib_Sharp
...
@@ -1449,7 +1469,6 @@ namespace eyemLib_Sharp
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//if (bitmap != null)
//{
//{
// //bitmap.Save("D:\\ResOut\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//}
...
@@ -1473,7 +1492,6 @@ namespace eyemLib_Sharp
...
@@ -1473,7 +1492,6 @@ namespace eyemLib_Sharp
}
}
sw
.
Stop
();
sw
.
Stop
();
Console
.
WriteLine
(
file
+
"--->"
+
"耗时:"
+
sw
.
ElapsedMilliseconds
.
ToString
()
+
"ms"
+
",结果:"
+
strReelNum
);
Console
.
WriteLine
(
file
+
"--->"
+
"耗时:"
+
sw
.
ElapsedMilliseconds
.
ToString
()
+
"ms"
+
",结果:"
+
strReelNum
);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//if (bitmap != null)
//{
//{
...
...
eyemLib-Sharp/Program.cs
查看文件 @
e9d5142
...
@@ -21,7 +21,6 @@ namespace eyemLib_Sharp
...
@@ -21,7 +21,6 @@ namespace eyemLib_Sharp
foreach
(
var
item
in
fileNames
)
foreach
(
var
item
in
fileNames
)
{
{
EyemLib
.
eyemReadImageTool
(
item
);
EyemLib
.
eyemReadImageTool
(
item
);
break
;
}
}
EyemLib
.
Free
();
EyemLib
.
Free
();
Console
.
Write
(
"请按任意键继续。。。"
);
Console
.
Write
(
"请按任意键继续。。。"
);
...
...
eyemLib-Sharp/UnmanagedBitmap.cs
0 → 100644
查看文件 @
e9d5142
using
System
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Runtime.InteropServices
;
namespace
eyemLib_Sharp
{
public
unsafe
class
UnmanagedBitmap
:
IDisposable
{
#
region
接口
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemImageRead
(
string
filename
,
int
iFalgs
,
out
EyemImage
tpImage
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
void
eyemImageFree
(
ref
EyemImage
tpImage
);
#
endregion
private
EyemImage
image
;
public
EyemImage
Image
{
get
{
return
image
;
}
}
public
UnmanagedBitmap
()
{
image
=
new
EyemImage
();
}
public
UnmanagedBitmap
(
string
fileName
)
{
eyemImageRead
(
fileName
,
-
1
,
out
image
);
}
public
UnmanagedBitmap
(
Bitmap
bitmap
)
{
mustbeDispose
=
true
;
image
=
eyemCvtToEyemImage
(
bitmap
);
}
private
bool
mustbeDispose
=
false
;
~
UnmanagedBitmap
()
{
Dispose
(
false
);
}
public
void
Dispose
()
{
Dispose
(
true
);
GC
.
SuppressFinalize
(
this
);
}
protected
virtual
void
Dispose
(
bool
disposing
)
{
if
(
disposing
)
{
// dispose managed resources
}
if
(
mustbeDispose
)
{
image
.
iChannels
=
image
.
iDepth
=
image
.
iHeight
=
image
.
iWidth
=
0
;
Marshal
.
FreeHGlobal
(
image
.
vpImage
);
image
.
vpImage
=
IntPtr
.
Zero
;
}
else
{
eyemImageFree
(
ref
image
);
}
}
#
region
EyemImage
与
Bitmap
相互转换
public
static
Bitmap
eyemCvtToBitmap
(
EyemImage
tpImage
)
{
if
(
tpImage
.
vpImage
==
IntPtr
.
Zero
||
tpImage
.
iDepth
!=
0
)
return
null
;
PixelFormat
format
;
switch
(
tpImage
.
iChannels
)
{
case
1
:
format
=
PixelFormat
.
Format8bppIndexed
;
break
;
case
3
:
format
=
PixelFormat
.
Format24bppRgb
;
break
;
case
4
:
format
=
PixelFormat
.
Format32bppArgb
;
break
;
default
:
return
null
;
}
Bitmap
bitmap
=
new
Bitmap
(
tpImage
.
iWidth
,
tpImage
.
iHeight
,
format
);
//对于输出灰度图像
if
(
format
==
PixelFormat
.
Format8bppIndexed
)
{
ColorPalette
palette
=
bitmap
.
Palette
;
for
(
int
i
=
0
;
i
<
256
;
i
++)
{
palette
.
Entries
[
i
]
=
Color
.
FromArgb
(
i
,
i
,
i
);
}
bitmap
.
Palette
=
palette
;
}
//锁定数据区
BitmapData
bd
=
bitmap
.
LockBits
(
new
Rectangle
(
0
,
0
,
tpImage
.
iWidth
,
tpImage
.
iHeight
),
ImageLockMode
.
WriteOnly
,
format
);
try
{
int
pd
=
((
tpImage
.
iWidth
*
tpImage
.
iChannels
)
+
3
)
/
4
*
4
;
long
bytesToCopy
=
tpImage
.
iWidth
*
tpImage
.
iChannels
;
for
(
int
y
=
0
;
y
<
tpImage
.
iHeight
;
y
++)
{
long
offsetSrc
=
(
y
*
tpImage
.
iWidth
*
tpImage
.
iChannels
);
long
offsetDst
=
(
y
*
pd
);
Buffer
.
MemoryCopy
((
byte
*)(
tpImage
.
vpImage
.
ToPointer
())
+
offsetSrc
,
(
byte
*)(
bd
.
Scan0
.
ToPointer
())
+
offsetDst
,
bytesToCopy
,
bytesToCopy
);
}
}
finally
{
bitmap
.
UnlockBits
(
bd
);
}
return
bitmap
;
}
public
static
EyemImage
eyemCvtToEyemImage
(
Bitmap
bitmap
)
{
EyemImage
tpImage
=
new
EyemImage
();
//锁定数据区
BitmapData
bd
=
bitmap
.
LockBits
(
new
Rectangle
(
0
,
0
,
bitmap
.
Width
,
bitmap
.
Height
),
ImageLockMode
.
ReadOnly
,
bitmap
.
PixelFormat
);
switch
(
bitmap
.
PixelFormat
)
{
case
PixelFormat
.
Format8bppIndexed
:
tpImage
.
iChannels
=
1
;
break
;
case
PixelFormat
.
Format24bppRgb
:
tpImage
.
iChannels
=
3
;
break
;
case
PixelFormat
.
Format32bppArgb
:
tpImage
.
iChannels
=
4
;
break
;
default
:
throw
new
Exception
(
"Image formats are not supported"
);
}
//仅支持8位
tpImage
.
iDepth
=
0
;
//图像尺寸
tpImage
.
iWidth
=
bitmap
.
Width
;
tpImage
.
iHeight
=
bitmap
.
Height
;
//分配内存(释放不是用eyemImageFree,用Marshal.FreeHGlobal(tpImage.vpImage))
tpImage
.
vpImage
=
Marshal
.
AllocHGlobal
(
bd
.
Stride
*
bd
.
Height
);
try
{
int
pd
=
((
tpImage
.
iWidth
*
tpImage
.
iChannels
)
+
3
)
/
4
*
4
;
long
bytesToCopy
=
tpImage
.
iWidth
*
tpImage
.
iChannels
;
for
(
int
y
=
0
;
y
<
tpImage
.
iHeight
;
y
++)
{
long
offsetSrc
=
y
*
pd
;
long
offsetDst
=
y
*
tpImage
.
iWidth
*
tpImage
.
iChannels
;
Buffer
.
MemoryCopy
((
byte
*)(
bd
.
Scan0
.
ToPointer
())
+
offsetSrc
,
(
byte
*)(
tpImage
.
vpImage
.
ToPointer
())
+
offsetDst
,
bytesToCopy
,
bytesToCopy
);
}
}
finally
{
bitmap
.
UnlockBits
(
bd
);
}
return
tpImage
;
}
#
endregion
}
}
eyemLib-Sharp/eyemLib-Sharp.csproj
查看文件 @
e9d5142
...
@@ -55,6 +55,7 @@
...
@@ -55,6 +55,7 @@
<Compile Include="log4cpp\LogManager.cs" />
<Compile Include="log4cpp\LogManager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnmanagedBitmap.cs" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="app.config" />
...
...
eyemLib/eyemBin.cpp
查看文件 @
e9d5142
...
@@ -1276,7 +1276,6 @@ int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpD
...
@@ -1276,7 +1276,6 @@ int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpD
//合并
//合并
cv
::
Mat
maskj
;
cv
::
Mat
maskj
;
cv
::
bitwise_or
(
mask1
,
mask2
,
maskj
);
cv
::
bitwise_or
(
mask1
,
mask2
,
maskj
);
//输出结果图像
//输出结果图像
if
(
NULL
!=
tpDstImg
->
vpImage
)
{
if
(
NULL
!=
tpDstImg
->
vpImage
)
{
tpDstImg
->
iWidth
=
tpDstImg
->
iHeight
=
tpDstImg
->
iDepth
=
tpDstImg
->
iChannels
=
0
;
tpDstImg
->
iWidth
=
tpDstImg
->
iHeight
=
tpDstImg
->
iDepth
=
tpDstImg
->
iChannels
=
0
;
...
@@ -1284,21 +1283,16 @@ int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpD
...
@@ -1284,21 +1283,16 @@ int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpD
free
(
tpDstImg
->
vpImage
);
free
(
tpDstImg
->
vpImage
);
tpDstImg
->
vpImage
=
NULL
;
tpDstImg
->
vpImage
=
NULL
;
}
}
tpDstImg
->
iWidth
=
maskj
.
cols
;
tpDstImg
->
iHeight
=
maskj
.
rows
;
tpDstImg
->
iDepth
=
maskj
.
depth
();
tpDstImg
->
iChannels
=
maskj
.
channels
();
tpDstImg
->
iWidth
=
maskj
.
cols
;
tpDstImg
->
iHeight
=
maskj
.
rows
;
tpDstImg
->
iDepth
=
maskj
.
depth
();
tpDstImg
->
iChannels
=
maskj
.
channels
();
//内存尺寸
//内存尺寸
int
_Size
=
tpDstImg
->
iWidth
*
tpDstImg
->
iHeight
*
tpDstImg
->
iChannels
*
sizeof
(
uint8_t
);
int
_Size
=
tpDstImg
->
iWidth
*
tpDstImg
->
iHeight
*
tpDstImg
->
iChannels
*
sizeof
(
uint8_t
);
//分配初始化内存
//分配初始化内存
tpDstImg
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
tpDstImg
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
if
(
NULL
==
tpDstImg
->
vpImage
)
if
(
NULL
==
tpDstImg
->
vpImage
)
return
FUNC_NOT_ENOUGH_MEM
;
return
FUNC_NOT_ENOUGH_MEM
;
memset
(
tpDstImg
->
vpImage
,
0
,
_Size
);
memset
(
tpDstImg
->
vpImage
,
0
,
_Size
);
//拷贝数据
//拷贝数据
memcpy
(
tpDstImg
->
vpImage
,
maskj
.
data
,
_Size
);
memcpy
(
tpDstImg
->
vpImage
,
maskj
.
data
,
_Size
);
return
FUNC_OK
;
return
FUNC_OK
;
}
}
...
@@ -1323,7 +1317,7 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst
...
@@ -1323,7 +1317,7 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst
return
FUNC_OK
;
return
FUNC_OK
;
}
}
int
eyemBinBlob
(
EyemImage
tpImage
,
IntPtr
*
hObject
,
int
iAreaThr
s
,
EyemBinBlob
**
tpResult
,
int
*
ipNum
,
EyemImage
*
tpDstImg
)
int
eyemBinBlob
(
EyemImage
tpImage
,
IntPtr
*
hObject
,
EyemBlobParams
tpParam
s
,
EyemBinBlob
**
tpResult
,
int
*
ipNum
,
EyemImage
*
tpDstImg
)
{
{
CV_Assert
(
tpImage
.
vpImage
!=
NULL
);
CV_Assert
(
tpImage
.
vpImage
!=
NULL
);
...
@@ -1336,7 +1330,6 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
...
@@ -1336,7 +1330,6 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
if
(
image
.
type
()
!=
CV_8UC1
||
image
.
channels
()
!=
1
)
{
if
(
image
.
type
()
!=
CV_8UC1
||
image
.
channels
()
!=
1
)
{
return
FUNC_CANNOT_CALC
;
return
FUNC_CANNOT_CALC
;
}
}
cv
::
threshold
(
image
,
image
,
0
,
255
,
cv
::
THRESH_BINARY_INV
|
cv
::
THRESH_OTSU
);
cv
::
threshold
(
image
,
image
,
0
,
255
,
cv
::
THRESH_BINARY_INV
|
cv
::
THRESH_OTSU
);
//显示图像
//显示图像
...
@@ -1344,35 +1337,18 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
...
@@ -1344,35 +1337,18 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
cv
::
cvtColor
(
image
,
showMat
,
cv
::
COLOR_GRAY2RGB
);
cv
::
cvtColor
(
image
,
showMat
,
cv
::
COLOR_GRAY2RGB
);
//图像尺寸
//图像尺寸
const
int
X
=
image
.
cols
,
Y
=
image
.
rows
;
const
int
X
=
image
.
cols
,
Y
=
image
.
rows
;
//斑点大小限制
bool
filterByArea
=
true
;
int
minArea
=
25
,
maxArea
=
25000
;
//斑点圆度限制
bool
filterByCircularity
=
false
;
float
minCircularity
=
0.8
f
,
maxCircularity
=
std
::
numeric_limits
<
float
>::
max
();
//斑点的惯性率限制
bool
filterByInertia
=
false
;
float
minInertiaRatio
=
0.1
f
,
maxInertiaRatio
=
std
::
numeric_limits
<
float
>::
max
();
//斑点凸度限制
bool
filterByConvexity
=
false
;
float
minConvexity
=
0.8
f
,
maxConvexity
=
std
::
numeric_limits
<
float
>::
max
();
//斑点检测
//斑点检测
cv
::
Mat
labels
,
stats
,
centroids
;
cv
::
Mat
labels
,
stats
,
centroids
;
int
nccomps
=
cv
::
connectedComponentsWithStats
(
image
,
labels
,
stats
,
centroids
);
int
nccomps
=
cv
::
connectedComponentsWithStats
(
image
,
labels
,
stats
,
centroids
);
std
::
vector
<
uchar
>
colors
(
nccomps
+
1
,
0
);
std
::
vector
<
uchar
>
colors
(
nccomps
+
1
,
0
);
//按面积过滤
//按面积过滤
if
(
filterByArea
)
{
if
(
tpParams
.
filterByArea
)
{
//过滤连通域面积
//过滤连通域面积
for
(
int
i
=
0
;
i
<
nccomps
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nccomps
;
i
++
)
{
colors
[
i
]
=
255
;
colors
[
i
]
=
255
;
double
dArea
=
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_AREA
];
double
dArea
=
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_AREA
];
if
(
!
(
dArea
>=
minArea
&&
dArea
<=
maxArea
))
{
if
(
!
(
dArea
>=
tpParams
.
minArea
&&
dArea
<=
tpParams
.
maxArea
))
{
colors
[
i
]
=
0
;
colors
[
i
]
=
0
;
}
}
}
}
...
@@ -1414,14 +1390,14 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
...
@@ -1414,14 +1390,14 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
}
}
//按圆度过滤
//按圆度过滤
if
(
filterByCircularity
)
{
if
(
tpParams
.
filterByCircularity
)
{
double
perimeter
=
cv
::
arcLength
(
contour
,
true
);
double
perimeter
=
cv
::
arcLength
(
contour
,
true
);
double
ratio
=
4
*
CV_PI
*
moms
.
m00
/
(
perimeter
*
perimeter
);
double
ratio
=
4
*
CV_PI
*
moms
.
m00
/
(
perimeter
*
perimeter
);
if
(
ratio
<
minCircularity
||
ratio
>=
maxCircularity
)
if
(
ratio
<
tpParams
.
minCircularity
||
ratio
>=
tpParams
.
maxCircularity
)
colors
[
label
]
=
0
;
colors
[
label
]
=
0
;
}
}
//按惯性率过滤
//按惯性率过滤
if
(
filterByInertia
)
{
if
(
tpParams
.
filterByInertia
)
{
double
denominator
=
std
::
sqrt
(
std
::
pow
(
2
*
moms
.
mu11
,
2
)
+
std
::
pow
(
moms
.
mu20
-
moms
.
mu02
,
2
));
double
denominator
=
std
::
sqrt
(
std
::
pow
(
2
*
moms
.
mu11
,
2
)
+
std
::
pow
(
moms
.
mu20
-
moms
.
mu02
,
2
));
const
double
eps
=
1e-2
;
const
double
eps
=
1e-2
;
double
ratio
;
double
ratio
;
...
@@ -1438,11 +1414,11 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
...
@@ -1438,11 +1414,11 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
else
{
else
{
ratio
=
1
;
ratio
=
1
;
}
}
if
(
ratio
<
minInertiaRatio
||
ratio
>=
maxInertiaRatio
)
if
(
ratio
<
tpParams
.
minInertiaRatio
||
ratio
>=
tpParams
.
maxInertiaRatio
)
colors
[
label
]
=
0
;
colors
[
label
]
=
0
;
}
}
//按凸度过滤
//按凸度过滤
if
(
filterByConvexity
)
{
if
(
tpParams
.
filterByConvexity
)
{
std
::
vector
<
cv
::
Point
>
hull
;
std
::
vector
<
cv
::
Point
>
hull
;
cv
::
convexHull
(
contour
,
hull
);
cv
::
convexHull
(
contour
,
hull
);
double
area
=
cv
::
contourArea
(
contour
);
double
area
=
cv
::
contourArea
(
contour
);
...
@@ -1450,7 +1426,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
...
@@ -1450,7 +1426,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
if
(
fabs
(
hullArea
)
<
DBL_EPSILON
)
if
(
fabs
(
hullArea
)
<
DBL_EPSILON
)
colors
[
label
]
=
0
;
colors
[
label
]
=
0
;
double
ratio
=
area
/
hullArea
;
double
ratio
=
area
/
hullArea
;
if
(
ratio
<
minConvexity
||
ratio
>=
maxConvexity
)
if
(
ratio
<
tpParams
.
minConvexity
||
ratio
>=
tpParams
.
maxConvexity
)
colors
[
label
]
=
0
;
colors
[
label
]
=
0
;
}
}
}
}
...
@@ -1485,8 +1461,8 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
...
@@ -1485,8 +1461,8 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob *
std
::
vector
<
EyemBinBlob
>
*
tpResults
=
new
std
::
vector
<
EyemBinBlob
>
();
std
::
vector
<
EyemBinBlob
>
*
tpResults
=
new
std
::
vector
<
EyemBinBlob
>
();
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
if
(
colors
[
i
])
{
if
(
colors
[
i
])
{
/*
cv::rectangle(showMat, cv::Rect(stats.ptr<int>(i)[cv::CC_STAT_LEFT], stats.ptr<int>(i)[cv::CC_STAT_TOP],
cv
::
rectangle
(
showMat
,
cv
::
Rect
(
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_LEFT
],
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_TOP
],
stats.ptr<int>(i)[cv::CC_STAT_WIDTH], stats.ptr<int>(i)[cv::CC_STAT_HEIGHT]), cv::Scalar(0, 0, 255));
*/
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_WIDTH
],
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_HEIGHT
]),
cv
::
Scalar
(
0
,
0
,
255
));
cv
::
drawMarker
(
showMat
,
cv
::
Point
((
int
)
centroids
.
ptr
<
double
>
(
i
)[
0
],
(
int
)
centroids
.
ptr
<
double
>
(
i
)[
1
]),
cv
::
Scalar
(
255
,
0
,
0
),
cv
::
MARKER_CROSS
,
6
);
cv
::
drawMarker
(
showMat
,
cv
::
Point
((
int
)
centroids
.
ptr
<
double
>
(
i
)[
0
],
(
int
)
centroids
.
ptr
<
double
>
(
i
)[
1
]),
cv
::
Scalar
(
255
,
0
,
0
),
cv
::
MARKER_CROSS
,
6
);
double
x1
,
y1
,
x2
,
y2
;
double
x1
,
y1
,
x2
,
y2
;
...
...
eyemLib/eyemLib.cpp
查看文件 @
e9d5142
...
@@ -26,147 +26,18 @@ void setSkipProcessID(int pid)
...
@@ -26,147 +26,18 @@ void setSkipProcessID(int pid)
killProcessID
=
pid
;
killProcessID
=
pid
;
}
}
//void strip_args(char *s)
//{
// size_t i;
// size_t len = strlen(s);
// size_t offset = 0;
// for (i = 0; i < len; ++i) {
// char c = s[i];
// if (c == '\t' || c == '\n' || c == '\r' || c == 0x0d || c == 0x0a) ++offset;
// else s[i - offset] = c;
// }
// s[len - offset] = '\0';
//}
//extern void run_tester(int argc, char **argv);
//extern void run_count_object(int argc, char **argv);
//extern void run_count_object_irregular(int argc, char **argv);
//extern void run_count_object_(int argc, char **argv);
//extern void run_count_object_irregular_(int argc, char **argv);
//extern void run_detect_decode(int argc, char **argv);
//extern void run_detect_decode_usenn(int argc, char **argv);
Logger
logger
;
Logger
logger
;
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
//cv::ocl::Context ctx = cv::ocl::Context::getDefault();
cv
::
ocl
::
Context
ctx
=
cv
::
ocl
::
Context
::
getDefault
();
//if (!ctx.ptr())
if
(
!
ctx
.
ptr
())
//{
{
// std::cout << "OpenCL is not available" << std::endl;
std
::
cout
<<
"OpenCL is not available"
<<
std
::
endl
;
//}
}
//else {
else
{
// std::cout << "OpenCL is available" << std::endl;
std
::
cout
<<
"OpenCL is available"
<<
std
::
endl
;
//}
}
std
::
cerr
<<
" OpenCV version: "
<<
CV_VERSION_MAJOR
<<
"."
<<
CV_VERSION_MINOR
<<
"."
<<
CVAUX_STR
(
CV_VERSION_REVISION
)
//std::cerr << " OpenCV version: " << CV_VERSION_MAJOR << "." << CV_VERSION_MINOR << "." << CVAUX_STR(CV_VERSION_REVISION)
<<
std
::
endl
;
// << std::endl;
//std::cerr << " EyemLib version: " << "4." << FILE_VER_GET_PREFETCHED << "." << FILE_VER_GET_NEUTRAL << "." << FILE_VER_GET_LOCALISED
// << std::endl;
//if (argc < 2) {
// fprintf(stderr, "usage: %s <function>\n", argv[0]);
// return 0;
//}
//int i;
//for (i = 0; i < argc; ++i) {
// if (!argv[i]) continue;
// strip_args(argv[i]);
//}
//if (0 == strcmp(argv[1], "func")) {
// run_tester(argc, argv);
//}
//else if (0 == strcmp(argv[1], "method")) {
//}
return
0
;
return
0
;
}
}
//void del_arg(int argc, char **argv, int index)
//{
// int i;
// for (i = index; i < argc - 1; ++i) argv[i] = argv[i + 1];
// argv[i] = 0;
//}
//
//int find_arg(int argc, char* argv[], char *arg)
//{
// int i;
// for (i = 0; i < argc; ++i) {
// if (!argv[i]) continue;
// if (0 == strcmp(argv[i], arg)) {
// del_arg(argc, argv, i);
// return 1;
// }
// }
// return 0;
//}
//void run_tester(int argc, char **argv)
//{
// char *func_name = argv[2];
// if (0 == strcmp(func_name, "count_object")) run_count_object(argc, argv);
// else if (0 == strcmp(func_name, "count_object_irregular")) run_count_object_irregular(argc, argv);
// else if (0 == strcmp(func_name, "count_object_")) run_count_object_(argc, argv);
// else if (0 == strcmp(func_name, "count_object_irregular_")) run_count_object_irregular_(argc, argv);
// else if (0 == strcmp(func_name, "detect_decode")) run_detect_decode(argc, argv);
// else if (0 == strcmp(func_name, "detect_decode_usenn")) run_detect_decode_usenn(argc, argv);
// else printf(" There isn't such command: %s", argv[2]);
//}
//
//void run_count_object(int argc, char **argv) {
// std::string filename(argv[2]);
// cv::Mat src = cv::imread(filename, -1);
// if (src.empty()) {
// printf("file does not exist");
// return;
// }
//}
//
//void run_count_object_irregular(int argc, char **argv) {
// std::string filename(argv[2]);
// cv::Mat src = cv::imread(filename, -1);
// if (src.empty()) {
// printf("file does not exist");
// return;
// }
//}
//
//void run_count_object_(int argc, char **argv) {
// std::string filename(argv[2]);
// cv::Mat src = cv::imread(filename, -1);
// if (src.empty()) {
// printf("file does not exist");
// return;
// }
//}
//
//void run_count_object_irregular_(int argc, char **argv) {
// std::string filename(argv[2]);
// cv::Mat src = cv::imread(filename, -1);
// if (src.empty()) {
// printf("file does not exist");
// return;
// }
//}
//
//void run_detect_decode(int argc, char **argv) {
// std::string filename(argv[2]);
// cv::Mat src = cv::imread(filename, -1);
// if (src.empty()) {
// printf("file does not exist");
// return;
// }
//}
//
//void run_detect_decode_usenn(int argc, char **argv) {
// std::string filename(argv[2]);
// cv::Mat src = cv::imread(filename, -1);
// if (src.empty()) {
// printf("file does not exist");
// return;
// }
//
}
\ No newline at end of file
\ No newline at end of file
eyemLib/eyemLib.h
查看文件 @
e9d5142
...
@@ -638,6 +638,17 @@ typedef struct {
...
@@ -638,6 +638,17 @@ typedef struct {
double
dVx
,
dVy
;
// 向量
double
dVx
,
dVy
;
// 向量
}
EyemChainCode
;
}
EyemChainCode
;
typedef
struct
{
bool
filterByArea
=
true
;
//斑点大小限制
int
minArea
=
25
,
maxArea
=
std
::
numeric_limits
<
int
>::
max
();
//最小面积/最大面积
bool
filterByCircularity
=
false
;
//斑点圆度限制
float
minCircularity
=
0
.
8
f
,
maxCircularity
=
std
::
numeric_limits
<
float
>::
max
();
//圆度最小/大限制
bool
filterByInertia
=
false
;
//斑点的惯性率限制
float
minInertiaRatio
=
0
.
1
f
,
maxInertiaRatio
=
std
::
numeric_limits
<
float
>::
max
();
//惯性率最小/大限制
bool
filterByConvexity
=
false
;
//斑点凸度限制
float
minConvexity
=
0
.
95
f
,
maxConvexity
=
std
::
numeric_limits
<
float
>::
max
();
//凸度最小/大限制
}
EyemBlobParams
;
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -653,7 +664,7 @@ extern "C" {
...
@@ -653,7 +664,7 @@ extern "C" {
EXPORTS
int
eyemBinErosion
(
EyemImage
tpSrcImg
,
int
iBinLevel
,
int
iNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinErosion
(
EyemImage
tpSrcImg
,
int
iBinLevel
,
int
iNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinOpening
(
EyemImage
tpSrcImg
,
int
iBinLevel
,
int
iNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinOpening
(
EyemImage
tpSrcImg
,
int
iBinLevel
,
int
iNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinClosing
(
EyemImage
tpSrcImg
,
int
iBinLevel
,
int
iNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinClosing
(
EyemImage
tpSrcImg
,
int
iBinLevel
,
int
iNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinBlob
(
EyemImage
tpImage
,
IntPtr
*
hObject
,
int
iAreaThr
s
,
EyemBinBlob
**
tpResult
,
int
*
ipNum
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemBinBlob
(
EyemImage
tpImage
,
IntPtr
*
hObject
,
EyemBlobParams
tpParam
s
,
EyemBinBlob
**
tpResult
,
int
*
ipNum
,
EyemImage
*
tpDstImg
);
EXPORTS
bool
eyemBinFree
(
IntPtr
hObject
);
EXPORTS
bool
eyemBinFree
(
IntPtr
hObject
);
#ifdef __cplusplus
#ifdef __cplusplus
...
@@ -911,7 +922,7 @@ extern "C" {
...
@@ -911,7 +922,7 @@ extern "C" {
EXPORTS
int
eyemAOIForTSAV
(
EyemImage
tpRefImg
,
EyemImage
tpNextImg
,
EyemRect3
*
tpRois
,
int
iRoiNum
);
EXPORTS
int
eyemAOIForTSAV
(
EyemImage
tpRefImg
,
EyemImage
tpNextImg
,
EyemRect3
*
tpRois
,
int
iRoiNum
);
EXPORTS
int
eyemMarkerTracing
(
EyemImage
tpImage
,
EyemHSVModel
tpHSVModel
,
EyemOcsFXYR
*
tpCircle
,
EyemImage
*
tpDstImg
,
bool
bHighAccuracy
=
false
);
EXPORTS
int
eyemMarkerTracing
(
EyemImage
tpImage
,
EyemHSVModel
tpHSVModel
,
EyemOcsFXYR
*
tpCircle
,
EyemImage
*
tpDstImg
,
bool
bHighAccuracy
=
false
);
EXPORTS
int
eyemMulFuncTool
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
funcName
,
double
dThreshold
,
int
iNumToIgnore
,
EyemOcsFXYR
*
tpCircle
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemMulFuncTool
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
funcName
,
double
dThreshold
,
int
iNumToIgnore
,
EyemOcsFXYR
*
tpCircle
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemLibImpl
(
EyemImage
tpImage
,
Eyem
HSVModel
tpHSVModel
,
Eyem
Image
*
tpDstImg
);
EXPORTS
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemDrawLine
(
EyemImage
tpImage
,
EyemOcsDABC
tpLine
);
EXPORTS
int
eyemDrawLine
(
EyemImage
tpImage
,
EyemOcsDABC
tpLine
);
EXPORTS
int
eyemDrawCircle
(
EyemImage
tpImage
,
EyemOcsDXYR
tpCircle
);
EXPORTS
int
eyemDrawCircle
(
EyemImage
tpImage
,
EyemOcsDXYR
tpCircle
);
EXPORTS
int
eyemDrawRectangle
(
EyemImage
tpImag
,
EyemRect
tpRect
);
EXPORTS
int
eyemDrawRectangle
(
EyemImage
tpImag
,
EyemRect
tpRect
);
...
...
eyemLib/eyemLib.rc
查看文件 @
e9d5142
此文件类型无法预览
eyemLib/eyemLib.vcxproj
查看文件 @
e9d5142
...
@@ -182,6 +182,7 @@
...
@@ -182,6 +182,7 @@
<ClInclude Include="eyemNNDetector.h" />
<ClInclude Include="eyemNNDetector.h" />
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="eyemCodeDetector.h" />
<ClInclude Include="eyemCodeDetector.h" />
<ClInclude Include="eyemStopwatch.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="yoloWrapper.h" />
<ClInclude Include="yoloWrapper.h" />
</ItemGroup>
</ItemGroup>
...
@@ -206,6 +207,7 @@
...
@@ -206,6 +207,7 @@
<ClCompile Include="eyemNNDetector.cpp" />
<ClCompile Include="eyemNNDetector.cpp" />
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="eyemCodeDetector.cpp" />
<ClCompile Include="eyemCodeDetector.cpp" />
<ClCompile Include="eyemStopwatch.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
</ItemGroup>
</ItemGroup>
...
...
eyemLib/eyemLib.vcxproj.filters
查看文件 @
e9d5142
...
@@ -72,6 +72,9 @@
...
@@ -72,6 +72,9 @@
<ClInclude Include="eyemMatchShapes.h">
<ClInclude Include="eyemMatchShapes.h">
<Filter>源文件</Filter>
<Filter>源文件</Filter>
</ClInclude>
</ClInclude>
<ClInclude Include="eyemStopwatch.h">
<Filter>源文件</Filter>
</ClInclude>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClCompile Include="eyemLib.cpp">
<ClCompile Include="eyemLib.cpp">
...
@@ -140,6 +143,9 @@
...
@@ -140,6 +143,9 @@
<ClCompile Include="eyemMatchShapes.cpp">
<ClCompile Include="eyemMatchShapes.cpp">
<Filter>源文件</Filter>
<Filter>源文件</Filter>
</ClCompile>
</ClCompile>
<ClCompile Include="eyemStopwatch.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ResourceCompile Include="eyemLib.rc">
<ResourceCompile Include="eyemLib.rc">
...
...
eyemLib/eyemMisc.cpp
查看文件 @
e9d5142
...
@@ -2000,7 +2000,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -2000,7 +2000,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
cv
::
Rect
rec
=
cv
::
Rect
(
forfilter
[
i
].
x
-
25
,
forfilter
[
i
].
y
-
25
,
50
,
50
)
&
cv
::
Rect
(
0
,
0
,
X
,
Y
);
cv
::
Rect
rec
=
cv
::
Rect
(
forfilter
[
i
].
x
-
25
,
forfilter
[
i
].
y
-
25
,
50
,
50
)
&
cv
::
Rect
(
0
,
0
,
X
,
Y
);
cv
::
Mat
filter
=
testmat
(
rec
);
cv
::
Mat
filter
=
testmat
(
rec
);
cv
::
Mat
mask
=
binary
(
rec
);
cv
::
Mat
mask
=
binary
(
rec
);
if
(
!
(
testmat
.
ptr
<
uint8_t
>
(
forfilter
[
i
].
y
)[
forfilter
[
i
].
x
]
>
cv
::
mean
(
filter
,
mask
)[
0
]
+
45
))
{
if
(
!
(
testmat
.
ptr
<
uint8_t
>
(
forfilter
[
i
].
y
)[
forfilter
[
i
].
x
]
>
cv
::
mean
(
filter
,
mask
)[
0
]
+
16
))
{
filtermap
.
at
<
uchar
>
(
forfilter
[
i
])
=
255
;
filtermap
.
at
<
uchar
>
(
forfilter
[
i
])
=
255
;
cv
::
circle
(
cc
,
forfilter
[
i
],
1
,
cv
::
Scalar
(
0
,
255
,
0
,
255
),
1
);
cv
::
circle
(
cc
,
forfilter
[
i
],
1
,
cv
::
Scalar
(
0
,
255
,
0
,
255
),
1
);
}
}
...
@@ -4477,6 +4477,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -4477,6 +4477,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
{
{
//面积过滤
//面积过滤
if
(
stats
.
ptr
<
int
>
(
j
)[
cv
::
CC_STAT_AREA
]
>
2
)
{
if
(
stats
.
ptr
<
int
>
(
j
)[
cv
::
CC_STAT_AREA
]
>
2
)
{
cv
::
circle
(
cc
,
cv
::
Point
(
cvRound
((
float
)
dpCent
[(
0
)
+
(
j
)
*
2
]),
cvRound
((
float
)
dpCent
[(
1
)
+
(
j
)
*
2
])),
1
,
cv
::
Scalar
(
0
,
255
,
0
));
binary
.
at
<
uchar
>
(
cv
::
Point
(
cvRound
((
float
)
dpCent
[(
0
)
+
(
j
)
*
2
]),
cvRound
((
float
)
dpCent
[(
1
)
+
(
j
)
*
2
])))
=
255
;
binary
.
at
<
uchar
>
(
cv
::
Point
(
cvRound
((
float
)
dpCent
[(
0
)
+
(
j
)
*
2
]),
cvRound
((
float
)
dpCent
[(
1
)
+
(
j
)
*
2
])))
=
255
;
}
}
}
}
...
@@ -4741,9 +4742,9 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
...
@@ -4741,9 +4742,9 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
image
-=
srcPrevEx
;
image
-=
srcPrevEx
;
//获取最大轮廓
//获取最大轮廓
cv
::
findContours
(
image
,
contoursFilter
,
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_NONE
);
cv
::
findContours
(
image
,
contoursFilter
,
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_NONE
);
if
(
contoursFilter
.
size
()
<=
0
)
if
(
contoursFilter
.
size
()
<=
0
)
{
{
//极有可能是不满足一圈的料//2021/09/26修改
c
ontinue
;
c
v
::
findContours
(
srcPrevEx
,
contoursFilter
,
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_NONE
)
;
}
}
std
::
vector
<
cv
::
Point
>
contourMax
=
contoursFilter
[
0
];
std
::
vector
<
cv
::
Point
>
contourMax
=
contoursFilter
[
0
];
for
(
int
i
=
1
;
i
<
contoursFilter
.
size
();
i
++
)
for
(
int
i
=
1
;
i
<
contoursFilter
.
size
();
i
++
)
...
@@ -4755,7 +4756,6 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
...
@@ -4755,7 +4756,6 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
}
}
cv
::
Moments
mu
=
cv
::
moments
(
contourMax
);
cv
::
Moments
mu
=
cv
::
moments
(
contourMax
);
cv
::
Point2f
reelCenter
(
float
(
mu
.
m10
/
mu
.
m00
),
float
(
mu
.
m01
/
mu
.
m00
));
cv
::
Point2f
reelCenter
(
float
(
mu
.
m10
/
mu
.
m00
),
float
(
mu
.
m01
/
mu
.
m00
));
//画中心
//计算最大外接圆半径
//计算最大外接圆半径
float
tFRadius
=
0
;
float
tFRadius
=
0
;
cv
::
minEnclosingCircle
(
contourMax
,
cv
::
Point2f
(),
tFRadius
);
cv
::
minEnclosingCircle
(
contourMax
,
cv
::
Point2f
(),
tFRadius
);
...
@@ -4764,6 +4764,23 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
...
@@ -4764,6 +4764,23 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
cv
::
drawMarker
(
cc
,
reelCenter
,
cv
::
Scalar
(
0
,
0
,
238
,
255
),
1
,
35
,
2
);
cv
::
drawMarker
(
cc
,
reelCenter
,
cv
::
Scalar
(
0
,
0
,
238
,
255
),
1
,
35
,
2
);
//去掉中心1/3区域
//去掉中心1/3区域
cv
::
circle
(
sinPartMask
,
reelCenter
,
cvRound
(
tFRadius
/
2
),
cv
::
Scalar
(
0
),
-
1
);
cv
::
circle
(
sinPartMask
,
reelCenter
,
cvRound
(
tFRadius
/
2
),
cv
::
Scalar
(
0
),
-
1
);
//20210926新增测试用
cv
::
Mat
llbabels
;
int
totalSize
=
cv
::
connectedComponents
(
sinPartMask
,
llbabels
);
//判断为仅剩几圈的料
if
(
totalSize
<
265
)
{
cv
::
Mat
srcPrevEEx
;
cv
::
morphologyEx
(
srcPrev
,
srcPrevEEx
,
cv
::
MORPH_TOPHAT
,
cv
::
getStructuringElement
(
cv
::
MORPH_RECT
,
cv
::
Size
(
3
,
3
)));
//非极大值抑制
cv
::
Mat
mask
;
cv
::
threshold
(
srcPrevEEx
,
mask
,
0
,
255
,
cv
::
THRESH_BINARY
|
cv
::
THRESH_OTSU
);
//去掉分数过低的
double
mmval
=
cv
::
mean
(
srcPrevEEx
,
mask
)[
0
];
mask
&=
cv
::
Mat
(
srcPrevEEx
>
mmval
*
0.75
);
//
sinPartSize
=
10
;
sinPartMask
=
mask
.
clone
();
}
//掩膜区域,用于区分处理区域
//掩膜区域,用于区分处理区域
uchar
*
upMask
=
sinPartMask
.
data
;
uchar
*
upMask
=
sinPartMask
.
data
;
//最小料不进行粘连判断
//最小料不进行粘连判断
...
@@ -4927,6 +4944,19 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
...
@@ -4927,6 +4944,19 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
contourMax
=
contoursFilter
[
i
];
contourMax
=
contoursFilter
[
i
];
}
}
}
}
//20210927测试用
//如果最大轮廓面积小于100000判断中间料盘影响到了定位
if
(
cv
::
contourArea
(
contourMax
)
<
85000
)
{
cv
::
findContours
(
srcPrevEx0
,
contoursFilter
,
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_NONE
);
contourMax
=
contoursFilter
[
0
];
for
(
int
i
=
1
;
i
<
contoursFilter
.
size
();
i
++
)
{
if
(
cv
::
contourArea
(
contoursFilter
[
i
])
>
cv
::
contourArea
(
contourMax
))
{
contourMax
=
contoursFilter
[
i
];
}
}
}
//计算最大外接圆半径
//计算最大外接圆半径
float
tFRadius
=
0
;
float
tFRadius
=
0
;
cv
::
minEnclosingCircle
(
contourMax
,
cv
::
Point2f
(),
tFRadius
);
cv
::
minEnclosingCircle
(
contourMax
,
cv
::
Point2f
(),
tFRadius
);
...
@@ -5901,7 +5931,6 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
...
@@ -5901,7 +5931,6 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
//输出结果
//输出结果
const
int
SizeConst
=
4
;
const
int
SizeConst
=
4
;
//<输出计数结果标记图像
//<输出计数结果标记图像
{
for
(
int
i
=
0
;
i
<
SizeConst
;
i
++
)
{
for
(
int
i
=
0
;
i
<
SizeConst
;
i
++
)
{
ipReelNum
[
i
]
=
trayNum
[
i
];
ipReelNum
[
i
]
=
trayNum
[
i
];
}
}
...
@@ -5916,10 +5945,8 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
...
@@ -5916,10 +5945,8 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
if
(
NULL
==
tpDstImg
->
vpImage
)
if
(
NULL
==
tpDstImg
->
vpImage
)
return
FUNC_NOT_ENOUGH_MEM
;
return
FUNC_NOT_ENOUGH_MEM
;
memset
(
tpDstImg
->
vpImage
,
0
,
_Size
);
memset
(
tpDstImg
->
vpImage
,
0
,
_Size
);
//拷贝数据
//拷贝数据
memcpy
(
tpDstImg
->
vpImage
,
cc
.
data
,
_Size
);
memcpy
(
tpDstImg
->
vpImage
,
cc
.
data
,
_Size
);
}
return
FUNC_OK
;
return
FUNC_OK
;
}
}
...
@@ -5931,15 +5958,12 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -5931,15 +5958,12 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char
if
(
src
.
empty
()
||
NULL
==
hModelID
)
{
if
(
src
.
empty
()
||
NULL
==
hModelID
)
{
return
FUNC_IMAGE_NOT_EXIST
;
return
FUNC_IMAGE_NOT_EXIST
;
}
}
//跳过执行
//跳过执行
if
(
killProcessID
==
0
)
{
if
(
killProcessID
==
0
)
{
logger
.
t
(
"eyemCountObjectIrregularPartsE 初始阶段被跳过执行..."
);
logger
.
t
(
"eyemCountObjectIrregularPartsE 初始阶段被跳过执行..."
);
return
FUNC_CANNOT_CALC
;
return
FUNC_CANNOT_CALC
;
}
}
double
begin0
=
(
double
)
cv
::
getTickCount
();
double
begin0
=
(
double
)
cv
::
getTickCount
();
//转单通道图像
//转单通道图像
if
(
src
.
channels
()
!=
1
)
if
(
src
.
channels
()
!=
1
)
cv
::
cvtColor
(
src
,
src
,
cv
::
COLOR_BGR2GRAY
);
cv
::
cvtColor
(
src
,
src
,
cv
::
COLOR_BGR2GRAY
);
...
@@ -7941,7 +7965,8 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
...
@@ -7941,7 +7965,8 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
return
FUNC_OK
;
return
FUNC_OK
;
}
}
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemHSVModel
tpHSVModel
,
EyemImage
*
tpDstImg
)
#include "eyemStopwatch.h"
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemImage
*
tpDstImg
)
{
{
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
...
@@ -7950,11 +7975,14 @@ int eyemLibImpl(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg)
...
@@ -7950,11 +7975,14 @@ int eyemLibImpl(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg)
if
(
image
.
empty
())
if
(
image
.
empty
())
return
FUNC_IMAGE_NOT_EXIST
;
return
FUNC_IMAGE_NOT_EXIST
;
//多个分割阈值
#pragma region clock test
if
((
tpHSVModel
.
dpRangeLExt
[
0
]
+
tpHSVModel
.
dpRangeLExt
[
1
]
+
tpHSVModel
.
dpRangeLExt
[
2
])
!=
0
||
//Stopwatch sw;
(
tpHSVModel
.
dpRangeUExt
[
0
]
+
tpHSVModel
.
dpRangeUExt
[
1
]
+
tpHSVModel
.
dpRangeUExt
[
2
])
!=
0
)
{
//sw.Start();
std
::
cout
<<
"红色"
<<
std
::
endl
;
//cv::bitwise_not(image, image);
}
//sw.Stop();
//std::cout << "时间花费:" << sw.ElapsedMilliseconds() << std::endl;
#pragma endregion
#pragma region resize img
#pragma region resize img
//const int minInputSize = 832;
//const int minInputSize = 832;
...
...
eyemLib/eyemStopwatch.cpp
0 → 100644
查看文件 @
e9d5142
#include "eyemStopwatch.h"
Stopwatch
::
Stopwatch
()
{};
Stopwatch
::
~
Stopwatch
()
{};
void
Stopwatch
::
Start
()
{
begin0
=
static_cast
<
double
>
(
cv
::
getTickCount
());
}
void
Stopwatch
::
Stop
()
{
end1
=
static_cast
<
double
>
(
cv
::
getTickCount
());
}
void
Stopwatch
::
Reset
()
{
begin0
=
end1
=
0.0
;
}
void
Stopwatch
::
Restart
()
{
begin0
=
static_cast
<
double
>
(
cv
::
getTickCount
());
}
\ No newline at end of file
\ No newline at end of file
eyemLib/eyemStopwatch.h
0 → 100644
查看文件 @
e9d5142
#pragma once
//
// eyemStopwatchͷ
//
#ifndef __EYEMSTOPWATCH_H
#define __EYEMSTOPWATCH_H
#include "eyemLib.h"
class
Stopwatch
{
public
:
Stopwatch
();
~
Stopwatch
();
void
Start
();
void
Stop
();
void
Reset
();
void
Restart
();
double
ElapsedMilliseconds
()
{
return
1000
.
0
*
(
end1
-
begin0
)
/
cv
::
getTickFrequency
();
}
private
:
double
begin0
=
0
.
0
,
end1
=
0
.
0
;
};
#endif
/* __EYEMSTOPWATCH_H */
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论