Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit f2f74c45
由
张士柳
编写于
2021-04-22 09:14:04 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
ce080e8c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
84 行增加
和
74 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemMisc.cpp
eyemLib-Sharp/EyemLib.cs
查看文件 @
f2f74c4
...
...
@@ -787,7 +787,7 @@ namespace eyemLib_Sharp
#
region
测试接口
//测试接口
[
DllImport
(
"eyemLib.dll"
,
CharSet
=
CharSet
.
None
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
int
eyem
AllMindImpl
(
EyemImage
tpImage
);
private
static
extern
int
eyem
LibImpl
(
EyemImage
tpImage
,
out
EyemImage
tpDstImg
);
#
endregion
#
region
日志功能
...
...
@@ -861,7 +861,7 @@ namespace eyemLib_Sharp
//flag = eyemImageAbs(image1, ref tpDstImg);
flag
=
eyem
AllMindImpl
(
image
);
flag
=
eyem
LibImpl
(
image
,
out
tpDstImg
);
#
region
Test
Blob
...
...
@@ -1017,12 +1017,12 @@ namespace eyemLib_Sharp
//获取用于制作模板的图像
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
Bitmap
bitmap
=
eyemCvtToBitmap
(
tpDstImg
);
//
if (bitmap != null)
//
{
//
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//
}
if
(
bitmap
!=
null
)
{
bitmap
.
Save
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
+
"\\ResOut\\"
+
file
);
}
//创建模板匹配模型
EyemRect
tpRoi2
=
new
EyemRect
();
...
...
eyemLib/eyemLib.h
查看文件 @
f2f74c4
...
...
@@ -859,7 +859,7 @@ extern "C" {
EXPORTS
int
eyemReleaseModel
(
IntPtr
&
hModelID
);
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
eyem
AllMindImpl
(
EyemImage
tpImage
);
EXPORTS
int
eyem
LibImpl
(
EyemImage
tpImage
,
EyemImage
*
tpDstImg
);
#ifdef __cplusplus
}
...
...
eyemLib/eyemLib.rc
查看文件 @
f2f74c4
此文件类型无法预览
eyemLib/eyemMisc.cpp
查看文件 @
f2f74c4
...
...
@@ -5989,62 +5989,17 @@ int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, i
//}
//移除低置信度边界框
static
void
postprocess
(
cv
::
Mat
&
frame
,
const
std
::
vector
<
cv
::
Mat
>&
outs
)
{
std
::
vector
<
int
>
classIds
;
//储存识别类的索引
std
::
vector
<
float
>
confidences
;
//储存置信度
std
::
vector
<
cv
::
Rect
>
boxes
;
//储存边框
for
(
size_t
i
=
0
;
i
<
outs
.
size
();
i
++
)
{
//从网络输出中扫描所有边界框
//保留高置信度选框
cv
::
Mat
tm
=
outs
[
i
];
//目标数据data:x,y,w,h为百分比,x,y为目标中心点坐标
float
*
data
=
(
float
*
)
outs
[
i
].
data
;
for
(
int
j
=
0
;
j
<
outs
[
i
].
rows
;
j
++
,
data
+=
outs
[
i
].
cols
)
{
cv
::
Mat
scores
=
outs
[
i
].
row
(
j
).
colRange
(
5
,
outs
[
i
].
cols
);
cv
::
Point
classIdPoint
;
double
confidence
;
//置信度
//取得最大分数值与索引
cv
::
minMaxLoc
(
scores
,
0
,
&
confidence
,
0
,
&
classIdPoint
);
if
(
confidence
>
0.5
)
{
int
centerX
=
(
int
)(
data
[
0
]
*
frame
.
cols
);
int
centerY
=
(
int
)(
data
[
1
]
*
frame
.
rows
);
int
width
=
(
int
)(
data
[
2
]
*
frame
.
cols
);
int
height
=
(
int
)(
data
[
3
]
*
frame
.
rows
);
int
left
=
centerX
-
width
/
2
;
int
top
=
centerY
-
height
/
2
;
classIds
.
push_back
(
classIdPoint
.
x
);
confidences
.
push_back
((
float
)
confidence
);
boxes
.
push_back
(
cv
::
Rect
(
left
,
top
,
width
,
height
));
}
}
}
//低置信度
std
::
vector
<
int
>
indices
;
//保存没有重叠边框的索引
//该函数用于抑制重叠边框
cv
::
dnn
::
NMSBoxes
(
boxes
,
confidences
,
0.5
,
0.4
,
indices
);
for
(
size_t
i
=
0
;
i
<
indices
.
size
();
i
++
)
{
int
idx
=
indices
[
i
];
cv
::
Rect
box
=
boxes
[
idx
];
//drawPred(classIds[idx], confidences[idx], box.x, box.y,
//box.x + box.width, box.y + box.height, frame);
cv
::
rectangle
(
frame
,
box
,
cv
::
Scalar
(
0
,
0
,
255
));
}
}
int
eyemAllMindImpl
(
EyemImage
tpImage
)
int
eyemLibImpl
(
EyemImage
tpImage
,
EyemImage
*
tpDstImg
)
{
cv
::
Mat
image
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
if
(
image
.
empty
())
return
FUNC_IMAGE_NOT_EXIST
;
if
(
image
.
channels
()
!=
3
)
{
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_BGRA2BGR
);
}
#pragma region wechat_qrcode
//cv::Ptr<wechat_qrcode::WeChatQRCode> detector;
...
...
@@ -6065,6 +6020,15 @@ int eyemAllMindImpl(EyemImage tpImage)
#pragma endregion
//加载类名
std
::
vector
<
std
::
string
>
classes
;
std
::
string
classFile
=
".
\\
darknet
\\
detect.names"
;
std
::
ifstream
ifs
(
classFile
.
c_str
());
std
::
string
line
;
while
(
std
::
getline
(
ifs
,
line
))
classes
.
push_back
(
line
);
//加载网络
cv
::
dnn
::
Net
net
=
cv
::
dnn
::
readNet
(
".
\\
darknet
\\
detect.cfg"
,
".
\\
darknet
\\
detect.weights"
);
net
.
setPreferableBackend
(
cv
::
dnn
::
DNN_BACKEND_OPENCV
);
...
...
@@ -6087,9 +6051,15 @@ int eyemAllMindImpl(EyemImage tpImage)
//为网络输入新值
net
.
setInput
(
blob
);
double
begin0
=
(
double
)
cv
::
getTickCount
();
//获取预测结果
std
::
vector
<
cv
::
Mat
>
outputBlobs
;
net
.
forward
(
outputBlobs
,
outBlobNames
);
std
::
cout
<<
((
double
)
cv
::
getTickCount
()
-
begin0
)
/
cv
::
getTickFrequency
()
<<
std
::
endl
;
std
::
vector
<
int
>
classIds
;
//储存识别类的索引
std
::
vector
<
float
>
confidences
;
//储存置信度
std
::
vector
<
cv
::
Rect
>
bboxes
;
//储存边框
for
(
int
n
=
0
;
n
<
outputBlobs
.
size
();
n
++
)
{
for
(
int
row
=
0
;
row
<
outputBlobs
[
n
].
rows
;
row
++
)
{
...
...
@@ -6101,31 +6071,71 @@ int eyemAllMindImpl(EyemImage tpImage)
//取得最大分数值与索引
cv
::
minMaxLoc
(
prob
,
0
,
&
confidence
,
0
,
&
classIdPoint
);
//如果置信度大于阈值
if
(
confidence
>
0.35
)
{
cv
::
Mat
dt
=
outputBlobs
[
n
];
cv
::
Mat
dt
=
outputBlobs
[
n
];
cv
::
Mat
x
=
outputBlobs
[
n
](
cv
::
Range
(
row
,
row
+
1
),
cv
::
Range
(
0
,
5
));
cv
::
Mat
x
=
outputBlobs
[
n
](
cv
::
Range
(
row
,
row
+
1
),
cv
::
Range
(
0
,
5
));
//如果置信度大于阈值
if
(
confidence
>
0.5
)
{
/*int centerX = (int)(data[0] * frame.cols);
int centerY = (int)(data[1] * frame.rows);
int width = (int)(data[2] * frame.cols);
int height = (int)(data[3] * frame.rows);
int left = centerX - width / 2;
int top = centerY - height / 2;*/
//classIds.push_back(classIdPoint.x);
//confidences.push_back((float)confidence);
//boxes.push_back(cv::Rect(left, top, width, height));
int
cx
=
cvRound
(
x
.
ptr
<
float
>
(
0
)[
0
]
*
(
float
)
image
.
cols
);
int
cy
=
cvRound
(
x
.
ptr
<
float
>
(
0
)[
1
]
*
(
float
)
image
.
rows
);
int
w
=
cvRound
(
x
.
ptr
<
float
>
(
0
)[
2
]
*
(
float
)
image
.
cols
);
int
h
=
cvRound
(
x
.
ptr
<
float
>
(
0
)[
3
]
*
(
float
)
image
.
rows
);
int
left
=
cx
-
w
/
2
;
int
top
=
cy
-
h
/
2
;
classIds
.
push_back
(
classIdPoint
.
x
);
confidences
.
push_back
((
float
)
confidence
);
bboxes
.
push_back
(
cv
::
Rect
(
left
,
top
,
w
,
h
));
}
}
}
//cv::Mat showMat;
//cv::cvtColor(image)
//绘制结果
postprocess
(
image
,
outputBlobs
);
std
::
vector
<
int
>
indices
;
//非极大值抑制
cv
::
dnn
::
NMSBoxes
(
bboxes
,
confidences
,
0.5
,
0.4
,
indices
);
for
(
int
i
=
0
;
i
<
indices
.
size
();
i
++
)
{
int
idx
=
indices
[
i
];
cv
::
Rect
bbox
=
bboxes
[
idx
]
&
cv
::
Rect
(
0
,
0
,
image
.
cols
,
image
.
rows
);
//标签
std
::
string
label
=
cv
::
format
(
"%.2f"
,
confidences
[
idx
]);
if
(
!
classes
.
empty
())
{
label
=
classes
[
classIds
[
idx
]]
+
":"
+
label
;
}
int
baseLine
;
cv
::
Size
labelSize
=
cv
::
getTextSize
(
label
,
cv
::
FONT_HERSHEY_SIMPLEX
,
0.5
,
1
,
&
baseLine
);
cv
::
Scalar
pal
(
0
,
255
,
0
);
cv
::
rectangle
(
image
,
bbox
,
pal
);
cv
::
rectangle
(
image
,
cv
::
Point
(
bbox
.
x
,
bbox
.
y
-
labelSize
.
height
-
baseLine
),
cv
::
Point
(
bbox
.
x
+
labelSize
.
width
,
bbox
.
y
),
pal
,
cv
::
FILLED
);
cv
::
putText
(
image
,
label
,
cv
::
Point
(
bbox
.
tl
().
x
,
bbox
.
tl
().
y
-
baseLine
),
cv
::
FONT_HERSHEY_SIMPLEX
,
0.5
,
cv
::
Scalar
(
0
,
0
,
0
),
1
);
}
///<输出计数结果标记图像
{
tpDstImg
->
iWidth
=
image
.
cols
;
tpDstImg
->
iHeight
=
image
.
rows
;
tpDstImg
->
iDepth
=
image
.
depth
();
tpDstImg
->
iChannels
=
image
.
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
,
image
.
data
,
_Size
);
}
return
FUNC_OK
;
}
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论