Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit da2526be
由
张士柳
编写于
2021-10-26 16:02:28 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
94b11f53
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
321 行增加
和
120 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/Program.cs
eyemLib/eyemCodeDetector.cpp
eyemLib/eyemFit.cpp
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemLib.vcxproj
eyemLib/eyemMisc.cpp
eyemLib/eyemNNDetector.cpp
eyemLib/eyemNNDetector.h
eyemLib/resnet.h
eyemLib/yoloWrapper.cpp
eyemLib/yoloWrapper.h
eyemLib-Sharp/EyemLib.cs
查看文件 @
da2526b
...
...
@@ -7,6 +7,7 @@ using System.Drawing;
using
System.Drawing.Imaging
;
using
System.Threading
;
using
System.IO
;
using
System.Linq
;
namespace
eyemLib_Sharp
{
...
...
@@ -991,7 +992,7 @@ namespace eyemLib_Sharp
/// <param name="detectorModelPath">模型文件</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemInitNNDetector
(
string
detectorConfigPath
,
string
detectorModelPath
);
private
static
extern
int
eyemInitNNDetector
(
string
detectorConfigPath
,
string
detectorModelPath
,
int
iNetSizew
,
int
iNetSizeh
);
/// <summary>
/// 目标检测器
...
...
@@ -999,7 +1000,12 @@ namespace eyemLib_Sharp
/// <param name="tpImage">输入图像</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemNNDetector
(
EyemImage
tpImage
,
out
int
ipNum
,
ref
BboxContainer
container
);
private
static
extern
int
eyemNNDetector
(
EyemImage
tpImage
,
out
int
ipNum
,
ref
BboxContainer
container
,
out
EyemImage
tpDstImg
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemInitClassifier
(
string
class
ifierConfigPath
,
string
class
ifierModelPath
,
int
ntype
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemClassifier
(
EyemImage
tpImage
);
#
endregion
#
region
模板匹配
...
...
@@ -1114,6 +1120,8 @@ namespace eyemLib_Sharp
OnNewLogCallback
+=
new
TCallBack
(
EyemLib_OnNewLogCallback
);
eyemInitNNDataCodeModel
(
".\\darknet\\detect-tiny.cfg"
,
".\\darknet\\detect-tiny.weights"
,
".\\darknet\\sr.prototxt"
,
".\\darknet\\sr.caffemodel"
);
eyemInitClassifier
(
"D:\\detect-tiny-tray.cfg"
,
"D:\\detect-tiny-tray.weights"
,
0
);
}
public
static
void
Free
()
...
...
@@ -1136,6 +1144,24 @@ namespace eyemLib_Sharp
#
endregion
//list元素随机打乱
public
static
void
RandomShuffle
<
T
>(
List
<
T
>
list
)
{
List
<
T
>
cache
=
new
List
<
T
>();
int
currentIndex
;
while
(
list
.
Count
>
0
)
{
Random
rd
=
new
Random
(
unchecked
((
int
)
DateTime
.
Now
.
Ticks
));
currentIndex
=
rd
.
Next
(
0
,
list
.
Count
);
cache
.
Add
(
list
[
currentIndex
]);
list
.
RemoveAt
(
currentIndex
);
}
for
(
int
i
=
0
;
i
<
cache
.
Count
;
i
++)
{
list
.
Add
(
cache
[
i
]);
}
}
public
static
void
eyemReadImageTool
(
string
fileName
)
{
EyemImage
image
;
...
...
@@ -1151,6 +1177,35 @@ namespace eyemLib_Sharp
sw
.
Restart
();
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
//string[] fileNames = Directory.GetFiles(@"D:\训练数据集\点料机料盘识别\val_images", "*.png", SearchOption.AllDirectories);
//List<string> random_shuffle = new List<string>(fileNames);
////随机打乱顺序
//RandomShuffle(random_shuffle);
//bool HaveDuplicates = random_shuffle.GroupBy(i => i).Where(g => g.Count() > 1).Count() >= 1;
//StreamWriter swr = new StreamWriter("D:\\val.txt", true);
//foreach (var item in random_shuffle)
//{
// string[] items = item.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
// swr.WriteLine("data/val_images/" + items[items.Length - 1]);
// swr.Flush();
//}
//return;
//eyemRenameFile(@"D:\训练数据集\20211021");
//return;
//flag = eyemInitNNDetector(".\\darknet\\cifar_resnet50.cfg", ".\\darknet\\cifar_resnet50.weights");
//if (flag == 0)
//{
// int ipNum;
// BboxContainer bboxes = new BboxContainer();
// eyemNNDetector(image, out ipNum, ref bboxes, out tpDstImg);
//}
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//return;
//UnmanagedBitmap umBitmap = new UnmanagedBitmap("D:\\算法测试图像\\circle_plate_04.png");
//return;
...
...
@@ -1170,8 +1225,16 @@ namespace eyemLib_Sharp
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//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 };
//eyemClassifier(image);
//flag = eyemLibImpl(image, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save("D:\\ResOut\\" + file);
//}
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//return;
//EyemImage templ, search;
//flag = eyemImageRead("D://批量测试图像//template.png", -1, out templ);
...
...
@@ -1392,11 +1455,8 @@ namespace eyemLib_Sharp
tpRoi
.
iHeight
=
image
.
iHeight
-
100
;
//flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg);
int
[]
ipReelNum
=
new
int
[
4
];
//flag = eyemAchvMatchMat(image, tpRoi, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
...
...
@@ -1463,18 +1523,18 @@ namespace eyemLib_Sharp
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",,IP_SQUARE_PARTS
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
eyemCountObjectIrregularParts
(
image
,
tpRoi
,
file
.
Replace
(
".png"
,
""
),
"IP_SQUAR
E_PARTS"
,
ipReelNum
,
out
tpDstImg
);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARG
E_PARTS", 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);
//移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
Bitmap
bitmap
=
eyemCvtToBitmap
(
tpDstImg
);
if
(
bitmap
!=
null
)
{
bitmap
.
Save
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
+
"\\ResOut\\"
+
file
);
}
//
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//
if (bitmap != null)
//
{
//
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//
}
//< 解码测试
//int ipNum; EyemBarCode* tpResults;
...
...
eyemLib-Sharp/Program.cs
查看文件 @
da2526b
...
...
@@ -17,7 +17,7 @@ namespace eyemLib_Sharp
}
//初始化
EyemLib
.
Init
();
string
[]
fileNames
=
Directory
.
GetFiles
(
@"D:\批量测试图像"
,
"*.*"
,
SearchOption
.
AllDirectories
);
string
[]
fileNames
=
Directory
.
GetFiles
(
@"D:\批量测试图像
\
", "
*.*
", SearchOption.AllDirectories);
foreach
(
var
item
in
fileNames
)
{
EyemLib
.
eyemReadImageTool
(
item
);
...
...
eyemLib/eyemCodeDetector.cpp
查看文件 @
da2526b
...
...
@@ -33,7 +33,7 @@ CodeDetector::CodeDetector(const std::string & detector_config_path,
p
=
cv
::
makePtr
<
CodeDetector
::
Impl
>
();
if
(
!
detector_config_path
.
empty
()
&&
!
detector_model_path
.
empty
())
{
p
->
detector_
=
std
::
make_shared
<
YoloWrapper
>
();
p
->
detector_
->
init
(
detector_config_path
,
detector_model_path
);
p
->
detector_
->
init
(
detector_config_path
,
detector_model_path
,
cv
::
Size
(
960
,
960
)
);
}
else
{
p
->
detector_
=
NULL
;
...
...
eyemLib/eyemFit.cpp
查看文件 @
da2526b
...
...
@@ -288,9 +288,9 @@ static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsDAB
tpLine
.
dC
=
-
(
nx
*
px
+
ny
*
py
);
}
int
eyemFitLine
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
n
umToIgnore
,
EyemOcsDABC
&
tpLine
)
int
eyemFitLine
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
iN
umToIgnore
,
EyemOcsDABC
&
tpLine
)
{
if
(
iPtnNum
-
n
umToIgnore
<
2
||
iPtnNum
<
2
)
{
if
(
iPtnNum
-
iN
umToIgnore
<
2
||
iPtnNum
<
2
)
{
return
FUNC_CANNOT_CALC
;
}
//初始化参数,或许可用RANSAC算法进一步提高鲁棒性,不过没必要
...
...
@@ -313,7 +313,7 @@ int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, EyemOcsDABC &
}
std
::
sort
(
taPoints
.
begin
(),
taPoints
.
end
(),
std
::
less
<
EyemOcsDXY2D
>
());
for
(
int
i
=
(
iPtnNum
-
n
umToIgnore
);
i
<
iPtnNum
;
i
++
)
{
for
(
int
i
=
(
iPtnNum
-
iN
umToIgnore
);
i
<
iPtnNum
;
i
++
)
{
taPoints
[
i
].
bValid
=
false
;
}
/* Run again... */
...
...
@@ -325,7 +325,7 @@ int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, EyemOcsDABC &
sr
+=
r
;
}
}
err
=
std
::
sqrt
(
sr
/
(
double
)(
iPtnNum
-
n
umToIgnore
));
err
=
std
::
sqrt
(
sr
/
(
double
)(
iPtnNum
-
iN
umToIgnore
));
if
(
err
<
EPS
)
break
;
if
(
std
::
abs
(
err
-
min_err
)
<
EPS
)
...
...
@@ -437,9 +437,9 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsD
tpCircle
.
dR
=
sqrt
(
pow
(
x
.
ptr
<
double_t
>
(
0
)[
0
],
2
)
+
pow
(
x
.
ptr
<
double_t
>
(
1
)[
0
],
2
)
-
4.0
*
(
x
.
ptr
<
double_t
>
(
2
)[
0
]))
/
2.0
;
}
int
eyemFitCircle
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
n
umToIgnore
,
double
&
dRMS
,
EyemOcsDXYR
&
tpCircle
)
int
eyemFitCircle
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
iN
umToIgnore
,
double
&
dRMS
,
EyemOcsDXYR
&
tpCircle
)
{
if
(
iPtnNum
-
n
umToIgnore
<
3
||
iPtnNum
<
3
)
{
if
(
iPtnNum
-
iN
umToIgnore
<
3
||
iPtnNum
<
3
)
{
return
FUNC_CANNOT_CALC
;
}
//初始化参数,或许可用RANSAC算法进一步提高鲁棒性,不过没必要
...
...
@@ -463,7 +463,7 @@ int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, double &dRM
//排序
std
::
sort
(
taPoints
.
begin
(),
taPoints
.
end
(),
std
::
less
<
EyemOcsDXY2D
>
());
//忽略的点
for
(
int
i
=
iPtnNum
-
n
umToIgnore
;
i
<
iPtnNum
;
i
++
)
{
for
(
int
i
=
iPtnNum
-
iN
umToIgnore
;
i
<
iPtnNum
;
i
++
)
{
taPoints
[
i
].
bValid
=
false
;
}
fitCircle2D_wods
(
iPtnNum
,
&
taPoints
[
0
],
tpCircle
);
...
...
@@ -474,7 +474,7 @@ int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, double &dRM
sr
+=
r
;
}
}
rms
=
std
::
sqrt
(
sr
/
(
double
)(
iPtnNum
-
n
umToIgnore
));
rms
=
std
::
sqrt
(
sr
/
(
double
)(
iPtnNum
-
iN
umToIgnore
));
if
(
rms
<
0.03
||
std
::
abs
((
dRMS
-
rms
))
<
1e-3
)
{
break
;
}
...
...
eyemLib/eyemLib.h
查看文件 @
da2526b
...
...
@@ -490,10 +490,10 @@ extern "C" {
#endif
// 函数接口
EXPORTS
int
eyemFitLine
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
n
umToIgnore
,
EyemOcsDABC
&
tpLine
);
EXPORTS
int
eyemFitLine
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
iN
umToIgnore
,
EyemOcsDABC
&
tpLine
);
EXPORTS
int
eyemRobustFitLine
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
iCalcMode
,
double
dRobustCoef
,
EyemOcsDABC
&
tpLine
);
EXPORTS
int
eyemFitLineRANSAC
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
double
dClippingFactor
,
EyemOcsDABC
&
tpLine
);
EXPORTS
int
eyemFitCircle
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
n
umToIgnore
,
double
&
dRMS
,
EyemOcsDXYR
&
tpCircle
);
EXPORTS
int
eyemFitCircle
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
iN
umToIgnore
,
double
&
dRMS
,
EyemOcsDXYR
&
tpCircle
);
EXPORTS
int
eyemRobustFitCircle
(
int
iPtnNum
,
EyemOcsDXY
*
taPoint
,
int
iCalcMode
,
double
dRobustCoef
,
EyemOcsDXYR
&
tpCircle
);
EXPORTS
int
eyemFitRTMatrix
(
int
iPtnNum
,
EyemOcsDXY
*
taPointA
,
EyemOcsDXY
*
taPointB
,
EyemRigidMatrix
&
dpResult
);
EXPORTS
int
eyemRobustFitPlane
(
int
iPtnNum
,
EyemOcsDXYZ
*
taPoint
,
int
iCalcMode
,
double
dRobustCoef
,
EyemOcsDABCD
&
tpPlane
);
...
...
@@ -867,8 +867,11 @@ extern "C" {
#endif
// 函数接口
EXPORTS
int
eyemInitNNDetector
(
const
char
*
detectorConfigPath
,
const
char
*
detectorModelPath
);
EXPORTS
int
eyemNNDetector
(
EyemImage
tpImage
,
int
*
ipNum
,
BboxContainer
&
container
);
EXPORTS
int
eyemInitNNDetector
(
const
char
*
detectorConfigPath
,
const
char
*
detectorModelPath
,
int
iNetSizew
,
int
iNetSizeh
);
EXPORTS
int
eyemNNDetector
(
EyemImage
tpImage
,
int
*
ipNum
,
BboxContainer
&
container
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemInitClassifier
(
const
char
*
classifierConfigPath
,
const
char
*
classifierModelPath
,
int
ntype
);
EXPORTS
int
eyemClassifier
(
EyemImage
tpImage
);
#ifdef __cplusplus
}
...
...
eyemLib/eyemLib.rc
查看文件 @
da2526b
此文件类型无法预览
eyemLib/eyemLib.vcxproj
查看文件 @
da2526b
...
...
@@ -74,8 +74,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;
D:\darknet\include;D:\3rdparty\pthreads\include;
$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;
D:\darknet\lib;D:\3rdparty\pthreads\lib;
$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...
...
@@ -83,8 +83,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;
D:\darknet\include;D:\3rdparty\pthreads\include;
$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;
D:\darknet\lib;D:\3rdparty\pthreads\lib;
$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
...
...
@@ -111,7 +111,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;
HAVE_STRUCT_TIMESPEC;
%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
...
...
@@ -119,7 +119,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;
darknetd.lib;pthreadVC2.lib;
%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...
...
@@ -148,7 +148,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;
HAVE_STRUCT_TIMESPEC;
%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
...
...
@@ -161,7 +161,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;
darknet.lib;pthreadVC2.lib;
%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
...
...
eyemLib/eyemMisc.cpp
查看文件 @
da2526b
...
...
@@ -2228,8 +2228,10 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
//最小外包矩形
cv
::
Point2f
_pts
[
4
];
ta
.
RBox
.
points
(
_pts
);
//已做标记(TODO:考虑增加判断哪些是起点哪些不是)
if
(
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)]
==
255
)
{
//已做标记(TODO:考虑增加判断哪些是起点哪些不是,20211018增加为四联通判断当前起点是否追踪过)
if
(
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)
-
1
]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
)
-
1
)[
cvRound
(
startCenter
.
x
)]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)
+
1
]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
)
+
1
)[
cvRound
(
startCenter
.
x
)]
==
255
)
{
continue
;
}
//获取模板图像(是否每次起点都计算模板,如果元件变形过大是否还会有用?)
...
...
@@ -3320,8 +3322,10 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
//最小外包矩形
cv
::
Point2f
_pts
[
4
];
ta
.
RBox
.
points
(
_pts
);
//已做标记(TODO:考虑增加判断哪些是起点哪些不是)
if
(
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)]
==
255
)
{
//已做标记(TODO:考虑增加判断哪些是起点哪些不是,20211018增加为四联通判断当前起点是否追踪过)
if
(
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)
-
1
]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
)
-
1
)[
cvRound
(
startCenter
.
x
)]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)
+
1
]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
)
+
1
)[
cvRound
(
startCenter
.
x
)]
==
255
)
{
continue
;
}
//获取模板图像(是否每次起点都计算模板,如果元件变形过大是否还会有用?)
...
...
@@ -5045,8 +5049,10 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
//最小外包矩形
cv
::
Point2f
_pts
[
4
];
ta
.
RBox
.
points
(
_pts
);
//已做标记(TODO:考虑增加判断哪些是起点哪些不是)
if
(
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)]
==
255
)
{
//已做标记(TODO:考虑增加判断哪些是起点哪些不是,20211018增加为四联通判断当前起点是否追踪过)
if
(
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)
-
1
]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
)
-
1
)[
cvRound
(
startCenter
.
x
)]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
))[
cvRound
(
startCenter
.
x
)
+
1
]
==
255
||
trackMat
.
ptr
<
uint8_t
>
(
cvRound
(
startCenter
.
y
)
+
1
)[
cvRound
(
startCenter
.
x
)]
==
255
)
{
continue
;
}
//获取模板图像(是否每次起点都计算模板,如果元件变形过大是否还会有用?)
...
...
@@ -5926,7 +5932,6 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
int
eyemCountObjectIrregularPartsE
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
fileName
,
const
char
*
ccTplName
,
IntPtr
hModelID
,
int
*
ipReelNum
,
EyemImage
*
tpDstImg
)
{
cv
::
Mat
src
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
//判断文件是否存在
if
(
src
.
empty
()
||
NULL
==
hModelID
)
{
return
FUNC_IMAGE_NOT_EXIST
;
...
...
@@ -7479,9 +7484,7 @@ int eyemReleaseModel(IntPtr &hModelID)
{
if
(
NULL
==
hModelID
)
return
FUNC_OK
;
std
::
vector
<
EyemModelID
>
*
tpModelID
=
reinterpret_cast
<
std
::
vector
<
EyemModelID
>*>
(
hModelID
);
for
(
std
::
vector
<
EyemModelID
>::
iterator
it
=
tpModelID
->
begin
();
it
!=
tpModelID
->
end
();
++
it
)
{
EyemModelID
*
modelID
=
&
(
*
it
);
...
...
@@ -7494,11 +7497,9 @@ int eyemReleaseModel(IntPtr &hModelID)
}
//清空容器
tpModelID
->
clear
();
//释放容器
delete
tpModelID
;
tpModelID
=
NULL
;
hModelID
=
NULL
;
return
FUNC_OK
;
}
...
...
@@ -7596,7 +7597,6 @@ int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *t
cv
::
blur
(
image
,
image
,
cv
::
Size
(
5
,
5
));
//用于显示
cv
::
Mat
cc
=
image
.
clone
();
//转hsv空间
cv
::
Mat
imgGray
;
cv
::
cvtColor
(
image
,
imgGray
,
cv
::
COLOR_BGR2HSV
);
...
...
@@ -7615,7 +7615,7 @@ int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *t
cv
::
bitwise_or
(
mask1
,
mask2
,
maskj
);
//去掉干扰
cv
::
morphologyEx
(
maskj
,
maskj
,
cv
::
MORPH_OPEN
,
cv
::
getStructuringElement
(
cv
::
MORPH_
RECT
,
cv
::
Size
(
3
,
3
)));
cv
::
morphologyEx
(
maskj
,
maskj
,
cv
::
MORPH_OPEN
,
cv
::
getStructuringElement
(
cv
::
MORPH_
ELLIPSE
,
cv
::
Size
(
5
,
5
)));
//测试用,局部用RBG分割
cv
::
Mat
labels
,
stats
,
centroids
;
...
...
@@ -7625,7 +7625,7 @@ int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *t
for
(
int
i
=
1
;
i
<
nccomps
;
i
++
)
{
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
];
if
(
minSize
<
2
4
||
!
(
dRate
>
0.75
&&
dRate
<
1.25
))
if
(
minSize
<
2
0
||
!
(
dRate
>
0.75
&&
dRate
<
1.25
))
{
colors
[
i
]
=
0
;
}
...
...
@@ -7659,7 +7659,7 @@ int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *t
cv
::
approxPolyDP
(
cv
::
Mat
(
contour
),
approx
,
arcL
*
0.01
,
true
);
if
(
approx
.
size
()
>
5
)
{
cv
::
Rect
bbox
=
cv
::
boundingRect
(
contour
);
if
(
MIN
(
bbox
.
width
,
bbox
.
height
)
>
2
4
&&
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
>
0.75
&&
\
if
(
MIN
(
bbox
.
width
,
bbox
.
height
)
>
2
0
&&
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
>
0.75
&&
\
((
float
)
bbox
.
width
/
(
float
)
bbox
.
height
)
<
1.25
)
{
//圆度
double
afa
=
4.0
f
*
CV_PI
*
cv
::
contourArea
(
contour
,
false
)
/
std
::
pow
(
arcL
,
2
);
...
...
@@ -7924,6 +7924,7 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
}
#include "eyemStopwatch.h"
#include "yoloWrapper.h"
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemImage
*
tpDstImg
)
{
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
...
...
@@ -7932,6 +7933,55 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
if
(
image
.
empty
())
return
FUNC_IMAGE_NOT_EXIST
;
if
(
image
.
channels
()
>
3
)
{
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_BGRA2BGR
);
}
cv
::
Mat
output
=
image
.
clone
();
#pragma region darknet.lib
//int topk = 5;
//DarkNet net;
//net.setPreferableParams(0.2, topk);
//if (net.init("D:/cifar_resnet50.cfg", "D:/cifar_resnet50.weights", 1) != 0)
//{
// std::cout << "net load failed" << std::endl;
// return FUNC_CANNOT_CALC;
//}
//net.forward(image);
////获取结果
//int predicts[5]; float confidence[5]; auto bbox = std::vector<cv::Rect>();
//net.getResult(predicts, confidence, &bbox);
#pragma endregion
#pragma region test new preprocess
////转单通道
//if (image.channels() != 1)
// cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
////图像裁剪
//cv::Mat src = image(cv::Rect(200, 200, image.cols - 400, image.rows - 400)).clone();
////image size
//int X = src.cols, Y = src.rows;
////用于去除黑色坏点干扰
//cv::Mat medBlur;
//cv::medianBlur(src, medBlur, 3);
////去除局部量斑影响(默认亮斑尺寸不会大于15个像素)
//cv::morphologyEx(medBlur, medBlur, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
////图像增强
//double min, max;
//cv::minMaxLoc(medBlur, &min, &max, NULL);
//src.convertTo(src, CV_64FC1);
//src -= min;
//src /= (max - min);
//src *= 65535;
//src.convertTo(src, CV_16UC1);
//src.convertTo(output, CV_8UC1, 1 / 255.);
#pragma endregion
#pragma region clock test
//Stopwatch sw;
...
...
@@ -7943,15 +7993,13 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
#pragma region resize img
//const int minInputSize =
832
;
//const int minInputSize =
128
;
//float resizeRatio = (float)sqrt(image.cols * image.rows * 1.0 / (minInputSize * minInputSize));
//int target_width = cvRound((float)image.cols / resizeRatio);
//int target_height = cvRound((float)image.rows / resizeRatio);
//cv::Mat input;
//resize(image, input, cv::Size(image.cols / 2, image.rows / 2), 0, 0, cv::INTER_CUBIC);
//resize(image, output, cv::Size(target_width, target_height), 0, 0, cv::INTER_CUBIC);
//image = input;
#pragma endregion
...
...
@@ -8095,6 +8143,19 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
#pragma endregion
if
(
!
output
.
empty
())
{
//<输出结果图像
tpDstImg
->
iWidth
=
output
.
cols
;
tpDstImg
->
iHeight
=
output
.
rows
;
tpDstImg
->
iDepth
=
output
.
depth
();
tpDstImg
->
iChannels
=
output
.
channels
();
//内存尺寸
int
_Size
=
tpDstImg
->
iWidth
*
tpDstImg
->
iHeight
*
tpDstImg
->
iChannels
*
sizeof
(
uint8_t
);
//分配初始化内存
tpDstImg
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
if
(
NULL
==
tpDstImg
->
vpImage
)
return
FUNC_NOT_ENOUGH_MEM
;
memset
(
tpDstImg
->
vpImage
,
0
,
_Size
);
//拷贝数据
memcpy
(
tpDstImg
->
vpImage
,
output
.
data
,
_Size
);
}
return
FUNC_OK
;
}
...
...
eyemLib/eyemNNDetector.cpp
查看文件 @
da2526b
#include "eyemNNDetector.h"
#include "yoloWrapper.h"
class
NNDetector
::
Impl
{
public
:
...
...
@@ -12,12 +11,12 @@ public:
};
NNDetector
::
NNDetector
(
const
std
::
string
&
detector_config_path
,
const
std
::
string
&
detector_model_path
)
const
std
::
string
&
detector_model_path
,
const
cv
::
Size
&
input_size
)
{
p
=
cv
::
makePtr
<
NNDetector
::
Impl
>
();
if
(
!
detector_config_path
.
empty
()
&&
!
detector_model_path
.
empty
())
{
p
->
detector_
=
std
::
make_shared
<
YoloWrapper
>
();
p
->
detector_
->
init
(
detector_config_path
,
detector_model_path
);
p
->
detector_
->
init
(
detector_config_path
,
detector_model_path
,
input_size
);
}
else
{
p
->
detector_
=
NULL
;
...
...
@@ -45,10 +44,10 @@ std::vector<cv::Rect> NNDetector::Impl::detect(const cv::Mat& img) {
return
detector_
->
forward
(
img
);
}
int
eyemInitNNDetector
(
const
char
*
detectorConfigPath
,
const
char
*
detectorModelPath
)
int
eyemInitNNDetector
(
const
char
*
detectorConfigPath
,
const
char
*
detectorModelPath
,
int
iNetSizew
,
int
iNetSizeh
)
{
try
{
pNNDetector
=
cv
::
makePtr
<
NNDetector
>
(
detectorConfigPath
,
detectorModelPath
);
pNNDetector
=
cv
::
makePtr
<
NNDetector
>
(
detectorConfigPath
,
detectorModelPath
,
cv
::
Size
(
iNetSizew
,
iNetSizeh
)
);
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
...
...
@@ -57,7 +56,7 @@ int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModel
return
FUNC_OK
;
}
int
eyemNNDetector
(
EyemImage
tpImage
,
int
*
ipNum
,
BboxContainer
&
container
)
int
eyemNNDetector
(
EyemImage
tpImage
,
int
*
ipNum
,
BboxContainer
&
container
,
EyemImage
*
tpDstImg
)
{
cv
::
Mat
src
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
if
(
src
.
empty
())
{
...
...
@@ -69,6 +68,77 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container)
EyemRect
bbox
;
bbox
.
iXs
=
target
[
i
].
x
;
bbox
.
iYs
=
target
[
i
].
y
;
bbox
.
iWidth
=
target
[
i
].
width
;
bbox
.
iHeight
=
target
[
i
].
height
;
container
.
bboxes
[
i
]
=
bbox
;
}
//输出图像
cv
::
Mat
input
;
int
incn
=
src
.
channels
();
if
(
incn
==
4
)
{
cv
::
cvtColor
(
src
,
input
,
cv
::
COLOR_BGRA2BGR
);
}
else
if
(
incn
==
1
)
{
cv
::
cvtColor
(
src
,
input
,
cv
::
COLOR_GRAY2BGR
);
//根据配置支持三通道图像
}
else
{
input
=
src
;
}
for
(
int
idx
=
0
;
idx
<
target
.
size
();
idx
++
)
{
cv
::
Rect
bbox
=
target
[
idx
]
&
cv
::
Rect
(
0
,
0
,
src
.
cols
,
src
.
rows
);
//标签
std
::
string
label
=
"TARGET"
;
int
baseLine
;
cv
::
Size
labelSize
=
cv
::
getTextSize
(
label
,
cv
::
FONT_HERSHEY_SIMPLEX
,
1.5
,
2
,
&
baseLine
);
cv
::
Scalar
pal
(
0
,
255
,
0
);
cv
::
rectangle
(
input
,
bbox
,
pal
);
cv
::
rectangle
(
input
,
cv
::
Point
(
bbox
.
x
,
bbox
.
y
-
labelSize
.
height
-
baseLine
),
cv
::
Point
(
bbox
.
x
+
labelSize
.
width
,
bbox
.
y
),
pal
,
cv
::
FILLED
);
cv
::
putText
(
input
,
label
,
cv
::
Point
(
bbox
.
tl
().
x
+
2
,
bbox
.
tl
().
y
-
baseLine
+
2
),
cv
::
FONT_HERSHEY_SIMPLEX
,
1.5
,
cv
::
Scalar
(
0
,
0
,
0
),
2
);
}
//<输出计数结果标记图像
tpDstImg
->
iWidth
=
input
.
cols
;
tpDstImg
->
iHeight
=
input
.
rows
;
tpDstImg
->
iDepth
=
input
.
depth
();
tpDstImg
->
iChannels
=
input
.
channels
();
//内存尺寸
int
_Size
=
tpDstImg
->
iWidth
*
tpDstImg
->
iHeight
*
tpDstImg
->
iChannels
*
sizeof
(
uint8_t
);
//分配初始化内存
tpDstImg
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
if
(
NULL
==
tpDstImg
->
vpImage
)
return
FUNC_NOT_ENOUGH_MEM
;
memset
(
tpDstImg
->
vpImage
,
0
,
_Size
);
//拷贝数据
memcpy
(
tpDstImg
->
vpImage
,
input
.
data
,
_Size
);
*
ipNum
=
static_cast
<
int
>
(
target
.
size
());
return
FUNC_OK
;
}
int
eyemInitClassifier
(
const
char
*
classifierConfigPath
,
const
char
*
classifierModelPath
,
int
ntype
)
{
try
{
pClassifier
=
cv
::
makePtr
<
YoloDarknet
>
(
classifierConfigPath
,
classifierModelPath
,
ntype
);
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
return
FUNC_CANNOT_CALC
;
}
return
FUNC_OK
;
}
int
eyemClassifier
(
EyemImage
tpImage
)
{
cv
::
Mat
src
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
if
(
src
.
empty
())
{
return
FUNC_IMAGE_NOT_EXIST
;
}
cv
::
Mat
input
;
int
incn
=
src
.
channels
();
if
(
incn
==
4
)
{
cv
::
cvtColor
(
src
,
input
,
cv
::
COLOR_BGRA2BGR
);
}
else
if
(
incn
==
1
)
{
cv
::
cvtColor
(
src
,
input
,
cv
::
COLOR_GRAY2BGR
);
//根据配置支持三通道图像
}
else
{
input
=
src
;
}
pClassifier
->
setInput
(
input
,
0.4
,
5
);
auto
predict
=
std
::
vector
<
int
>
();
auto
confidence
=
std
::
vector
<
float
>
();
auto
bbox
=
std
::
vector
<
cv
::
Rect
>
();
pClassifier
->
forward
(
predict
,
confidence
,
bbox
);
std
::
cout
<<
"run_end!"
<<
std
::
endl
;
return
FUNC_OK
;
}
eyemLib/eyemNNDetector.h
查看文件 @
da2526b
...
...
@@ -6,11 +6,12 @@
#define __EYEMNNDETECTOR_H
#include "eyemLib.h"
#include "yoloWrapper.h"
class
NNDetector
{
public
:
NNDetector
(
const
std
::
string
&
detector_config_path
=
""
,
const
std
::
string
&
detector_model_path
=
""
);
NNDetector
(
const
std
::
string
&
detector_config_path
,
const
std
::
string
&
detector_model_path
,
const
cv
::
Size
&
input_size
);
NNDetector
()
{};
std
::
vector
<
cv
::
Rect
>
detect
(
cv
::
InputArray
img
);
...
...
@@ -22,4 +23,6 @@ protected:
cv
::
Ptr
<
NNDetector
>
pNNDetector
;
cv
::
Ptr
<
YoloDarknet
>
pClassifier
;
#endif
/* __EYEMNNDETECTOR_H */
\ No newline at end of file
eyemLib/resnet.h
deleted
100644 → 0
查看文件 @
94b11f5
#pragma once
#ifndef __RESNET_LIB_H
#define __RESNET_LIB_H
#ifdef __DLLEXPORT
#define __DLL_EXP _declspec(dllexport) // 导出函数 - 生成dll文件时使用
#else
#define __DLL_EXP _declspec(dllimport) // 导入函数 -使用dll时使用
#endif // __DLLEXPORT
#include "ncnn/net.h"
#include "opencv2/opencv.hpp"
#include <vector>
#include <iostream>
#include<fstream>
#include <sstream>
#include <string>
#include <windows.h>
//typedef struct {
// void* vpImage; // 地址
// int iWidth; // 图像内存 x 方向大小
// int iHeight; // 图像内存 y 方向大小
// int iDepth; // 图像位深度(参见说明)
// int iChannels; // 图像通道数
//} EyemImage;
#ifndef MAKETYPE
#define MAKETYPE CV_MAKETYPE
#endif
//// 一般定义
//#define FUNC_OK 0 // 正常
//#define FUNC_NOT_ENOUGH_MEM -1 // 工作内存不足
//#define FUNC_ILLEGAL_ARGUMENT -2 // 参数不合适
//#define FUNC_IMAGE_NOT_EXIST -3 // 图像不存在
//#define FUNC_CANNOT_CALC -100 // 不可计算
//#define FUNC_CANNOT_USE -999 // 不可用
#ifdef __cplusplus
extern
"C"
{
#endif
__DLL_EXP
void
match_feature
(
const
char
*
input_path
,
EyemImage
image
,
char
*
part_number
);
__DLL_EXP
void
enroll_feature
(
const
char
*
input_path
,
const
char
*
output_path
);
#ifdef __cplusplus
}
#endif
#endif
eyemLib/yoloWrapper.cpp
查看文件 @
da2526b
#include "yoloWrapper.h"
int
YoloWrapper
::
init
(
const
std
::
string
&
detector_config_path
,
const
std
::
string
&
detector_model_path
)
{
const
std
::
string
&
detector_model_path
,
const
cv
::
Size
&
input_size
)
{
if
(
!
detector_config_path
.
empty
()
&&
!
detector_model_path
.
empty
())
{
//加载并初始化网络
net_
=
cv
::
dnn
::
readNet
(
detector_config_path
,
detector_model_path
);
net_
.
setPreferableBackend
(
cv
::
dnn
::
DNN_BACKEND_OPENCV
);
net_
.
setPreferableBackend
(
cv
::
dnn
::
DNN_TARGET_CPU
);
//设置输入尺寸
Size_
=
cv
::
Size
(
input_size
.
width
,
input_size
.
height
);
}
return
0
;
}
...
...
@@ -23,7 +25,7 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
}
//预处理图像
cv
::
Mat
blob
;
cv
::
dnn
::
blobFromImage
(
img
,
blob
,
1.0
/
255.0
,
cv
::
Size
(
960
,
960
)
);
cv
::
dnn
::
blobFromImage
(
img
,
blob
,
1.0
/
255.0
,
Size_
);
//为网络输入新值
net_
.
setInput
(
blob
);
...
...
@@ -73,4 +75,42 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
points
.
push_back
(
bbox
);
}
return
points
;
}
\ No newline at end of file
}
class
YoloDarknet
::
Impl
{
public
:
Impl
()
{}
~
Impl
()
{}
std
::
shared_ptr
<
DarkNet
>
net_
;
};
YoloDarknet
::
YoloDarknet
(
const
std
::
string
&
config_path
,
const
std
::
string
&
model_path
,
const
int
ntype
)
{
p
=
cv
::
makePtr
<
YoloDarknet
::
Impl
>
();
if
(
!
config_path
.
empty
()
&&
!
model_path
.
empty
())
{
p
->
net_
=
std
::
make_shared
<
DarkNet
>
();
p
->
net_
->
init
(
config_path
,
model_path
,
ntype
);
}
else
{
p
->
net_
=
NULL
;
}
}
void
YoloDarknet
::
setInput
(
cv
::
Mat
&
img
,
float
threshold
,
int
topk
)
{
topk_
=
topk
;
p
->
net_
->
setPreferableParams
(
threshold
,
topk
);
p
->
net_
->
forward
(
img
);
}
void
YoloDarknet
::
forward
(
std
::
vector
<
int
>
&
outputPredict
,
std
::
vector
<
float
>
&
outputConfidence
,
std
::
vector
<
cv
::
Rect
>
&
outputBoxes
)
{
auto
bbox
=
std
::
vector
<
cv
::
Rect
>
();
int
*
predicts
=
new
int
[
topk_
];
float
*
confidence
=
new
float
[
topk_
];
p
->
net_
->
getResult
(
predicts
,
confidence
,
&
bbox
);
for
(
int
top
=
0
;
top
<
topk_
;
top
++
)
outputPredict
.
push_back
(
predicts
[
top
]),
outputConfidence
.
push_back
(
confidence
[
top
]);
for
(
auto
&
box
:
bbox
)
{
outputBoxes
.
push_back
(
box
);
}
delete
[]
predicts
;
predicts
=
NULL
;
delete
[]
confidence
;
confidence
=
NULL
;
}
eyemLib/yoloWrapper.h
查看文件 @
da2526b
...
...
@@ -8,15 +8,34 @@
#include "opencv2/dnn.hpp"
#include "opencv2/imgproc.hpp"
#include <darknet.h>
#include <yolo_class.h>
class
YoloWrapper
{
public
:
YoloWrapper
()
{};
int
init
(
const
std
::
string
&
config_path
,
const
std
::
string
&
model_path
);
int
init
(
const
std
::
string
&
config_path
,
const
std
::
string
&
model_path
,
const
cv
::
Size
&
input_size
);
std
::
vector
<
cv
::
Rect
>
forward
(
cv
::
Mat
img
);
private
:
cv
::
Size
Size_
;
cv
::
dnn
::
Net
net_
;
};
class
YoloDarknet
{
public
:
YoloDarknet
(
const
std
::
string
&
config_path
=
""
,
const
std
::
string
&
model_path
=
""
,
const
int
ntype
=
0
);
YoloDarknet
()
{};
void
setInput
(
cv
::
Mat
&
img
,
float
threshold
,
int
topk
=
2
);
void
forward
(
std
::
vector
<
int
>
&
outputPredict
,
std
::
vector
<
float
>
&
outputConfidence
,
std
::
vector
<
cv
::
Rect
>
&
outputBoxes
);
private
:
int
topk_
=
0
;
protected
:
class
Impl
;
cv
::
Ptr
<
Impl
>
p
;
};
#endif
/* __YOLOWRAPPER_H */
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论