Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
1688582d
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1688582d
编写于
10月 13, 2020
作者:
B
BohaoWu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for complier.
上级
13c98ad8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
28 addition
and
91 deletion
+28
-91
core/preprocess/CMakeLists.txt
core/preprocess/CMakeLists.txt
+1
-0
core/preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h
.../preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h
+1
-1
core/preprocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp
...rocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp
+1
-1
core/preprocess/nvdec-extractframe/src/main.cpp
core/preprocess/nvdec-extractframe/src/main.cpp
+0
-88
python/paddle_serving_app/reader/test_preprocess.py
python/paddle_serving_app/reader/test_preprocess.py
+25
-1
未找到文件。
core/preprocess/CMakeLists.txt
浏览文件 @
1688582d
add_subdirectory
(
hwvideoframe
)
add_subdirectory
(
nvdec-extractframe
)
core/preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h
浏览文件 @
1688582d
...
...
@@ -82,7 +82,7 @@ class ExtractFrameJpeg : public ExtractFrameBase {
int
jpeg_encode
(
uint8_t
*
p_image
,
int
width
,
int
height
,
const
FrameResult
&
result
);
FrameResult
&
result
);
nvjpegHandle_t
_nv_jpeg_handler
;
nvjpegEncoderState_t
_nv_enc_state
;
nvjpegEncoderParams_t
_nv_enc_params
;
...
...
core/preprocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp
浏览文件 @
1688582d
...
...
@@ -20,7 +20,7 @@
simplelogger
::
Logger
*
logger
=
simplelogger
::
LoggerFactory
::
CreateConsoleLogger
();
PYBIND11_MODULE
(
hwextract
,
m
)
{
PYBIND11_MODULE
(
lib
hwextract
,
m
)
{
pybind11
::
class_
<
baidu
::
xvision
::
ExtractFrameJpeg
>
(
m
,
"HwExtractFrameJpeg"
)
.
def
(
pybind11
::
init
<
int
>
())
.
def
(
"init_handler"
,
&
baidu
::
xvision
::
ExtractFrameJpeg
::
init
)
...
...
core/preprocess/nvdec-extractframe/src/main.cpp
已删除
100644 → 0
浏览文件 @
13c98ad8
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include <iomanip>
#include <memory>
#include <sstream>
#include <string>
#include "ExtractFrameBGRARaw.h"
#include "ExtractFrameJpeg.h"
simplelogger
::
Logger
*
g_logger
=
simplelogger
::
LoggerFactory
::
CreateConsoleLogger
();
/**
* @Name:
* image_file_writer
* @Feature:
* write image data to file
* @params
* img_data: image_data
* file_path: image_file stored path
* prefix: image_name prefix
* extension: image_file extension name
* @returns
* void
**/
void
inline
image_file_writer
(
const
baidu
::
xvision
::
FrameResult
&
img_data
,
std
::
string
file_path
,
std
::
string
prefix
,
std
::
string
extension
=
"raw"
)
{
std
::
ofstream
f_out
(
file_path
+
"/"
+
prefix
+
"."
+
extension
,
std
::
ios
::
binary
|
std
::
ios
::
out
);
f_out
.
write
(
reinterpret_cast
<
char
*>
(
img_data
.
get_frame
()),
img_data
.
len
());
f_out
.
close
();
}
bool
parse_cmd_line
(
int
argc
,
const
char
*
const
argv
[])
{
if
(
argc
<=
3
)
{
LOG
(
FATAL
)
<<
"params error, eg: ./hw_frame_extract /path/to/mp4.mp4 "
"/output/path bgra|jpeg"
;
return
false
;
}
if
(
!
strcmp
(
argv
[
3
],
"bgra"
)
&&
!
strcmp
(
argv
[
3
],
"jpeg"
))
{
LOG
(
FATAL
)
<<
"unsupported output file format"
;
return
false
;
}
return
true
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
!
parse_cmd_line
(
argc
,
argv
))
{
return
-
1
;
}
baidu
::
xvision
::
ExtractFrameBase
*
extract_frame_handler
(
nullptr
);
if
(
strcmp
(
"bgra"
,
argv
[
3
])
==
0
)
{
extract_frame_handler
=
new
baidu
::
xvision
::
ExtractFrameBGRARaw
();
}
else
{
extract_frame_handler
=
new
baidu
::
xvision
::
ExtractFrameJpeg
();
}
auto
init_result
=
extract_frame_handler
->
init
();
auto
result
=
extract_frame_handler
->
extract_frame
(
argv
[
1
],
1
,
200
);
int
frame_index
=
0
;
std
::
stringstream
ss
;
for
(
auto
result_iter
=
result
.
begin
();
result_iter
!=
result
.
end
();
result_iter
++
)
{
ss
<<
std
::
setw
(
5
)
<<
std
::
setfill
(
'0'
)
<<
frame_index
;
image_file_writer
(
*
result_iter
,
argv
[
2
],
"image_"
+
std
::
to_string
(
result_iter
->
width
())
+
"_"
+
std
::
to_string
(
result_iter
->
height
())
+
"_"
+
ss
.
str
(),
argv
[
3
]);
result_iter
->
free_memory
();
frame_index
++
;
ss
.
str
(
""
);
}
return
0
;
}
python/paddle_serving_app/reader/test_preprocess.py
浏览文件 @
1688582d
...
...
@@ -16,9 +16,10 @@
import
unittest
import
sys
import
numpy
as
np
import
cv2
from
paddle_serving_app.reader
import
Sequential
,
Resize
,
File2Image
import
libgpupreprocess
as
pp
import
libhwextract
class
TestOperators
(
unittest
.
TestCase
):
"""
...
...
@@ -147,6 +148,29 @@ class TestOperators(unittest.TestCase):
img_resize_diff
=
img_vis
-
img
self
.
assertEqual
(
np
.
all
(
img_resize_diff
==
0
),
True
)
def
test_extract_frame
(
self
):
handler
=
libhwextract
.
HwExtractFrameJpeg
(
0
)
# 0, gpu card index
# if you want BGRA Raw Data, plz use HwExtractBGRARaw
handler
.
init_handler
()
# init once can decode many videos
video_file_name
=
sys
.
argv
[
1
]
# for now just support h264 codec
frame_list
=
[]
try
:
frame_list
=
handler
.
extract_frame
(
video_file_name
,
1
)
# specifiy file name and fps you want to extract, 0 for all frame
except
Exception
as
e_frame
:
print
(
"Failed to cutframe, exception[%s]"
%
(
e_frame
))
sys
.
exit
(
1
)
for
item
in
frame_list
:
print
"i am a item in frame_list"
# do something, for instance
jpeg_array
=
np
.
array
(
item
,
copy
=
False
)
img
=
cv2
.
imdecode
(
jpeg_array
,
cv2
.
IMREAD_COLOR
)
cv2
.
imwrite
(
'1.jpg'
,
img
)
item
.
free_memory
()
# have to release memor
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录