CUDA-BEVFusion中,src/common/visualize.cu 源文件的当前部分代码class SceneArtistImplement
的作用是图像处理工具,主要用于图像的缩放、翻转和合成操作。
一、src/common/visualize.cu 部分源码
static __device__ uchar3 load_pixel(const unsigned char* image, int x, int y, float sx, float sy, int width, int stride, int height) {
// 计算源图像中的坐标
float src_x = (x + 0.5f) * sx - 0.5f;
float src_y = (y + 0.5f) * sy - 0.5f;
// 获取周围4个像素的坐标
int y_low = floorf(src_y);
int x_low = floorf(src_x);
int y_high = limit(y_low + 1, 0, height - 1);
int x_high = limit(x_low + 1, 0, width - 1);
y_low = limit(y_low, 0, height - 1);
x_low = limit(x_low, 0, width - 1);
// 计算插值权重
int ly = rint((src_y - y_low) * INTER_RESIZE_COEF_SCALE);
int lx = rint((src_x - x_low) * INTER_RESIZE_COEF_SCALE);
int hy = INTER_RESIZE_COEF_SCALE - ly;
int hx = INTER_RESIZE_COEF_SCALE - lx;
// 加载周围4个像素的值
uchar3 rgb[4];
rgb[0] = *(uchar3*)&image[y_low * stride + x_low * 3];
rgb[1] = *(uchar3*)&image[y_low * stride + x_high * 3];
rgb[2] = *(uchar3*)&image[y_high * stride + x_low * 3];
rgb[3] = *(uchar3*)&image[y_high * stride + x_high * 3];
// 双线性插值计算目标像素值
uchar3 output;
output.x = (((hy * ((hx * rgb[0].x + lx * rgb[1].x) >> 4)) >> 16) + ((ly * ((hx * rgb[2].x + lx * rgb[3].x) >> 4)) >> 16) + 2) >> 2;
output.y = (((hy * ((hx * rgb[0].y + lx * rgb[1].y) >> 4)) >> 16) + ((ly * ((hx * rgb[2].y + lx * rgb[3].y) >> 4)) >> 16) + 2) >>