Apollo 10.0
自动驾驶开放平台
image_data_operations_npp.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
18namespace apollo {
19namespace perception {
20namespace camera {
21
23 NppStatus status;
24 NppiSize roi;
25 roi.height = image.rows();
26 roi.width = image.cols();
27 blob->Reshape({1, roi.height, roi.width, image.channels()});
28 if (image.channels() == 1) {
29 status = nppiCopy_8u_C1R(
30 image.gpu_data(), image.width_step(), blob->mutable_gpu_data(),
31 blob->count(2) * static_cast<int>(sizeof(uint8_t)), roi);
32 } else {
33 status = nppiCopy_8u_C3R(
34 image.gpu_data(), image.width_step(), blob->mutable_gpu_data(),
35 blob->count(2) * static_cast<int>(sizeof(uint8_t)), roi);
36 }
37 if (status != NPP_SUCCESS) {
38 return false;
39 }
40 return true;
41}
42
44 const int src_width, const int src_height,
45 const float coeffs[3]) {
46 NppStatus status;
47 NppiSize roi;
48 roi.height = src_height;
49 roi.width = src_width;
50 status = nppiColorToGray_8u_C3C1R(src->gpu_data(), src->width_step(),
51 dst->mutable_gpu_data(), dst->width_step(),
52 roi, coeffs);
53 if (status != NPP_SUCCESS) {
54 return false;
55 }
56 return true;
57}
58
60 const base::Image8UPtr &dst,
61 const int src_width, const int src_height,
62 const int order[3]) {
63 NppStatus status;
64 NppiSize roi;
65 roi.height = src_height;
66 roi.width = src_width;
67 status = nppiSwapChannels_8u_C3R(src->gpu_data(), src->width_step(),
68 dst->mutable_gpu_data(), dst->width_step(),
69 roi, order);
70 if (status != NPP_SUCCESS) {
71 return false;
72 }
73 return true;
74}
75
77 const base::Image8UPtr &dst,
78 const int src_width, const int src_height) {
79 NppStatus status;
80 NppiSize roi;
81 roi.height = src_height;
82 roi.width = src_width;
83 status = nppiDup_8u_C1C3R(src->gpu_data(), src->width_step(),
84 dst->mutable_gpu_data(), dst->width_step(), roi);
85 if (status != NPP_SUCCESS) {
86 return false;
87 }
88 return true;
89}
90
91bool nppImageRemap(const base::Image8U &src_img, base::Image8U *dst_img,
92 const int src_width, const int src_height,
93 const base::Blob<float> &map_x,
94 const base::Blob<float> &map_y) {
95 NppiInterpolationMode remap_mode = NPPI_INTER_LINEAR;
96 NppiSize image_size;
97 image_size.width = src_width;
98 image_size.height = src_height;
99 NppiRect remap_roi = {0, 0, src_width, src_height};
100 NppStatus status = NPP_SUCCESS;
101 int d_map_step = static_cast<int>(map_x.shape(1) * sizeof(float));
102 switch (src_img.channels()) {
103 case 1:
104 status = nppiRemap_8u_C1R(src_img.gpu_data(), image_size,
105 src_img.width_step(), remap_roi,
106 map_x.gpu_data(), d_map_step, map_y.gpu_data(),
107 d_map_step, dst_img->mutable_gpu_data(),
108 dst_img->width_step(), image_size, remap_mode);
109 break;
110 case 3:
111 status = nppiRemap_8u_C3R(src_img.gpu_data(), image_size,
112 src_img.width_step(), remap_roi,
113 map_x.gpu_data(), d_map_step, map_y.gpu_data(),
114 d_map_step, dst_img->mutable_gpu_data(),
115 dst_img->width_step(), image_size, remap_mode);
116 break;
117 default:
118 AERROR << "Invalid number of channels: " << src_img.channels();
119 return false;
120 }
121 if (status != NPP_SUCCESS) {
122 AERROR << "NPP_CHECK_NPP - status = " << status;
123 return false;
124 }
125 return true;
126}
127} // namespace camera
128} // namespace perception
129} // namespace apollo
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
Definition blob.h:88
const Dtype * gpu_data() const
Definition blob.cc:154
const std::vector< int > & shape() const
Definition blob.h:130
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
Definition blob.cc:72
A wrapper around Blob holders serving as the basic computational unit for images.
Definition image_8u.h:44
const uint8_t * gpu_data() const
Definition image_8u.h:101
#define AERROR
Definition log.h:44
std::shared_ptr< Image8U > Image8UPtr
Definition image_8u.h:148
bool nppImageToGray(const base::Image8UPtr &src, const base::Image8UPtr &dst, const int src_width, const int src_height, const float coeffs[3])
bool nppDupImageChannels(const base::Image8UPtr &src, const base::Image8UPtr &dst, const int src_width, const int src_height)
bool nppImageRemap(const base::Image8U &src_img, base::Image8U *dst_img, const int src_width, const int src_height, const base::Blob< float > &map_x, const base::Blob< float > &map_y)
bool nppSwapImageChannels(const base::Image8UPtr &src, const base::Image8UPtr &dst, const int src_width, const int src_height, const int order[3])
bool nppImageToBlob(const base::Image8U &image, base::Blob< uint8_t > *blob)
class register implement
Definition arena_queue.h:37