Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
RetinaFace_migraphx
Commits
89618e74
Commit
89618e74
authored
Jun 12, 2023
by
liucong
Browse files
精简代码
parent
ce8766c6
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
28 deletions
+36
-28
Src/main.cpp
Src/main.cpp
+36
-28
No files found.
Src/main.cpp
View file @
89618e74
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Sample.h>
#include <SimpleLog.h>
#include <Filesystem.h>
#include <RetinaFace.h>
void
MIGraphXSamplesUsage
(
char
*
programName
)
int
main
(
)
{
printf
(
"Usage : %s <index>
\n
"
,
programName
);
printf
(
"index:
\n
"
);
printf
(
"
\t
0) RetinaFace sample.
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
||
argc
>
2
)
{
MIGraphXSamplesUsage
(
argv
[
0
]);
return
-
1
;
}
if
(
!
strncmp
(
argv
[
1
],
"-h"
,
2
))
// 创建RetinaFace检测器
migraphxSamples
::
DetectorRetinaFace
detector
;
migraphxSamples
::
InitializationParameterOfDetector
initParamOfDetectorRetinaFace
;
initParamOfDetectorRetinaFace
.
configFilePath
=
CONFIG_FILE
;
migraphxSamples
::
ErrorCode
errorCode
=
detector
.
Initialize
(
initParamOfDetectorRetinaFace
);
if
(
errorCode
!=
migraphxSamples
::
SUCCESS
)
{
MIGraphXSamplesUsage
(
argv
[
0
]
);
return
0
;
LOG_ERROR
(
stdout
,
"fail to initialize detector!
\n
"
);
exit
(
-
1
)
;
}
switch
(
*
argv
[
1
])
LOG_INFO
(
stdout
,
"succeed to initialize detector
\n
"
);
// 读取测试图片
cv
::
Mat
srcImage
=
cv
::
imread
(
"../Resource/Images/FaceDetect.jpg"
,
1
);
// 推理
std
::
vector
<
migraphxSamples
::
ResultOfDetection
>
predictions
;
double
time1
=
cv
::
getTickCount
();
detector
.
Detect
(
srcImage
,
predictions
);
double
time2
=
cv
::
getTickCount
();
double
elapsedTime
=
(
time2
-
time1
)
*
1000
/
cv
::
getTickFrequency
();
LOG_INFO
(
stdout
,
"inference time:%f ms
\n
"
,
elapsedTime
);
// 获取推理结果
LOG_INFO
(
stdout
,
"========== Detection Results ==========
\n
"
);
for
(
int
i
=
0
;
i
<
predictions
.
size
();
++
i
)
{
case
'0'
:
{
Sample_DetectorRetinaFace
();
break
;
}
default
:
{
MIGraphXSamplesUsage
(
argv
[
0
]);
break
;
}
migraphxSamples
::
ResultOfDetection
result
=
predictions
[
i
];
cv
::
rectangle
(
srcImage
,
result
.
boundingBox
,
cv
::
Scalar
(
0
,
255
,
255
),
2
);
LOG_INFO
(
stdout
,
"box:%d %d %d %d,label:%d,confidence:%f
\n
"
,
predictions
[
i
].
boundingBox
.
x
,
predictions
[
i
].
boundingBox
.
y
,
predictions
[
i
].
boundingBox
.
width
,
predictions
[
i
].
boundingBox
.
height
,
predictions
[
i
].
classID
,
predictions
[
i
].
confidence
);
}
cv
::
imwrite
(
"Result.jpg"
,
srcImage
);
LOG_INFO
(
stdout
,
"Detection results have been saved to ./Result.jpg
\n
"
);
return
0
;
}
\ No newline at end of file
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment