45 auto src_mat = cv::Mat(size_, type_, cv::Scalar(0, 0, 0));
47 cv::Point2i center = cv::Point2i(src_mat.cols / 2, src_mat.rows / 2);
57 const cv::Point2i& center_point,
59 double coeffs[2][3]) {
60 double alpha, beta, angle;
62 angle = heading * M_PI / 180;
63 alpha = std::cos(angle) * scale;
64 beta = std::sin(angle) * scale;
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;
77 const cv::Point2i& center_point,
const double heading,
78 const double scale, cv::Mat* output_img) {
83 cudaMalloc(&process_buff, size_.width * size_.height * 3);
84 cudaMalloc(&output_buff, size_.width * size_.height * 3);
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};
93 if (
GetCoeffs(heading, center_point, scale, coeffs)) {
94 AERROR <<
"Fail to get rotation matrix";
98 cudaMemcpy(process_buff, (
unsigned char*) input_img.data,
99 input_img.size().width * input_img.size().height * 3,
100 cudaMemcpyHostToDevice);
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);
108 AERROR <<
"Affine transform failed, error: " << status;
112 *output_img = cv::Mat(input_img.size(),
113 input_img.type(), cv::Scalar(0, 0, 0));
115 cudaMemcpy((
unsigned char*) output_img->data, output_buff,
116 input_img.size().width * input_img.size().height * 3,
117 cudaMemcpyDeviceToHost);
119 cudaFree(process_buff);
120 cudaFree(output_buff);