Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 547390fb
由
张士柳
编写于
2021-08-27 17:33:59 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
ae41cb88
全部展开
显示空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
673 行增加
和
77 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/EyemLibDemo.cs
eyemLib-Sharp/Program.cs
eyemLib/eyemBin.h
eyemLib/eyemClp2d.cpp
eyemLib/eyemEdge1d.cpp
eyemLib/eyemEdge1d.h
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemLib.vcxproj
eyemLib/eyemLib.vcxproj.filters
eyemLib/eyemMat.cpp
eyemLib/eyemMisc.cpp
eyemLib/eyemMisc.h
eyemLib/stegers.cpp
eyemLib/stegers.h
eyemLib-Sharp/EyemLib.cs
查看文件 @
547390f
此文件的差异被折叠,
点击展开。
eyemLib-Sharp/EyemLibDemo.cs
查看文件 @
547390f
...
@@ -497,6 +497,5 @@ namespace eyemLib_Sharp
...
@@ -497,6 +497,5 @@ namespace eyemLib_Sharp
return
tpImage
;
return
tpImage
;
}
}
#
endregion
#
endregion
}
}
}
}
eyemLib-Sharp/Program.cs
查看文件 @
547390f
...
@@ -24,7 +24,6 @@ namespace eyemLib_Sharp
...
@@ -24,7 +24,6 @@ namespace eyemLib_Sharp
{
{
EyemLib
.
eyemReadImageTool
(
item
);
EyemLib
.
eyemReadImageTool
(
item
);
}
}
EyemLib
.
Free
();
EyemLib
.
Free
();
Console
.
Write
(
"请按任意键继续。。。"
);
Console
.
Write
(
"请按任意键继续。。。"
);
Console
.
ReadKey
();
Console
.
ReadKey
();
...
...
eyemLib/eyemBin.h
查看文件 @
547390f
...
@@ -8,44 +8,4 @@
...
@@ -8,44 +8,4 @@
#include "eyemLib.h"
#include "eyemLib.h"
typedef
unsigned
int
CvLabel
;
typedef
std
::
map
<
CvLabel
,
cv
::
Scalar
>
Palete
;
/// \def _HSV2RGB_(H, S, V, R, G, B)
/// \brief Color translation between HSV and RGB.
#define _HSV2RGB_(H, S, V, R, G, B) \
{ \
double _h = H/60.; \
int _hf = (int)floor(_h); \
int _hi = ((int)_h)%6; \
double _f = _h - _hf; \
\
double _p = V * (1. - S); \
double _q = V * (1. - _f * S); \
double _t = V * (1. - (1. - _f) * S); \
\
switch (_hi) \
{ \
case 0: \
R = 255.*V; G = 255.*_t; B = 255.*_p; \
break; \
case 1: \
R = 255.*_q; G = 255.*V; B = 255.*_p; \
break; \
case 2: \
R = 255.*_p; G = 255.*V; B = 255.*_t; \
break; \
case 3: \
R = 255.*_p; G = 255.*_q; B = 255.*V; \
break; \
case 4: \
R = 255.*_t; G = 255.*_p; B = 255.*V; \
break; \
case 5: \
R = 255.*V; G = 255.*_p; B = 255.*_q; \
break; \
} \
}
#endif
/* __EYEM_BIN_H */
#endif
/* __EYEM_BIN_H */
\ No newline at end of file
\ No newline at end of file
eyemLib/eyemClp2d.cpp
查看文件 @
547390f
...
@@ -54,26 +54,12 @@ void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &
...
@@ -54,26 +54,12 @@ void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &
int
eyemClp2dIntersectionTwoLines
(
EyemOcsDABC
tpLine1
,
EyemOcsDABC
tpLine2
,
EyemOcsDXY
&
tpPoint
)
int
eyemClp2dIntersectionTwoLines
(
EyemOcsDABC
tpLine1
,
EyemOcsDABC
tpLine2
,
EyemOcsDXY
&
tpPoint
)
{
{
if
(
abs
(
tpLine1
.
dA
*
tpLine2
.
dB
-
tpLine2
.
dA
*
tpLine1
.
dB
)
<
EPS
)
{
double
det
=
tpLine1
.
dA
*
tpLine2
.
dB
-
tpLine2
.
dA
*
tpLine1
.
dB
;
if
(
abs
(
det
)
<
EPS
)
{
return
FUNC_CANNOT_CALC
;
return
FUNC_CANNOT_CALC
;
}
}
//计算系数
tpPoint
.
dX
=
(
tpLine1
.
dB
*
tpLine2
.
dC
-
tpLine2
.
dB
*
tpLine1
.
dC
)
/
det
;
double
sa
[
4
],
sb
[
2
],
sx
[
2
];
tpPoint
.
dY
=
(
tpLine2
.
dA
*
tpLine1
.
dC
-
tpLine1
.
dA
*
tpLine2
.
dC
)
/
det
;
cv
::
Mat
a
=
cv
::
Mat
(
2
,
2
,
CV_64F
,
sa
),
b
=
cv
::
Mat
(
2
,
1
,
CV_64F
,
sb
);
//系数矩阵A*X=B;
cv
::
Mat
x
=
cv
::
Mat
(
2
,
1
,
CV_64F
,
sx
);
std
::
memset
(
sa
,
0
,
sizeof
(
sa
));
std
::
memset
(
sb
,
0
,
sizeof
(
sb
));
std
::
memset
(
sx
,
0
,
sizeof
(
sx
));
sa
[
0
]
=
tpLine1
.
dA
,
sa
[
1
]
=
tpLine1
.
dB
;
sa
[
2
]
=
tpLine2
.
dA
,
sa
[
3
]
=
tpLine2
.
dB
;
sb
[
0
]
=
-
tpLine1
.
dC
,
sb
[
1
]
=
-
tpLine2
.
dC
;
//solve
cv
::
solve
(
a
,
b
,
x
,
cv
::
DECOMP_SVD
);
tpPoint
.
dX
=
sx
[
0
];
tpPoint
.
dY
=
sx
[
1
];
return
FUNC_OK
;
return
FUNC_OK
;
}
}
...
...
eyemLib/eyemEdge1d.cpp
查看文件 @
547390f
此文件的差异被折叠,
点击展开。
eyemLib/eyemEdge1d.h
查看文件 @
547390f
此文件的差异被折叠,
点击展开。
eyemLib/eyemLib.h
查看文件 @
547390f
...
@@ -102,6 +102,46 @@
...
@@ -102,6 +102,46 @@
typedef
intptr_t
IntPtr
;
typedef
intptr_t
IntPtr
;
#endif
#endif
typedef
unsigned
int
CvLabel
;
typedef
std
::
map
<
CvLabel
,
cv
::
Scalar
>
Palete
;
/// \def _HSV2RGB_(H, S, V, R, G, B)
/// \brief Color translation between HSV and RGB.
#define _HSV2RGB_(H, S, V, R, G, B) \
{ \
double _h = H/60.; \
int _hf = (int)floor(_h); \
int _hi = ((int)_h)%6; \
double _f = _h - _hf; \
\
double _p = V * (1. - S); \
double _q = V * (1. - _f * S); \
double _t = V * (1. - (1. - _f) * S); \
\
switch (_hi) \
{ \
case 0: \
R = 255.*V; G = 255.*_t; B = 255.*_p; \
break; \
case 1: \
R = 255.*_q; G = 255.*V; B = 255.*_p; \
break; \
case 2: \
R = 255.*_p; G = 255.*V; B = 255.*_t; \
break; \
case 3: \
R = 255.*_p; G = 255.*_q; B = 255.*V; \
break; \
case 4: \
R = 255.*_t; G = 255.*_p; B = 255.*V; \
break; \
case 5: \
R = 255.*V; G = 255.*_p; B = 255.*_q; \
break; \
} \
}
// 图像边界处理
// 图像边界处理
#ifndef __EYEM_BORDER
#ifndef __EYEM_BORDER
...
@@ -149,6 +189,14 @@ typedef struct {
...
@@ -149,6 +189,14 @@ typedef struct {
double
dVar
;
// 可能会使用的值
double
dVar
;
// 可能会使用的值
}
EyemRect3
;
}
EyemRect3
;
// 旋转矩形定义
typedef
struct
{
double
dWidth
;
// 旋转矩形宽度
double
dHeight
;
// 旋转矩形高度
double
dAngle
;
// 旋转矩形角度(-90==>90)
EyemOcsDXY
tC
;
// 旋转矩形中心
}
EyemRotateRect
;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System
// Orthogonal Coordinate System
...
@@ -621,6 +669,7 @@ extern "C" {
...
@@ -621,6 +669,7 @@ extern "C" {
EXPORTS
int
eyemEdge1dGenPosRect
(
EyemImage
tpImage
,
EyemOcsDXY
tpLineSt
,
EyemOcsDXY
tpLineEd
,
int
iWhRoi
,
int
iTransition
,
double
dSigma
,
double
dAmpThresh
,
IntPtr
*
hObject
);
EXPORTS
int
eyemEdge1dGenPosRect
(
EyemImage
tpImage
,
EyemOcsDXY
tpLineSt
,
EyemOcsDXY
tpLineEd
,
int
iWhRoi
,
int
iTransition
,
double
dSigma
,
double
dAmpThresh
,
IntPtr
*
hObject
);
EXPORTS
int
eyemEdge1dFindCircle
(
EyemImage
tpImage
,
EyemOcsDXY
tpPoint
,
int
iRadius
,
int
iCapLength
,
int
iCapWidth
,
int
nCalipers
,
int
nFilterSize
,
int
iSearchDirec
,
double
dAmpThreshold
,
const
char
*
ccTransition
,
IntPtr
*
hObject
);
EXPORTS
int
eyemEdge1dFindCircle
(
EyemImage
tpImage
,
EyemOcsDXY
tpPoint
,
int
iRadius
,
int
iCapLength
,
int
iCapWidth
,
int
nCalipers
,
int
nFilterSize
,
int
iSearchDirec
,
double
dAmpThreshold
,
const
char
*
ccTransition
,
IntPtr
*
hObject
);
EXPORTS
int
eyemEdge1dFindLine
(
EyemImage
tpImage
,
EyemOcsDXY
tpLineSt
,
EyemOcsDXY
tpLineEd
,
int
iCapLength
,
int
iCapWidth
,
int
nCalipers
,
int
iFilterSize
,
int
iSearchDirec
,
double
dAmpThreshold
,
const
char
*
ccTransition
,
IntPtr
*
hObject
);
EXPORTS
int
eyemEdge1dFindLine
(
EyemImage
tpImage
,
EyemOcsDXY
tpLineSt
,
EyemOcsDXY
tpLineEd
,
int
iCapLength
,
int
iCapWidth
,
int
nCalipers
,
int
iFilterSize
,
int
iSearchDirec
,
double
dAmpThreshold
,
const
char
*
ccTransition
,
IntPtr
*
hObject
);
EXPORTS
int
eyemEdge1dRidgeDetection
(
EyemImage
tpImage
);
EXPORTS
bool
eyemEdge1dGenMeasureFree
(
IntPtr
hObject
);
EXPORTS
bool
eyemEdge1dGenMeasureFree
(
IntPtr
hObject
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
eyemLib/eyemLib.rc
查看文件 @
547390f
此文件类型无法预览
eyemLib/eyemLib.vcxproj
查看文件 @
547390f
...
@@ -182,6 +182,7 @@
...
@@ -182,6 +182,7 @@
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="eyemCodeDetector.h" />
<ClInclude Include="eyemCodeDetector.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stegers.h" />
<ClInclude Include="yoloWrapper.h" />
<ClInclude Include="yoloWrapper.h" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
@@ -205,6 +206,7 @@
...
@@ -205,6 +206,7 @@
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="eyemCodeDetector.cpp" />
<ClCompile Include="eyemCodeDetector.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="stegers.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
eyemLib/eyemLib.vcxproj.filters
查看文件 @
547390f
...
@@ -69,6 +69,9 @@
...
@@ -69,6 +69,9 @@
<ClInclude Include="eyemNNDetector.h">
<ClInclude Include="eyemNNDetector.h">
<Filter>源文件</Filter>
<Filter>源文件</Filter>
</ClInclude>
</ClInclude>
<ClInclude Include="stegers.h">
<Filter>源文件</Filter>
</ClInclude>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClCompile Include="eyemLib.cpp">
<ClCompile Include="eyemLib.cpp">
...
@@ -134,6 +137,9 @@
...
@@ -134,6 +137,9 @@
<ClCompile Include="eyemNNDetector.cpp">
<ClCompile Include="eyemNNDetector.cpp">
<Filter>源文件</Filter>
<Filter>源文件</Filter>
</ClCompile>
</ClCompile>
<ClCompile Include="stegers.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ResourceCompile Include="eyemLib.rc">
<ResourceCompile Include="eyemLib.rc">
...
...
eyemLib/eyemMat.cpp
查看文件 @
547390f
...
@@ -617,6 +617,16 @@ int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG,
...
@@ -617,6 +617,16 @@ int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG,
return
FUNC_OK
;
return
FUNC_OK
;
}
}
int
eyemCopyRegion
(
EyemImage
tpImage
,
EyemRotateRect
tpRoi
,
EyemImage
*
tpDstImg
)
{
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
cv
::
Mat
image
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
return
FUNC_OK
;
}
int
eyemNormalize
(
EyemImage
&
tpImage
)
int
eyemNormalize
(
EyemImage
&
tpImage
)
{
{
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
...
...
eyemLib/eyemMisc.cpp
查看文件 @
547390f
...
@@ -1887,6 +1887,10 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -1887,6 +1887,10 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
contourAll
.
resize
(
0
);
contourAll
.
resize
(
0
);
findContours
(
image
,
contourAll
,
cv
::
noArray
(),
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_SIMPLE
);
findContours
(
image
,
contourAll
,
cv
::
noArray
(),
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_SIMPLE
);
if
(
contourAll
.
empty
())
{
return
FUNC_CANNOT_CALC
;
}
//寻找最大轮廓
//寻找最大轮廓
contourMax
=
contourAll
[
0
];
contourMaxArea
=
cv
::
contourArea
(
contourMax
);
contourMax
=
contourAll
[
0
];
contourMaxArea
=
cv
::
contourArea
(
contourMax
);
for
(
int
i
=
1
;
i
<
contourAll
.
size
();
i
++
)
for
(
int
i
=
1
;
i
<
contourAll
.
size
();
i
++
)
...
@@ -2105,6 +2109,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -2105,6 +2109,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
cv
::
drawContours
(
image
,
contoursFilter
,
i
,
cv
::
Scalar
(
255
),
-
1
);
cv
::
drawContours
(
image
,
contoursFilter
,
i
,
cv
::
Scalar
(
255
),
-
1
);
}
}
image
-=
srcPrevEx0
;
image
-=
srcPrevEx0
;
//2021/08/26增加测试用
cv
::
morphologyEx
(
image
,
image
,
cv
::
MORPH_CLOSE
,
cv
::
getStructuringElement
(
cv
::
MORPH_RECT
,
cv
::
Size
(
45
,
45
)));
//获取最大轮廓
//获取最大轮廓
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
)
...
@@ -2487,6 +2494,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -2487,6 +2494,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
if
(
coeff
>
1.0
f
)
{
if
(
coeff
>
1.0
f
)
{
cv
::
resize
(
_tplMat
,
_tplMat
,
cv
::
Size
(),
coeff
,
coeff
);
cv
::
resize
(
_tplMat
,
_tplMat
,
cv
::
Size
(),
coeff
,
coeff
);
}
}
if
(
_tplMat
.
cols
>
_traceMat
.
cols
||
_tplMat
.
rows
>
_traceMat
.
rows
)
{
return
FUNC_CANNOT_CALC
;
}
//考虑并行计算两个模板结果
//考虑并行计算两个模板结果
cv
::
Mat
tplResult0
;
cv
::
Mat
tplResult0
;
cv
::
matchTemplate
(
_traceMat
,
_tplMat
,
tplResult0
,
cv
::
TM_SQDIFF_NORMED
);
cv
::
matchTemplate
(
_traceMat
,
_tplMat
,
tplResult0
,
cv
::
TM_SQDIFF_NORMED
);
...
@@ -2826,6 +2836,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -2826,6 +2836,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
if
(
coeff
>
1.0
f
)
{
if
(
coeff
>
1.0
f
)
{
cv
::
resize
(
_tplMat
,
_tplMat
,
cv
::
Size
(),
coeff
,
coeff
);
cv
::
resize
(
_tplMat
,
_tplMat
,
cv
::
Size
(),
coeff
,
coeff
);
}
}
if
(
_tplMat
.
cols
>
_traceMat
.
cols
||
_tplMat
.
rows
>
_traceMat
.
rows
)
{
return
FUNC_CANNOT_CALC
;
}
//考虑并行计算两个模板结果
//考虑并行计算两个模板结果
cv
::
Mat
tplResult0
;
cv
::
Mat
tplResult0
;
cv
::
matchTemplate
(
_traceMat
,
_tplMat
,
tplResult0
,
cv
::
TM_SQDIFF_NORMED
);
cv
::
matchTemplate
(
_traceMat
,
_tplMat
,
tplResult0
,
cv
::
TM_SQDIFF_NORMED
);
...
@@ -3185,6 +3198,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -3185,6 +3198,9 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
cv
::
drawContours
(
image
,
contoursFilter
,
i
,
cv
::
Scalar
(
255
),
-
1
);
cv
::
drawContours
(
image
,
contoursFilter
,
i
,
cv
::
Scalar
(
255
),
-
1
);
}
}
image
-=
srcPrevEx0
;
image
-=
srcPrevEx0
;
//2021/08/26增加测试用
cv
::
morphologyEx
(
image
,
image
,
cv
::
MORPH_CLOSE
,
cv
::
getStructuringElement
(
cv
::
MORPH_RECT
,
cv
::
Size
(
45
,
45
)));
//获取最大轮廓
//获取最大轮廓
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
)
...
@@ -4108,7 +4124,153 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -4108,7 +4124,153 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
else
if
(
strcmp
(
ccSubType
,
"IP_SQUARE_PARTS"
)
==
0
)
else
if
(
strcmp
(
ccSubType
,
"IP_SQUARE_PARTS"
)
==
0
)
{
{
//TODO:
//TODO:
//二值化
cv
::
threshold
(
srcPrev
,
binary
,
0
,
255
,
cv
::
THRESH_BINARY
|
cv
::
THRESH_OTSU
);
cv
::
morphologyEx
(
binary
,
binary
,
cv
::
MORPH_CLOSE
,
cv
::
getStructuringElement
(
cv
::
MORPH_RECT
,
cv
::
Size
(
75
,
75
)));
//计算直方图
int
hist_
[
256
];
for
(
int
y
=
0
;
y
<
256
;
y
++
)
hist_
[
y
]
=
0
;
for
(
int
y
=
0
;
y
<
Y
;
y
++
)
{
uchar
*
uPtr
=
srcPrev
.
data
+
y
*
X
;
for
(
int
x
=
0
;
x
<
srcPrev
.
cols
;
x
++
,
uPtr
++
)
{
if
(
binary
.
ptr
<
uint8_t
>
(
y
)[
x
]
==
255
)
{
hist_
[
*
uPtr
]
++
;
}
}
}
cv
::
threshold
(
srcPrev
,
binary
,
Otsu
(
hist_
),
255
,
cv
::
THRESH_BINARY
);
//计算元件大小
cv
::
Mat
m1
,
m2
,
m3
;
int
nccomps
=
cv
::
connectedComponentsWithStats
(
binary
,
m1
,
m2
,
m3
);
std
::
vector
<
uchar
>
colors0
(
nccomps
+
1
,
0
);
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
colors0
[
i
]
=
255
;
if
((((
int
*
)
m2
.
data
)[(
cv
::
CC_STAT_AREA
)
+
(
i
)
*
m2
.
cols
]
<=
2
))
//经验值
{
colors0
[
i
]
=
0
;
}
}
//认为是干扰
cv
::
parallel_for_
(
cv
::
Range
(
0
,
Y
),
[
&
](
const
cv
::
Range
&
range
)
->
void
{
for
(
int
y
=
range
.
start
;
y
<
range
.
end
;
y
++
)
{
for
(
int
x
=
0
;
x
<
X
;
x
++
)
{
int
label
=
((
int
*
)
m1
.
data
)[(
x
)
+
(
y
)
*
m1
.
cols
];
CV_Assert
(
0
<=
label
&&
label
<=
nccomps
);
(
binary
.
data
)[(
x
)
+
(
y
)
*
X
]
=
colors0
[
label
];
}
}
});
nccomps
=
cv
::
connectedComponentsWithStats
(
binary
,
m1
,
m2
,
m3
,
4
);
//
if
(
nccomps
<=
1
)
return
FUNC_CANNOT_CALC
;
//统计元件面积
std
::
vector
<
int
>
vHist
(
nccomps
);
for
(
int
y
=
0
;
y
<
Y
;
y
++
)
{
int
*
uPtr
=
(
int
*
)
m1
.
data
+
y
*
X
;
for
(
int
x
=
0
;
x
<
X
;
x
++
,
uPtr
++
)
{
vHist
[
*
uPtr
]
++
;
}
}
//统计面积个数
std
::
map
<
int
,
int
>
cAreaMap
;
for
(
const
auto
&
v
:
vHist
)
{
std
::
map
<
int
,
int
>::
iterator
it
=
cAreaMap
.
find
(
v
);
if
(
it
!=
cAreaMap
.
end
())
{
it
->
second
++
;
continue
;
}
else
{
cAreaMap
.
insert
(
std
::
make_pair
(
v
,
1
));
};
}
struct
tMap
{
int
Key
;
int
Value
;
tMap
(
int
Key
,
int
Value
)
:
Key
(
Key
),
Value
(
Value
)
{}
bool
operator
>
(
const
tMap
&
te
)
const
{
return
Value
>
te
.
Value
;
}
};
//获得单个元器件面积(准确性待测试,假定不粘连占大多数!)
std
::
vector
<
tMap
>
tVector
;
std
::
map
<
int
,
int
>::
iterator
it
;
for
(
it
=
cAreaMap
.
begin
();
it
!=
cAreaMap
.
end
();
it
++
)
{
tVector
.
push_back
(
tMap
(
it
->
first
,
it
->
second
));
}
std
::
sort
(
tVector
.
begin
(),
tVector
.
end
(),
std
::
greater
<
tMap
>
());
if
(
tVector
.
size
()
<
2
)
{
return
false
;
}
//单个元件面积
int
sinPartSize
=
cvRound
((
tVector
[
0
].
Key
+
tVector
[
1
].
Key
)
/
2.
);
std
::
vector
<
uchar
>
colors
(
nccomps
+
1
,
0
);
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
colors
[
i
]
=
255
;
if
((((
int
*
)
m2
.
data
)[(
cv
::
CC_STAT_AREA
)
+
(
i
)
*
m2
.
cols
]
>=
1.35
*
sinPartSize
)
||
(((
int
*
)
m2
.
data
)[(
cv
::
CC_STAT_AREA
)
+
(
i
)
*
m2
.
cols
]
<
0.45
*
sinPartSize
))
//经验值
{
colors
[
i
]
=
0
;
}
}
std
::
vector
<
int
>
trayCount
(
nccomps
+
1
,
0
);
Palete
pal
;
unsigned
int
colorCount
=
0
;
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
colorCount
=
cvRound
((
float
)
m2
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_AREA
]
/
(
float
)
sinPartSize
);
CvLabel
_label
=
i
;
double
r
,
g
,
b
;
if
(
!
colors
[
_label
]
==
0
)
{
_HSV2RGB_
((
double
)((
colorCount
*
77
)
%
360
),
1.
,
1.
,
r
,
g
,
b
);
}
else
{
_HSV2RGB_
((
double
)(((
colorCount
+
2
)
*
77
)
%
360
),
1.
,
.5
,
r
,
g
,
b
);
}
pal
[
_label
]
=
CV_RGB
(
r
,
g
,
b
);
trayCount
[
_label
]
=
colorCount
;
}
//认为是粘连
cv
::
parallel_for_
(
cv
::
Range
(
0
,
Y
),
[
&
](
const
cv
::
Range
&
range
)
->
void
{
for
(
int
y
=
range
.
start
;
y
<
range
.
end
;
y
++
)
{
for
(
int
x
=
0
;
x
<
X
;
x
++
)
{
int
label
=
((
int
*
)
m1
.
data
)[(
x
)
+
(
y
)
*
m1
.
cols
];
CV_Assert
(
0
<=
label
&&
label
<=
nccomps
);
if
(
binary
.
ptr
<
uint8_t
>
(
y
)[
x
])
{
cc
.
ptr
<
cv
::
Vec4b
>
(
y
)[
x
]
=
cv
::
Vec4b
((
uchar
)
pal
[
label
].
val
[
0
],
(
uchar
)
pal
[
label
].
val
[
1
],
(
uchar
)
pal
[
label
].
val
[
2
],
255
);
}
binary
.
ptr
<
uint8_t
>
(
y
)[
x
]
=
colors
[
label
];
}
}
});
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
CvLabel
_label
=
i
;
if
(
trayCount
[
_label
]
!=
1
)
{
cv
::
putText
(
cc
,
std
::
to_string
(
trayCount
[
_label
]),
cv
::
Point
(
cvRound
(
m3
.
ptr
<
double
>
(
i
)[
0
]),
cvRound
(
m3
.
ptr
<
double
>
(
i
)[
1
])),
cv
::
FONT_HERSHEY_PLAIN
,
1
,
cv
::
Scalar
(
0
,
0
,
255
,
255
),
1
);
}
}
//计数
int
totalCount
=
std
::
accumulate
(
trayCount
.
begin
(),
trayCount
.
end
(),
0
);
//画图显示
std
::
string
text
=
"Reel Number = "
+
std
::
to_string
(
totalCount
);
cv
::
putText
(
cc
,
text
,
cv
::
Point
(
35
,
35
),
0
,
1.0
,
cv
::
Scalar
(
0
,
140
,
255
,
255
),
2
);
//标记
binary
=
cv
::
Scalar
(
0
);
for
(
int
t
=
0
;
t
<
totalCount
;
t
++
)
{
binary
.
ptr
<
uint8_t
>
(
0
)[
t
]
=
255
;
}
}
}
else
if
(
strcmp
(
ccSubType
,
"IP_DYNAMIC_PARTS"
)
==
0
)
else
if
(
strcmp
(
ccSubType
,
"IP_DYNAMIC_PARTS"
)
==
0
)
{
{
...
@@ -4303,7 +4465,6 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -4303,7 +4465,6 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
}
}
}
}
}
}
//计数
//计数
std
::
vector
<
cv
::
Point
>
idx
;
std
::
vector
<
cv
::
Point
>
idx
;
cv
::
findNonZero
(
binary
,
idx
);
cv
::
findNonZero
(
binary
,
idx
);
...
@@ -4315,7 +4476,6 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -4315,7 +4476,6 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
//<输出结果
//<输出结果
const
int
SizeConst
=
4
;
const
int
SizeConst
=
4
;
//<输出计数结果标记图像
//<输出计数结果标记图像
{
memset
(
ipReelNum
,
0
,
SizeConst
);
memset
(
ipReelNum
,
0
,
SizeConst
);
ipReelNum
[
0
]
=
trayNum
;
ipReelNum
[
0
]
=
trayNum
;
...
@@ -4333,7 +4493,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
...
@@ -4333,7 +4493,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
//拷贝数据
//拷贝数据
memcpy
(
tpDstImg
->
vpImage
,
cc
.
data
,
_Size
);
memcpy
(
tpDstImg
->
vpImage
,
cc
.
data
,
_Size
);
}
return
FUNC_OK
;
return
FUNC_OK
;
}
}
...
@@ -7452,7 +7612,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
...
@@ -7452,7 +7612,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
colors
[
i
]
=
255
;
colors
[
i
]
=
255
;
double
minSize
=
cv
::
min
(
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_WIDTH
],
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_HEIGHT
]);
double
dRate
=
(
double
)
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_WIDTH
]
/
(
double
)
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_HEIGHT
];
double
minSize
=
cv
::
min
(
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_WIDTH
],
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_HEIGHT
]);
double
dRate
=
(
double
)
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_WIDTH
]
/
(
double
)
stats
.
ptr
<
int
>
(
i
)[
cv
::
CC_STAT_HEIGHT
];
if
(
minSize
<
2
0
||
!
(
dRate
>
0.75
&&
dRate
<
1.25
))
if
(
minSize
<
2
4
||
!
(
dRate
>
0.75
&&
dRate
<
1.25
))
{
{
colors
[
i
]
=
0
;
colors
[
i
]
=
0
;
}
}
...
@@ -7500,7 +7660,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
...
@@ -7500,7 +7660,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
cv
::
approxPolyDP
(
cv
::
Mat
(
contour
),
approx
,
arcL
*
0.01
,
true
);
cv
::
approxPolyDP
(
cv
::
Mat
(
contour
),
approx
,
arcL
*
0.01
,
true
);
if
(
approx
.
size
()
>
5
)
{
if
(
approx
.
size
()
>
5
)
{
cv
::
Rect
bbox
=
cv
::
boundingRect
(
contour
);
cv
::
Rect
bbox
=
cv
::
boundingRect
(
contour
);
if
(
MIN
(
bbox
.
width
,
bbox
.
height
)
>
18
&&
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
>
0.75
&&
\
if
(
MIN
(
bbox
.
width
,
bbox
.
height
)
>
24
&&
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
>
0.75
&&
\
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
<
1.25
)
{
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
<
1.25
)
{
//圆度
//圆度
double
afa
=
4.0
f
*
CV_PI
*
cv
::
contourArea
(
contour
,
false
)
/
std
::
pow
(
arcL
,
2
);
double
afa
=
4.0
f
*
CV_PI
*
cv
::
contourArea
(
contour
,
false
)
/
std
::
pow
(
arcL
,
2
);
...
@@ -7556,14 +7716,15 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
...
@@ -7556,14 +7716,15 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
//排序
//排序
std
::
sort
(
AFAs
.
begin
(),
AFAs
.
end
(),
std
::
less
<
AFA
>
());
std
::
sort
(
AFAs
.
begin
(),
AFAs
.
end
(),
std
::
less
<
AFA
>
());
//高精度定位
//高精度定位
if
(
bHighAccuracy
)
{
if
(
false
)
{
EyemOcsDXY
tpPoint
;
IntPtr
hObject
;
EyemOcsDXY
tpPoint
;
IntPtr
hObject
;
tpPoint
.
dX
=
AFAs
[
0
].
tpCircle
.
dX
;
tpPoint
.
dY
=
AFAs
[
0
].
tpCircle
.
dY
;
tpPoint
.
dX
=
AFAs
[
0
].
tpCircle
.
dX
;
tpPoint
.
dY
=
AFAs
[
0
].
tpCircle
.
dY
;
//提取图像
//提取图像
std
::
vector
<
cv
::
Mat
>
mvx
;
std
::
vector
<
cv
::
Mat
>
mvx
;
cv
::
split
(
cc
,
mvx
);
cv
::
split
(
cc
,
mvx
);
EyemImage
imageRed
;
imageRed
.
iWidth
=
cc
.
cols
;
imageRed
.
iHeight
=
cc
.
rows
;
imageRed
.
iDepth
=
cc
.
depth
();
imageRed
.
iChannels
=
1
;
imageRed
.
vpImage
=
mvx
[
2
].
data
;
EyemImage
imageRed
;
imageRed
.
iWidth
=
cc
.
cols
;
imageRed
.
iHeight
=
cc
.
rows
;
imageRed
.
iDepth
=
cc
.
depth
();
imageRed
.
iChannels
=
1
;
imageRed
.
vpImage
=
mvx
[
2
].
data
;
eyemEdge1dFindCircle
(
imageRed
,
tpPoint
,
13
,
4
,
2
,
19
,
2
,
1
,
35
,
"positive"
,
&
hObject
);
int
iRadius
=
27
,
iCapLength
=
9
,
iCapWidth
=
6
,
nCalipers
=
19
,
nFilterSize
=
2
,
iSearchDirec
=
1
;
eyemEdge1dFindCircle
(
imageRed
,
tpPoint
,
iRadius
,
iCapLength
,
iCapWidth
,
nCalipers
,
nFilterSize
,
iSearchDirec
,
35
,
"positive"
,
&
hObject
);
//拟合
//拟合
std
::
vector
<
EyemOcsDXY
>
*
tpResults
=
reinterpret_cast
<
std
::
vector
<
EyemOcsDXY
>*>
(
hObject
);
std
::
vector
<
EyemOcsDXY
>
*
tpResults
=
reinterpret_cast
<
std
::
vector
<
EyemOcsDXY
>*>
(
hObject
);
double
rms
;
EyemOcsDXYR
_tpCircle
;
double
rms
;
EyemOcsDXYR
_tpCircle
;
...
@@ -7776,18 +7937,37 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
...
@@ -7776,18 +7937,37 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
const
int
X
=
image
.
cols
;
const
int
Y
=
image
.
rows
;
const
int
X
=
image
.
cols
;
const
int
Y
=
image
.
rows
;
if
(
image
.
channels
()
>
3
)
{
cv
::
Mat
showMat
;
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_BGRA2BGR
);
cv
::
cvtColor
(
image
,
showMat
,
cv
::
COLOR_GRAY2BGRA
);
}
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_BGR2GRAY
);
cv
::
Mat
mask
;
cv
::
threshold
(
image
,
mask
,
0
,
255
,
cv
::
THRESH_BINARY_INV
|
cv
::
THRESH_OTSU
);
cv
::
Mat
judgeMat
;
//设定bin数目
judgeMat
=
image
(
cv
::
Rect
(
500
,
160
,
120
,
120
));
const
int
histSize
=
17
;
//设定取值范围
float
range
[]
=
{
0
,
255
};
const
float
*
histRange
=
{
range
};
//计算直方图
cv
::
Mat
hist
;
cv
::
calcHist
(
&
image
,
1
,
0
,
cv
::
Mat
(),
hist
,
1
,
&
histSize
,
&
histRange
);
//计算背景像素
int
maxIdx
[
2
]
=
{
255
,
255
};
cv
::
minMaxIdx
(
hist
,
NULL
,
NULL
,
NULL
,
maxIdx
);
//背景阈值
int
backThresh
=
15
*
(
maxIdx
[
0
]
-
2
);
//去掉背景
cv
::
parallel_for_
(
cv
::
Range
(
0
,
Y
),
[
&
](
const
cv
::
Range
range
)
->
void
{
for
(
int
y
=
range
.
start
;
y
<
range
.
end
;
y
++
)
{
for
(
int
x
=
0
;
x
<
X
;
x
++
)
{
if
((
image
.
data
)[(
x
)
+
(
y
)
*
X
]
>=
backThresh
)
{
(
image
.
data
)[(
x
)
+
(
y
)
*
X
]
=
backThresh
;
}
}
}
});
//去掉干扰
cv
::
Mat
binary
,
srcPrev
;
cv
::
bitwise_not
(
image
,
srcPrev
);
return
FUNC_OK
;
#pragma region resize img
#pragma region resize img
//const int minInputSize = 832;
//const int minInputSize = 832;
...
@@ -7944,3 +8124,5 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
...
@@ -7944,3 +8124,5 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
return
FUNC_OK
;
return
FUNC_OK
;
}
}
eyemLib/eyemMisc.h
查看文件 @
547390f
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#ifndef __EYEM_MISC_H
#ifndef __EYEM_MISC_H
#define __EYEM_MISC_H
#define __EYEM_MISC_H
#include <numeric>
#include "eyemLib.h"
#include "eyemLib.h"
#include <tbb\tbb.h>
#include <tbb\tbb.h>
...
...
eyemLib/stegers.cpp
0 → 100644
查看文件 @
547390f
#include "stegers.h"
contour
::
contour
()
{
clear
();
}
//constructor
contour
::
contour
(
int32_t
nnum
,
std
::
vector
<
float
>&
nrow
,
std
::
vector
<
float
>&
ncol
,
std
::
vector
<
float
>&
nangle
,
std
::
vector
<
float
>&
nresponse
,
contour_class
ncont_class
)
{
num
=
nnum
;
row
=
nrow
;
col
=
ncol
;
angle
=
nangle
;
response
=
nresponse
;
cont_class
=
ncont_class
;
}
void
contour
::
clear
()
{
num
=
0
;
row
.
resize
(
0
);
col
.
resize
(
0
);
angle
.
resize
(
0
);
response
.
resize
(
0
);
width_l
.
resize
(
0
);
width_r
.
resize
(
0
);
asymmetry
.
resize
(
0
);
contrast
.
resize
(
0
);
cont_class
=
contour_class
::
cont_no_junc
;
}
chord
::
chord
()
{
r
=
0
;
cb
=
0
;
ce
=
0
;
}
chord
::
chord
(
short
nr
,
short
ncb
,
short
nce
)
{
r
=
nr
;
cb
=
ncb
;
ce
=
nce
;
}
region
::
region
(
const
std
::
vector
<
int32_t
>&
image
,
uint32_t
min_val
,
int32_t
image_width
,
int32_t
image_m_height
)
{
rl
.
resize
(
0
);
long
grey
;
long
r
,
c
,
l
,
count
;
bool
inside
;
inside
=
false
;
count
=
0
;
rl
.
emplace_back
();
for
(
r
=
0
;
r
<
image_m_height
;
r
++
)
{
for
(
c
=
0
;
c
<
image_width
;
c
++
)
{
l
=
LCOR
(
r
,
c
,
image_width
);
grey
=
image
[
l
];
if
(
grey
>=
min_val
)
{
if
(
!
inside
)
{
inside
=
true
;
rl
[
count
].
r
=
(
int16_t
)
r
;
rl
[
count
].
cb
=
(
int16_t
)
c
;
}
}
else
{
if
(
inside
)
{
inside
=
false
;
rl
[
count
].
ce
=
(
int16_t
)(
c
-
1
);
count
++
;
rl
.
emplace_back
();
}
}
}
if
(
inside
)
{
inside
=
false
;
rl
[
count
].
ce
=
(
int16_t
)(
image_width
-
1
);
count
++
;
rl
.
emplace_back
();
}
}
this
->
num
=
count
;
}
//
//bool region::test() {
// const char* frame[] =
// {
// "00100100",
// "00110100",
// "00011000",
// "01000100",
// "01000000",
// 0 };
// const char* gold[] =
// {
// "00100100",
// "00110100",
// "00011000",
// "02000100",
// "02000000",
// 0 };
//
// cv::Mat pels(5, 8, CV_8U);
// DrawShape(pels, frame);
//
// std::vector<int32_t> lpels(5 * 8);
// for (auto row = 0; row < pels.rows; row++)
// for (auto col = 0; col < pels.cols; col++) {
// auto l = LCOR(row, col, pels.cols);
// lpels[l] = int32_t(pels.at<uint8_t>(row, col));
// }
//
// region rg(lpels, 1, pels.cols, pels.rows);
// bool check = rg.rl.size() == 9;
// if (!check) return check;
//
// std::vector<chord> golds;
// golds.emplace_back(0, 2, 2);
// golds.emplace_back(0, 5, 5);
// golds.emplace_back(1, 2, 3);
// golds.emplace_back(1, 5, 5);
// golds.emplace_back(2, 3, 4);
// golds.emplace_back(3, 1, 1);
// golds.emplace_back(3, 5, 5);
// golds.emplace_back(4, 1, 1);
// golds.emplace_back(0, 0, 0);
//
// for (int i = 0; i < 9; i++)
// assert(rg.rl[i] == golds[i]);
//
// return true;
//
}
\ No newline at end of file
\ No newline at end of file
eyemLib/stegers.h
0 → 100644
查看文件 @
547390f
#pragma once
#include <vector>
#include <ostream>
#ifndef LCOR
#define LCOR(row,col,width) (row)*(width) + (col)
#endif
enum
class
contour_class
{
/** no end point is a junction */
cont_no_junc
,
/** only the start point of the line is a junction */
cont_start_junc
,
/** only the end point of the line is a junction */
cont_end_junc
,
/** both end points of the line are junctions */
cont_both_junc
,
/** the contour is closed */
cont_closed
};
class
contour
{
/** number of points */
public
:
//default constructor
contour
();
//constructor
contour
(
int32_t
nnum
,
std
::
vector
<
float
>&
nrow
,
std
::
vector
<
float
>&
ncol
,
std
::
vector
<
float
>&
nangle
,
std
::
vector
<
float
>&
nresponse
,
contour_class
ncont_class
);
void
clear
();
float
compute_length
()
const
{
std
::
vector
<
float
>::
const_iterator
row_b
=
row
.
begin
()
+
1
;
std
::
vector
<
float
>::
const_iterator
col_b
=
col
.
begin
()
+
1
;
float
length
=
0
.
0
f
;
for
(;
row_b
<
row
.
end
()
&&
col_b
<
col
.
end
();
row_b
++
,
col_b
++
)
{
float
dr
=
*
(
row_b
)
-*
(
row_b
-
1
);
float
dc
=
*
(
col_b
)
-*
(
col_b
-
1
);
length
+=
std
::
sqrt
(
dr
*
dr
+
dc
*
dc
);
}
return
length
;
}
int32_t
num
=
0
;
std
::
vector
<
float
>
row
;
/** column coordinates of the line points (X coordinate in ImageJ) */
std
::
vector
<
float
>
col
;
/** angle of normal (measured from the row (Y) axis) */
std
::
vector
<
float
>
angle
;
/** response of line point (second derivative) */
std
::
vector
<
float
>
response
;
/** width to the left of the line */
std
::
vector
<
float
>
width_l
;
/** width to the right of the line */
std
::
vector
<
float
>
width_r
;
/** asymmetry of the line point */
std
::
vector
<
float
>
asymmetry
;
/** contrast of the line point */
std
::
vector
<
float
>
contrast
;
/** contour class (e.g., closed, no_junc) */
contour_class
cont_class
;
};
class
crossRef
{
public
:
/*
Storage the Crossref variables, it is the Correction.java code
This data structure facilitates the quick search for the next possible starting point of a line.An array of crossrefs will be accumulatedand
sorted according to its value.xand y are the coordinates of a point in the image.When this point has been processed it will be marked as done.
*/
crossRef
(
int32_t
x
=
0
,
int32_t
y
=
0
,
double
value
=
0
.
0
,
bool
done
=
false
)
:
m_x
(
x
),
m_y
(
y
),
m_val
(
value
),
m_done
(
done
)
{}
// Accessors
const
int32_t
&
x
()
const
{
return
m_x
;
}
const
int32_t
&
y
()
const
{
return
m_y
;
}
const
double
&
value
()
const
{
return
m_val
;
}
bool
done
()
const
{
return
m_done
;
}
void
setDone
()
const
{
m_done
=
true
;
}
void
setUnDone
()
const
{
m_done
=
false
;
}
int32_t
compareTo
(
crossRef
&
other
)
{
int32_t
rt
=
(
m_val
>
other
.
value
())
?
-
1
:
(
m_val
<
other
.
value
())
?
1
:
0
;
return
rt
;
}
bool
operator
==
(
const
crossRef
&
other
)
const
{
return
this
->
m_val
==
other
.
value
();
}
bool
operator
<
(
const
crossRef
&
other
)
const
{
return
this
->
m_val
<
other
.
value
();
}
bool
operator
>
(
const
crossRef
&
other
)
const
{
return
this
->
m_val
>
other
.
value
();
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ous
,
const
crossRef
&
dis
)
{
// return + str(self.x) + + str(self.y) + + str(self.value) + + str(self.done)
ous
<<
"x: "
<<
dis
.
x
()
<<
"
\t
y: "
<<
dis
.
y
()
<<
"
\t
value: "
<<
dis
.
value
()
<<
"
\t
done: "
<<
std
::
boolalpha
<<
dis
.
done
();
return
ous
;
}
private
:
int32_t
m_x
,
m_y
;
double
m_val
;
mutable
bool
m_done
;
};
/** Data structure to store three doubles: x,y and t (distance along line) */
class
doublepoint
{
public
:
double
cx
=
0
;
double
cy
=
0
;
double
t
=
0
;
doublepoint
()
{}
doublepoint
(
double
ccx
,
double
ccy
,
double
ct
)
{
cx
=
ccx
;
cy
=
ccy
;
t
=
ct
;
}
doublepoint
(
double
ccx
,
double
ccy
)
{
cx
=
ccx
;
cy
=
ccy
;
t
=
0
;
}
};
/** Offsets to a specific location in the image. An array of this type is
returned by the modified Bresenham algorithm in width.c. It is also used
in link.c to hold an array of pixel locations to check for appropriate
neighbors. */
class
offset
{
public
:
int32_t
x
;
int32_t
y
;
offset
()
{
x
=
0
;
y
=
0
;
}
offset
(
int32_t
nx
,
int32_t
ny
)
{
x
=
nx
;
y
=
ny
;
}
};
/** This data structure is used to accumulate junction information. It is
needed to split lines at junction points. */
class
junction
{
/** Index of line that is already processed */
public
:
int32_t
cont1
=
0
;
/** Index of line that runs into cont1 */
int32_t
cont2
=
0
;
/** Index of the junction point in cont1 */
int32_t
pos
=
0
;
/** y-(row-)coordinate of the junction point (corrected for ImageJ)*/
float
x
=
0
;
/** x-(col-)coordinate of the junction point (corrected for ImageJ)*/
float
y
=
0
;
junction
()
{}
junction
(
int32_t
ncont1
,
int32_t
ncont2
,
int32_t
npos
,
float
nx
,
float
ny
)
{
cont1
=
ncont1
;
cont2
=
ncont2
;
pos
=
npos
;
x
=
nx
;
y
=
ny
;
}
bool
operator
==
(
const
junction
&
other
)
const
{
return
this
->
pos
==
other
.
pos
;
}
bool
operator
<
(
const
junction
&
other
)
const
{
return
this
->
pos
<
other
.
pos
;
}
bool
operator
>
(
const
junction
&
other
)
const
{
return
this
->
pos
>
other
.
pos
;
}
/** This function compares two junctions according to their first line indexes,
and, if needed, by the position of the junction within the line. It is
called by qsort. */
static
bool
compare
(
const
junction
&
thisJunction
,
const
junction
&
otherjunction
)
{
if
(
thisJunction
.
cont1
==
otherjunction
.
cont1
)
{
return
thisJunction
.
pos
>=
otherjunction
.
pos
;
}
else
{
return
thisJunction
.
cont1
>
otherjunction
.
cont1
;
}
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ous
,
const
junction
&
dis
)
{
ous
<<
"cont1: "
<<
dis
.
cont1
<<
"
\t
cont2: "
<<
dis
.
cont2
<<
"
\t
pos: "
<<
dis
.
pos
<<
"
\t
xy: "
<<
dis
.
x
<<
","
<<
dis
.
y
;
return
ous
;
}
};
/** A chord in a run-length encoded region */
class
chord
{
/** row coordinate of the chord */
public
:
// default dtor, copy ctor ok
short
r
=
0
;
/** column coordinate of the start of the chord */
short
cb
=
0
;
/** column coordinate of the end of the chord */
short
ce
=
0
;
chord
();
chord
(
short
nr
,
short
ncb
,
short
nce
);
bool
operator
==
(
chord
&
other
)
const
{
return
this
->
r
==
other
.
r
&&
this
->
cb
==
other
.
cb
&&
this
->
ce
==
other
.
ce
;
}
};
/** Run-length encoded region of an image. This type is returned by the
threshold() function. It provides the means to efficiently link line points
into lines. */
class
region
{
public
:
region
(
const
std
::
vector
<
int32_t
>&
image
,
uint32_t
min_val
,
int32_t
image_width
,
int32_t
image_m_height
);
int32_t
num
=
0
;
// number of chords
std
::
vector
<
chord
>
rl
;
// array of chords
//static bool test();
};
\ No newline at end of file
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论