Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit ce080e8c
由
张士柳
编写于
2021-04-20 17:30:01 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
ee8a6917
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
149 行增加
和
27 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/Program.cs
eyemLib/eyemMisc.cpp
eyemLib-Sharp/EyemLib.cs
查看文件 @
ce080e8
...
@@ -861,7 +861,7 @@ namespace eyemLib_Sharp
...
@@ -861,7 +861,7 @@ namespace eyemLib_Sharp
//flag = eyemImageAbs(image1, ref tpDstImg);
//flag = eyemImageAbs(image1, ref tpDstImg);
//
flag = eyemAllMindImpl(image);
flag
=
eyemAllMindImpl
(
image
);
#
region
Test
Blob
#
region
Test
Blob
...
@@ -1073,19 +1073,19 @@ namespace eyemLib_Sharp
...
@@ -1073,19 +1073,19 @@ namespace eyemLib_Sharp
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",""
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",""
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), 0.1, "", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), 0.1, "", 100, 7, ref pNumObj, out tpDstImg);
eyemCountObjectE
(
image
,
tpRoi
,
fileName
,
ref
pNumObj
,
out
tpDstImg
);
//
eyemCountObjectE(image, tpRoi, fileName, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//移除模板
//移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
Bitmap
bitmap
=
eyemCvtToBitmap
(
tpDstImg
);
//
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if
(
bitmap
!=
null
)
//
if (bitmap != null)
{
//
{
bitmap
.
Save
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
+
"\\ResOut\\"
+
file
);
//
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
}
//
}
////<解码测试
////<解码测试
//int ipNum; EyemBarCode* tpResults;
//int ipNum; EyemBarCode* tpResults;
...
...
eyemLib-Sharp/Program.cs
查看文件 @
ce080e8
...
@@ -17,25 +17,26 @@ namespace eyemLib_Sharp
...
@@ -17,25 +17,26 @@ namespace eyemLib_Sharp
}
}
//初始化
//初始化
//
EyemLib.Init();
EyemLib
.
Init
();
string
[]
fileNames
=
Directory
.
GetFiles
(
@"D:\批量测试图像\", "
*.*
", SearchOption.AllDirectories);
string
[]
fileNames
=
Directory
.
GetFiles
(
@"D:\批量测试图像\", "
*.*
", SearchOption.AllDirectories);
for
(
int
j
=
0
;
j
<
1
;
j
++)
{
ParallelOptions
po
=
new
ParallelOptions
();
po
.
MaxDegreeOfParallelism
=
1
;
Parallel
.
ForEach
(
fileNames
,
po
,
fn
=>
{
EyemLib
.
eyemReadImageTool
(
fn
);
});
Console
.
Write
(
"请按任意键继续。。。"
);
}
//for
each (var item in fileNames
)
//for
(int j = 0; j < 1; j++
)
//{
//{
// EyemLib.eyemReadImageTool(item);
// ParallelOptions po = new ParallelOptions();
// po.MaxDegreeOfParallelism = 1;
// Parallel.ForEach(fileNames, po, fn =>
// {
// EyemLib.eyemReadImageTool(fn);
// });
// Console.Write("请按任意键继续。。。");
//}
//}
foreach
(
var
item
in
fileNames
)
{
EyemLib
.
eyemReadImageTool
(
item
);
}
//for (int i = 0; i < 1; i++)
//for (int i = 0; i < 1; i++)
//{
//{
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
...
@@ -69,7 +70,7 @@ namespace eyemLib_Sharp
...
@@ -69,7 +70,7 @@ namespace eyemLib_Sharp
//EyemLib.eyemReleaseModelE(ref hModelID);
//EyemLib.eyemReleaseModelE(ref hModelID);
//
EyemLib.Free();
EyemLib
.
Free
();
Console
.
Write
(
"请按任意键继续。。。"
);
Console
.
Write
(
"请按任意键继续。。。"
);
Console
.
ReadKey
();
Console
.
ReadKey
();
...
...
eyemLib/eyemMisc.cpp
查看文件 @
ce080e8
...
@@ -5970,6 +5970,74 @@ int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, i
...
@@ -5970,6 +5970,74 @@ int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, i
return
FUNC_OK
;
return
FUNC_OK
;
}
}
////绘制预测边界框
//static void drawPred(int classId, float conf, int left, int top, int right, int bottom, cv::Mat& frame) {
// //绘制边界框
// cv::rectangle(frame, cv::Point(left, top), cv::Point(right, bottom), cv::Scalar(255, 178, 50), 3);
//
// std::string label = cv::format("%.2f", conf);
// if (!classes.empty()) {
// CV_Assert(classId < (int)classes.size());
// label = classes[classId] + ":" + label;//边框上的类别标签与置信度
// }
// //绘制边界框上的标签
// int baseLine;
// cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
// top = std::max(top, labelSize.height);
// cv::rectangle(frame, cv::Point(left, top - round(1.5*labelSize.height)), cv::Point(left + round(1.5*labelSize.width), top + baseLine), cv::Scalar(255, 255, 255), cv::FILLED);
// cv::putText(frame, label, cv::Point(left, top), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(0, 0, 0), 1);
//}
//移除低置信度边界框
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
eyemAllMindImpl
(
EyemImage
tpImage
)
{
{
cv
::
Mat
image
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
cv
::
Mat
image
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
...
@@ -5997,14 +6065,67 @@ int eyemAllMindImpl(EyemImage tpImage)
...
@@ -5997,14 +6065,67 @@ int eyemAllMindImpl(EyemImage tpImage)
#pragma endregion
#pragma endregion
cv
::
Mat
sum
,
sqsum
,
templ
;
//加载网络
cv
::
Scalar
templMean
,
templSdv
;
cv
::
dnn
::
Net
net
=
cv
::
dnn
::
readNet
(
".
\\
darknet
\\
detect.cfg"
,
".
\\
darknet
\\
detect.weights"
);
double
*
q0
=
0
,
*
q1
=
0
,
*
q2
=
0
,
*
q3
=
0
;
net
.
setPreferableBackend
(
cv
::
dnn
::
DNN_BACKEND_OPENCV
);
double
templNorm
=
0
,
templSum2
=
0
;
net
.
setPreferableBackend
(
cv
::
dnn
::
DNN_TARGET_CPU
);
//获取输出层名称
auto
layerNames
=
net
.
getLayerNames
();
std
::
vector
<
int
>
outLayers
=
net
.
getUnconnectedOutLayers
();
std
::
vector
<
std
::
string
>
outBlobNames
(
outLayers
.
size
());
for
(
int
i
=
0
;
i
<
outLayers
.
size
();
i
++
)
{
outBlobNames
[
i
]
=
layerNames
[
outLayers
[
i
]
-
1
];
}
cv
::
integral
(
image
,
sum
,
sqsum
,
CV_64F
);
//预处理图像
cv
::
meanStdDev
(
templ
,
templMean
,
templSdv
);
cv
::
Mat
blob
;
cv
::
dnn
::
blobFromImage
(
image
,
blob
,
1
/
255.
,
cv
::
Size
(
416
,
416
));
//为网络输入新值
net
.
setInput
(
blob
);
//获取预测结果
std
::
vector
<
cv
::
Mat
>
outputBlobs
;
net
.
forward
(
outputBlobs
,
outBlobNames
);
for
(
int
n
=
0
;
n
<
outputBlobs
.
size
();
n
++
)
{
for
(
int
row
=
0
;
row
<
outputBlobs
[
n
].
rows
;
row
++
)
{
//置信度
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
);
cv
::
Mat
dt
=
outputBlobs
[
n
];
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));
}
}
}
//cv::Mat showMat;
//cv::cvtColor(image)
//绘制结果
postprocess
(
image
,
outputBlobs
);
return
FUNC_OK
;
return
FUNC_OK
;
}
}
\ No newline at end of file
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论