Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
9ca42bea
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9ca42bea
编写于
4月 11, 2018
作者:
G
ghdawn31
提交者:
xiaohuitu
4月 11, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
perception: put yuv2bgr in gpu (#3817)
* put yuv2bgr in gpu * perception: put yuv2bgr in gpu
上级
78214f8e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
11 deletion
+93
-11
modules/perception/cuda_util/util.cu
modules/perception/cuda_util/util.cu
+86
-1
modules/perception/cuda_util/util.h
modules/perception/cuda_util/util.h
+2
-1
modules/perception/obstacle/onboard/camera_process_subnode.cc
...les/perception/obstacle/onboard/camera_process_subnode.cc
+5
-9
未找到文件。
modules/perception/cuda_util/util.cu
浏览文件 @
9ca42bea
...
...
@@ -14,7 +14,10 @@
* limitations under the License.
*****************************************************************************/
#include "util.h"
#include "modules/perception/cuda_util/util.h"
#include <thrust/host_vector.h>
#include <thrust/sequence.h>
#include <thrust/device_vector.h>
namespace
apollo
{
namespace
perception
{
...
...
@@ -171,6 +174,88 @@ void resize(cv::Mat frame, caffe::Blob<float> *dst, std::shared_ptr <caffe::Sync
width
,
fx
,
fy
,
mean_b
,
mean_g
,
mean_r
,
scale
);
}
/******************/
struct
index_functor
:
public
thrust
::
unary_function
<
int
,
int
>
{
int
div_
;
int
mul_
;
int
offset_
;
index_functor
(
int
div
,
int
mul
,
int
offset
)
:
div_
(
div
),
mul_
(
mul
),
offset_
(
offset
)
{}
__host__
__device__
int
operator
()(
const
int
&
index
)
{
return
(
index
/
div_
)
*
mul_
+
offset_
;
}
};
struct
yuv2bgr_functor
{
template
<
typename
Tuple
>
__host__
__device__
void
operator
()(
Tuple
t
)
{
const
uint8_t
&
y
=
thrust
::
get
<
0
>
(
t
);
const
uint8_t
&
u
=
thrust
::
get
<
1
>
(
t
);
const
uint8_t
&
v
=
thrust
::
get
<
2
>
(
t
);
uint8_t
&
b
=
thrust
::
get
<
3
>
(
t
);
uint8_t
&
g
=
thrust
::
get
<
4
>
(
t
);
uint8_t
&
r
=
thrust
::
get
<
5
>
(
t
);
const
int
y2
=
(
int
)
y
;
const
int
u2
=
(
int
)
u
-
128
;
const
int
v2
=
(
int
)
v
-
128
;
float
r2
=
y2
+
(
1.4065
*
v2
);
float
g2
=
y2
-
(
0.3455
*
u2
)
-
(
0.7169
*
v2
);
float
b2
=
y2
+
(
2.041
*
u2
);
// Cap the values.
r
=
clip_value
(
r2
);
g
=
clip_value
(
g2
);
b
=
clip_value
(
b2
);
}
__host__
__device__
inline
uint8_t
clip_value
(
float
v
)
{
v
=
v
<
0
?
0
:
v
;
return
v
>
255
?
255
:
v
;
}
};
typedef
thrust
::
device_vector
<
int
>::
iterator
IntegerIterator
;
void
yuyv2bgr
(
const
uint8_t
*
yuv_data
,
uint8_t
*
bgr_data
,
const
int
pixel_num
)
{
thrust
::
device_vector
<
uint8_t
>
bgr
(
pixel_num
*
3
);
thrust
::
device_vector
<
uint8_t
>
yuv
(
yuv_data
,
yuv_data
+
pixel_num
*
2
);
thrust
::
counting_iterator
<
int
>
first
(
0
);
thrust
::
counting_iterator
<
int
>
last
(
yuv
.
size
()
/
2
);
thrust
::
for_each
(
thrust
::
make_zip_iterator
(
thrust
::
make_tuple
(
thrust
::
make_permutation_iterator
(
yuv
.
begin
(),
thrust
::
make_transform_iterator
(
first
,
index_functor
(
1
,
2
,
0
))),
thrust
::
make_permutation_iterator
(
yuv
.
begin
(),
thrust
::
make_transform_iterator
(
first
,
index_functor
(
2
,
4
,
1
))),
thrust
::
make_permutation_iterator
(
yuv
.
begin
(),
thrust
::
make_transform_iterator
(
first
,
index_functor
(
2
,
4
,
3
))),
thrust
::
make_permutation_iterator
(
bgr
.
begin
(),
thrust
::
make_transform_iterator
(
first
,
index_functor
(
1
,
3
,
0
))),
thrust
::
make_permutation_iterator
(
bgr
.
begin
(),
thrust
::
make_transform_iterator
(
first
,
index_functor
(
1
,
3
,
1
))),
thrust
::
make_permutation_iterator
(
bgr
.
begin
(),
thrust
::
make_transform_iterator
(
first
,
index_functor
(
1
,
3
,
2
))))),
thrust
::
make_zip_iterator
(
thrust
::
make_tuple
(
thrust
::
make_permutation_iterator
(
yuv
.
begin
(),
thrust
::
make_transform_iterator
(
last
,
index_functor
(
1
,
2
,
0
))),
thrust
::
make_permutation_iterator
(
yuv
.
begin
(),
thrust
::
make_transform_iterator
(
last
,
index_functor
(
2
,
4
,
1
))),
thrust
::
make_permutation_iterator
(
yuv
.
begin
(),
thrust
::
make_transform_iterator
(
last
,
index_functor
(
2
,
4
,
3
))),
thrust
::
make_permutation_iterator
(
bgr
.
begin
(),
thrust
::
make_transform_iterator
(
last
,
index_functor
(
1
,
3
,
0
))),
thrust
::
make_permutation_iterator
(
bgr
.
begin
(),
thrust
::
make_transform_iterator
(
last
,
index_functor
(
1
,
3
,
1
))),
thrust
::
make_permutation_iterator
(
bgr
.
begin
(),
thrust
::
make_transform_iterator
(
last
,
index_functor
(
1
,
3
,
2
))))),
yuv2bgr_functor
());
cudaMemcpy
(
bgr_data
,
thrust
::
raw_pointer_cast
(
bgr
.
data
()),
pixel_num
*
3
,
cudaMemcpyDeviceToHost
);
}
}
}
modules/perception/cuda_util/util.h
浏览文件 @
9ca42bea
...
...
@@ -59,12 +59,13 @@ int divup(int a, int b);
void
resize
(
cv
::
Mat
frame
,
caffe
::
Blob
<
float
>
*
dst
,
std
::
shared_ptr
<
caffe
::
SyncedMemory
>
src_gpu
,
int
start_axis
);
// resize with mean and scale
void
resize
(
cv
::
Mat
frame
,
caffe
::
Blob
<
float
>
*
dst
,
std
::
shared_ptr
<
caffe
::
SyncedMemory
>
src_gpu
,
int
start_axis
,
const
float
mean_b
,
const
float
mean_g
,
const
float
mean_r
,
const
float
scale
);
void
yuyv2bgr
(
const
uint8_t
*
yuv
,
uint8_t
*
rgb
,
const
int
pixel_num
);
}
// namespace perception
}
// namespace apollo
...
...
modules/perception/obstacle/onboard/camera_process_subnode.cc
浏览文件 @
9ca42bea
...
...
@@ -15,6 +15,7 @@
*****************************************************************************/
#include "modules/perception/obstacle/onboard/camera_process_subnode.h"
#include "modules/perception/cuda_util/util.h"
namespace
apollo
{
namespace
perception
{
...
...
@@ -155,22 +156,17 @@ void CameraProcessSubnode::ChassisCallback(
bool
CameraProcessSubnode
::
MessageToMat
(
const
sensor_msgs
::
Image
&
msg
,
cv
::
Mat
*
img
)
{
cv
::
Mat
cv_img
;
*
img
=
cv
::
Mat
(
msg
.
height
,
msg
.
width
,
CV_8UC3
);
int
pixel_num
=
msg
.
width
*
msg
.
height
;
if
(
msg
.
encoding
.
compare
(
"yuyv"
)
==
0
)
{
unsigned
char
*
yuv
=
(
unsigned
char
*
)
&
(
msg
.
data
[
0
]);
cv_img
=
cv
::
Mat
(
msg
.
height
,
msg
.
width
,
CV_8UC3
);
traffic_light
::
Yuyv2rgb
(
yuv
,
cv_img
.
data
,
msg
.
height
*
msg
.
width
);
cv
::
cvtColor
(
cv_img
,
cv_img
,
CV_RGB2BGR
);
yuyv2bgr
(
yuv
,
img
->
data
,
pixel_num
);
}
else
{
cv_bridge
::
CvImagePtr
cv_ptr
=
cv_bridge
::
toCvCopy
(
msg
,
sensor_msgs
::
image_encodings
::
BGR8
);
cv_
img
=
cv_ptr
->
image
;
*
img
=
cv_ptr
->
image
;
}
if
(
cv_img
.
rows
!=
image_height_
||
cv_img
.
cols
!=
image_width_
)
{
cv
::
resize
(
cv_img
,
cv_img
,
cv
::
Size
(
image_width_
,
image_height_
));
}
*
img
=
cv_img
.
clone
();
return
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录