Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 0871eb39
由
张士柳
编写于
2021-12-01 09:13:59 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
da2526be
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
135 行增加
和
27 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib.sln
eyemLib/eyemLib.cpp
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemLib.vcxproj
eyemLib/eyemMisc.cpp
eyemLib/eyemMisc.h
eyemLib/eyemNNDetector.cpp
eyemLib/eyemNNDetector.h
eyemLib/yoloWrapper.cpp
eyemLib/yoloWrapper.h
eyemLib-Sharp/EyemLib.cs
查看文件 @
0871eb3
...
...
@@ -995,12 +995,28 @@ namespace eyemLib_Sharp
private
static
extern
int
eyemInitNNDetector
(
string
detectorConfigPath
,
string
detectorModelPath
,
int
iNetSizew
,
int
iNetSizeh
);
/// <summary>
/// 设置检测参数
/// </summary>
/// <param name="fConfidence">置信度</param>
/// <param name="fNMSThreshold">非极大值抑制阈值</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemNNDetectorParams
(
float
fConfidence
,
float
fNMSThreshold
);
/// <summary>
/// 目标检测器
/// </summary>
/// <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
,
out
EyemImage
tpDstImg
);
/// <summary>
/// 初始化darknet分类器
/// </summary>
/// <param name="classifierConfigPath">配置地址</param>
/// <param name="classifierModelPath">模型地址</param>
/// <param name="ntype">0 检测网络,1 分类网络</param>
/// <returns></returns>
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemInitClassifier
(
string
class
ifierConfigPath
,
string
class
ifierModelPath
,
int
ntype
);
...
...
@@ -1085,6 +1101,14 @@ namespace eyemLib_Sharp
//多功能工具
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemMulFuncTool
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
string
funcName
,
double
dThreshold
,
int
iNumToIgnore
,
ref
EyemOcsFXYR
tpCircle
,
out
EyemImage
tpDstImg
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemDetectCircleUseHough
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
EyemRect
limRoi
,
out
EyemOcsDXYR
tpCircle
,
out
EyemImage
tpDstImg
,
double
dp
,
double
dMinDist
,
double
dParam1
,
double
dParam2
,
double
dMinRadius
,
double
dMaxRadius
,
int
iMethod
=
3
,
bool
useValLimit
=
false
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
void
loadImage2Mem
(
string
key
,
EyemImage
tpImage
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
setProcessLevel
(
double
pl
);
#
endregion
#
region
测试专用接口
...
...
@@ -1094,6 +1118,8 @@ namespace eyemLib_Sharp
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemEdge1dRidgeDetection
(
EyemImage
tpImage
);
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyemBuildTrainFile
(
string
filePath
,
string
fileName
);
#
endregion
...
...
@@ -1119,9 +1145,15 @@ namespace eyemLib_Sharp
OnNewLogCallback
+=
new
TCallBack
(
EyemLib_OnNewLogCallback
);
eyemInitNNDataCodeModel
(
".\\darknet\\detect-tiny.cfg"
,
".\\darknet\\detect-tiny.weights"
,
".\\darknet\\sr.prototxt"
,
".\\darknet\\sr.caffemodel"
);
//setProcessLevel(2.0);
//EyemImage image_back = new EyemImage();
//eyemImageRead("D:\\Img20211028142015.png", -1, out image_back);
//loadImage2Mem("back", image_back);
eyemInitClassifier
(
"D:\\detect-tiny-tray.cfg"
,
"D:\\detect-tiny-tray.weights"
,
0
);
//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
()
...
...
@@ -1177,13 +1209,29 @@ namespace eyemLib_Sharp
sw
.
Restart
();
string
file
=
fileName
.
Split
(
new
string
[]
{
"\\"
},
StringSplitOptions
.
RemoveEmptyEntries
)[
2
];
//string[] fileNames = Directory.GetFiles(@"D:\训练数据集\点料机料盘识别\val_images", "*.png", SearchOption.AllDirectories);
//string[] fileNames = Directory.GetFiles(@"C:\Users\nzslw\PycharmProjects\pythonProject\venv\data\AntBee\test\ants", "*.jpg", SearchOption.AllDirectories);
//eyemBuildTrainFile(@"D:\darknet-master\build\darknet\x64\data\val_images", "D:/val.txt");
//return;
//foreach (var item in fileNames)
//{
// eyemBuildTrainFile(item, "D:\\标签识别\\" + item.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[4]);
//}
//return;
//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;
//for (int i = 0; i < fileNames.Length; i++)
//{
// string item = fileNames[i];
// string[] items = item.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
// FileInfo fi = new FileInfo(item);
// fi.MoveTo(@"D:\日志\" + (i+83).ToString() + ".png");
//}
//return;
//StreamWriter swr = new StreamWriter("D:\\val.txt", true);
//foreach (var item in random_shuffle)
//{
...
...
@@ -1226,7 +1274,7 @@ namespace eyemLib_Sharp
//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);
flag
=
eyemLibImpl
(
image
,
out
tpDstImg
);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
...
...
@@ -1234,7 +1282,7 @@ namespace eyemLib_Sharp
//}
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//
return;
return
;
//EyemImage templ, search;
//flag = eyemImageRead("D://批量测试图像//template.png", -1, out templ);
...
...
@@ -1454,9 +1502,14 @@ namespace eyemLib_Sharp
tpRoi
.
iWidth
=
image
.
iWidth
-
100
;
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);
//EyemOcsDXYR tpCircle = new EyemOcsDXYR();
//EyemRect limRoi = new EyemRect();
//limRoi.iXs = 222; limRoi.iYs = 222;
//limRoi.iWidth = 214;
//limRoi.iHeight = 214;
//flag = eyemDetectCircleUseHough(image, tpRoi, limRoi, out tpCircle, out tpDstImg, 1.0, 80, 100, 50, 28, 43, 3, true);
//////flag = eyemMulFuncTool(image, tpRoi, "__func1__", 65, 75, ref tpCircle, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
...
...
@@ -1521,20 +1574,21 @@ namespace eyemLib_Sharp
//如果对象供其他接口使用要先释放
//eyemImageFree(ref tpDstImg);
int
[]
ipReelNum
=
new
int
[
4
];
//"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_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);
//移除模板
//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.sln
查看文件 @
0871eb3
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.2
5420.1
VisualStudioVersion = 14.0.2
3107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eyemLib", "eyemLib\eyemLib.vcxproj", "{33D5F550-C799-4B05-8E14-ACA390DF5442}"
EndProject
...
...
eyemLib/eyemLib.cpp
查看文件 @
0871eb3
...
...
@@ -20,12 +20,23 @@ void setLogCallback(TCallback cb)
}
int
killProcessID
=
-
1
;
void
setSkipProcessID
(
int
pid
)
{
killProcessID
=
pid
;
}
double
processLevel
=
2.0
;
void
setProcessLevel
(
double
processLevel_
)
{
processLevel
=
processLevel_
;
}
std
::
map
<
std
::
string
,
EyemImage
>
imageMap
;
void
loadImage2Mem
(
const
char
*
key
,
EyemImage
tpImage
)
{
imageMap
.
insert
(
std
::
pair
<
std
::
string
,
EyemImage
>
(
std
::
string
(
key
),
tpImage
));
}
Logger
logger
;
int
main
(
int
argc
,
char
**
argv
)
{
...
...
eyemLib/eyemLib.h
查看文件 @
0871eb3
...
...
@@ -868,6 +868,7 @@ extern "C" {
// 函数接口
EXPORTS
int
eyemInitNNDetector
(
const
char
*
detectorConfigPath
,
const
char
*
detectorModelPath
,
int
iNetSizew
,
int
iNetSizeh
);
EXPORTS
int
eyemNNDetectorParams
(
float
fConfidence
,
float
fNMSThreshold
);
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
);
...
...
@@ -925,11 +926,13 @@ extern "C" {
EXPORTS
int
eyemTrackFeature
(
EyemImage
tpPrevImg
,
EyemImage
tpNextImg
,
EyemRect3
*
tpRois
,
int
iRoiNum
,
int
*
ipResults
,
EyemImage
*
tpDstImg
);
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
eyemDetectCircleUseHough
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
EyemRect
limRoi
,
EyemOcsDXYR
*
tpCircle
,
EyemImage
*
tpDstImg
,
double
dp
,
double
dMinDist
,
double
dParam1
,
double
dParam2
,
double
dMinRadius
,
double
dMaxRadius
,
int
iMethod
=
3
,
bool
useValLimit
=
false
);
EXPORTS
int
eyemMulFuncTool
(
EyemImage
tpImage
,
EyemRect
tpRoi
,
const
char
*
funcName
,
double
dThreshold
,
int
iNumToIgnore
,
EyemOcsFXYR
*
tpCircle
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemDrawLine
(
EyemImage
tpImage
,
EyemOcsDABC
tpLine
);
EXPORTS
int
eyemDrawCircle
(
EyemImage
tpImage
,
EyemOcsDXYR
tpCircle
);
EXPORTS
int
eyemDrawRectangle
(
EyemImage
tpImag
,
EyemRect
tpRect
);
EXPORTS
int
eyemBuildTrainFile
(
const
char
*
filePath
,
const
char
*
fileName
);
#ifdef __cplusplus
}
...
...
@@ -938,6 +941,12 @@ extern "C" {
// 跳过某接口执行
extern
"C"
__declspec
(
dllexport
)
void
setSkipProcessID
(
int
pid
);
//设置全局参数
extern
"C"
__declspec
(
dllexport
)
void
setProcessLevel
(
double
pl
);
// 加载图像到内存
extern
"C"
__declspec
(
dllexport
)
void
loadImage2Mem
(
const
char
*
key
,
EyemImage
tpImage
);
// 日志回调定义
typedef
void
(
__stdcall
*
TCallback
)(
const
char
*
msg
);
...
...
eyemLib/eyemLib.rc
查看文件 @
0871eb3
此文件类型无法预览
eyemLib/eyemLib.vcxproj
查看文件 @
0871eb3
...
...
@@ -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;
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>
<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>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
...
...
@@ -161,7 +161,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;
darknet.lib;pthreadVC2.lib;
%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
...
...
eyemLib/eyemMisc.cpp
查看文件 @
0871eb3
此文件的差异被折叠,
点击展开。
eyemLib/eyemMisc.h
查看文件 @
0871eb3
...
...
@@ -13,5 +13,7 @@ constexpr double c = PI / 180.;
extern
Logger
logger
;
extern
int
killProcessID
;
extern
double
processLevel
;
extern
std
::
map
<
std
::
string
,
EyemImage
>
imageMap
;
#endif
/* __EYEM_MISC_H */
eyemLib/eyemNNDetector.cpp
查看文件 @
0871eb3
...
...
@@ -4,10 +4,13 @@ class NNDetector::Impl {
public
:
Impl
()
{}
~
Impl
()
{}
//目标检测
std
::
vector
<
cv
::
Rect
>
detect
(
const
cv
::
Mat
&
img
);
//目标检测器
std
::
shared_ptr
<
YoloWrapper
>
detector_
;
//目标检测参数
float
_fConfidence
=
0.01
f
,
_fNMSThreshold
=
0.05
f
;
};
NNDetector
::
NNDetector
(
const
std
::
string
&
detector_config_path
,
...
...
@@ -23,6 +26,11 @@ NNDetector::NNDetector(const std::string & detector_config_path,
}
}
void
NNDetector
::
setInputParams
(
float
fConfidence
,
float
fNMSThreshold
)
{
p
->
_fConfidence
=
fConfidence
;
p
->
_fNMSThreshold
=
fNMSThreshold
;
}
std
::
vector
<
cv
::
Rect
>
NNDetector
::
detect
(
cv
::
InputArray
img
)
{
CV_Assert
(
!
img
.
empty
());
...
...
@@ -41,6 +49,7 @@ std::vector<cv::Rect> NNDetector::detect(cv::InputArray img)
}
std
::
vector
<
cv
::
Rect
>
NNDetector
::
Impl
::
detect
(
const
cv
::
Mat
&
img
)
{
detector_
->
setPreferableParams
(
_fConfidence
,
_fNMSThreshold
);
return
detector_
->
forward
(
img
);
}
...
...
@@ -56,6 +65,12 @@ int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModel
return
FUNC_OK
;
}
int
eyemNNDetectorParams
(
float
fConfidence
,
float
fNMSThreshold
)
{
pNNDetector
->
setInputParams
(
fConfidence
,
fNMSThreshold
);
return
FUNC_OK
;
}
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
();
...
...
@@ -106,6 +121,7 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, Eyem
return
FUNC_OK
;
}
#ifdef _DEBUG
int
eyemInitClassifier
(
const
char
*
classifierConfigPath
,
const
char
*
classifierModelPath
,
int
ntype
)
{
try
{
...
...
@@ -142,3 +158,4 @@ int eyemClassifier(EyemImage tpImage)
return
FUNC_OK
;
}
#endif
\ No newline at end of file
eyemLib/eyemNNDetector.h
查看文件 @
0871eb3
...
...
@@ -13,7 +13,8 @@ public:
NNDetector
(
const
std
::
string
&
detector_config_path
,
const
std
::
string
&
detector_model_path
,
const
cv
::
Size
&
input_size
);
NNDetector
()
{};
//ü
void
setInputParams
(
float
fConfidence
,
float
fNMSThreshold
);
std
::
vector
<
cv
::
Rect
>
detect
(
cv
::
InputArray
img
);
protected
:
...
...
@@ -23,6 +24,8 @@ protected:
cv
::
Ptr
<
NNDetector
>
pNNDetector
;
#ifdef _DEBUG
cv
::
Ptr
<
YoloDarknet
>
pClassifier
;
#endif
#endif
/* __EYEMNNDETECTOR_H */
\ No newline at end of file
eyemLib/yoloWrapper.cpp
查看文件 @
0871eb3
...
...
@@ -13,6 +13,12 @@ int YoloWrapper::init(const std::string& detector_config_path,
return
0
;
}
int
YoloWrapper
::
setPreferableParams
(
float
fConfidence
,
float
fNMSThreshold
)
{
this
->
confidence
=
fConfidence
;
this
->
NMSThreshold
=
fNMSThreshold
;
return
0
;
}
std
::
vector
<
cv
::
Rect
>
YoloWrapper
::
forward
(
cv
::
Mat
img
)
{
//获取输出层名称
auto
layerNames
=
net_
.
getLayerNames
();
...
...
@@ -42,13 +48,11 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
//置信度
cv
::
Mat
prob
=
outputBlobs
[
n
](
cv
::
Range
(
row
,
row
+
1
),
cv
::
Range
(
5
,
outputBlobs
[
n
].
cols
));
double
confidence
;
cv
::
Point
classIdPoint
;
//取得最大分数值与索引
cv
::
minMaxLoc
(
prob
,
0
,
&
confidence
,
0
,
&
classIdPoint
);
double
score
=
.0
;
cv
::
Point
classIdPoint
;
cv
::
minMaxLoc
(
prob
,
0
,
&
score
,
0
,
&
classIdPoint
);
//把可能的区域都算作进去
if
(
confidence
>
0.01
)
{
if
(
score
>
confidence
)
{
cv
::
Mat
dt
=
outputBlobs
[
n
](
cv
::
Range
(
row
,
row
+
1
),
cv
::
Range
(
0
,
5
));
int
cx
=
cvRound
(
dt
.
ptr
<
float
>
(
0
)[
0
]
*
(
float
)
img
.
cols
);
...
...
@@ -59,14 +63,14 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
int
left
=
cx
-
w
/
2
;
int
top
=
cy
-
h
/
2
;
confidences
.
push_back
((
float
)
confidenc
e
);
confidences
.
push_back
((
float
)
scor
e
);
bboxes
.
push_back
(
cv
::
Rect
(
left
,
top
,
w
,
h
));
}
}
}
std
::
vector
<
int
>
indices
;
//非极大值抑制
cv
::
dnn
::
NMSBoxes
(
bboxes
,
confidences
,
0.01
f
,
0.05
f
,
indices
);
cv
::
dnn
::
NMSBoxes
(
bboxes
,
confidences
,
confidence
,
NMSThreshold
,
indices
);
//裁剪区域
auto
points
=
std
::
vector
<
cv
::
Rect
>
();
for
(
int
i
=
0
;
i
<
indices
.
size
();
i
++
)
{
...
...
@@ -77,6 +81,8 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
return
points
;
}
#ifdef _DEBUG
class
YoloDarknet
::
Impl
{
public
:
Impl
()
{}
...
...
@@ -114,3 +120,4 @@ void YoloDarknet::forward(std::vector<int> &outputPredict, std::vector<float> &o
}
delete
[]
predicts
;
predicts
=
NULL
;
delete
[]
confidence
;
confidence
=
NULL
;
}
#endif
eyemLib/yoloWrapper.h
查看文件 @
0871eb3
...
...
@@ -8,20 +8,25 @@
#include "opencv2/dnn.hpp"
#include "opencv2/imgproc.hpp"
#ifdef _DEBUG
#include <darknet.h>
#include <yolo_class.h>
#endif
class
YoloWrapper
{
public
:
YoloWrapper
()
{};
int
init
(
const
std
::
string
&
config_path
,
const
std
::
string
&
model_path
,
const
cv
::
Size
&
input_size
);
int
setPreferableParams
(
float
fConfidence
,
float
fNMSThreshold
);
//置信度,非极大值抑制阈值
std
::
vector
<
cv
::
Rect
>
forward
(
cv
::
Mat
img
);
private
:
cv
::
Size
Size_
;
float
confidence
=
0
.
01
f
,
NMSThreshold
=
0
.
05
f
;
cv
::
dnn
::
Net
net_
;
};
#ifdef _DEBUG
class
YoloDarknet
{
public
:
...
...
@@ -36,6 +41,6 @@ protected:
class
Impl
;
cv
::
Ptr
<
Impl
>
p
;
};
#endif
#endif
/* __YOLOWRAPPER_H */
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论