Apollo 10.0
自动驾驶开放平台
apollo::prediction::AffineTransform类 参考

#include <affine_transform.h>

apollo::prediction::AffineTransform 的协作图:

Public 成员函数

 AffineTransform ()
 
 ~AffineTransform ()
 
bool Init (cv::Size size, int type)
 init function to the class
 
int GetCoeffs (const double heading, const cv::Point2i &center_point, const double scale, double coeffs[2][3])
 calculate the coeffs martix
 
int AffineTransformsFromMat (const cv::Mat &input_img, const cv::Point2i &center_point, const double heading, const double scale, cv::Mat *output_img)
 perform the affine transform from cv mat
 

详细描述

在文件 affine_transform.h30 行定义.

构造及析构函数说明

◆ AffineTransform()

apollo::prediction::AffineTransform::AffineTransform ( )

在文件 affine_transform.cc31 行定义.

31{}

◆ ~AffineTransform()

apollo::prediction::AffineTransform::~AffineTransform ( )

在文件 affine_transform.cc33 行定义.

33 {
34 for (auto it = pointer_table_.begin(); it != pointer_table_.end(); it++) {
35 if (*it) {
36 cudaFreeHost(*it);
37 }
38 }
39}

成员函数说明

◆ AffineTransformsFromMat()

int apollo::prediction::AffineTransform::AffineTransformsFromMat ( const cv::Mat &  input_img,
const cv::Point2i &  center_point,
const double  heading,
const double  scale,
cv::Mat *  output_img 
)

perform the affine transform from cv mat

参数
input_imgthe input of image
center_pointrotation point of the image
headingthe heading angle
scalethe scale of affine transform
output_imgoutput buffer

在文件 affine_transform.cc76 行定义.

78 {
79 double coeffs[2][3];
80 void* process_buff;
81 void* output_buff;
82
83 cudaMalloc(&process_buff, size_.width * size_.height * 3);
84 cudaMalloc(&output_buff, size_.width * size_.height * 3);
85 // auto output_buff = out_pool_->GetObject();
86 // auto stream = stream_pool_->GetObject();
87
88 // perform affine transform of the whole image
89 NppiRect src_ROI{0, 0, input_img.size().width, input_img.size().height};
90 NppiRect dst_ROI{0, 0, input_img.size().width, input_img.size().height};
91 NppiSize image_size{input_img.size().width, input_img.size().height};
92
93 if (GetCoeffs(heading, center_point, scale, coeffs)) {
94 AERROR << "Fail to get rotation matrix";
95 return -1;
96 }
97
98 cudaMemcpy(process_buff, (unsigned char*) input_img.data,
99 input_img.size().width * input_img.size().height * 3,
100 cudaMemcpyHostToDevice);
101
102 NppStatus status = nppiWarpAffine_8u_C3R(
103 static_cast<Npp8u*>(process_buff),
104 image_size, input_img.step, src_ROI,
105 static_cast<Npp8u*>(output_buff),
106 input_img.step, dst_ROI, coeffs, NPPI_INTER_NN);
107 if (status) {
108 AERROR << "Affine transform failed, error: " << status;
109 return -1;
110 }
111
112 *output_img = cv::Mat(input_img.size(),
113 input_img.type(), cv::Scalar(0, 0, 0));
114
115 cudaMemcpy((unsigned char*) output_img->data, output_buff,
116 input_img.size().width * input_img.size().height * 3,
117 cudaMemcpyDeviceToHost);
118
119 cudaFree(process_buff);
120 cudaFree(output_buff);
121
122 return 0;
123}
int GetCoeffs(const double heading, const cv::Point2i &center_point, const double scale, double coeffs[2][3])
calculate the coeffs martix
#define AERROR
Definition log.h:44

◆ GetCoeffs()

int apollo::prediction::AffineTransform::GetCoeffs ( const double  heading,
const cv::Point2i &  center_point,
const double  scale,
double  coeffs[2][3] 
)

calculate the coeffs martix

参数
headingthe heading angle
center_pointrotation point of the image
scalethe scale of affine transform
coeffsoutput coeffs martix

在文件 affine_transform.cc56 行定义.

59 {
60 double alpha, beta, angle;
61
62 angle = heading * M_PI / 180;
63 alpha = std::cos(angle) * scale;
64 beta = std::sin(angle) * scale;
65
66 *((*(coeffs+0))+0) = alpha;
67 *((*(coeffs+0))+1) = beta;
68 *((*(coeffs+0))+2) = (1 - alpha) * center_point.x - beta * center_point.y;
69 *((*(coeffs+1))+0) = -beta;
70 *((*(coeffs+1))+1) = alpha;
71 *((*(coeffs+1))+2) = beta * center_point.x + (1 - alpha) * center_point.y;
72
73 return 0;
74}

◆ Init()

bool apollo::prediction::AffineTransform::Init ( cv::Size  size,
int  type 
)

init function to the class

参数
sizesize of the image
typethe image format type

在文件 affine_transform.cc41 行定义.

41 {
42 size_ = size;
43 type_ = type;
44
45 auto src_mat = cv::Mat(size_, type_, cv::Scalar(0, 0, 0));
46 cv::Mat out_mat;
47 cv::Point2i center = cv::Point2i(src_mat.cols / 2, src_mat.rows / 2);
48 double angle = -90.0;
49 double scale = 1.0;
50 AffineTransformsFromMat(src_mat, center, angle, scale, &out_mat);
51
52 return true;
53}
int AffineTransformsFromMat(const cv::Mat &input_img, const cv::Point2i &center_point, const double heading, const double scale, cv::Mat *output_img)
perform the affine transform from cv mat

该类的文档由以下文件生成: