前:
!(data/attachment/forum/202304/14/130802s6yl0x0dxjumjjty.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "Y1P`_M2WBR)9`WF}J2DX9HW.png")
后:
!(data/attachment/forum/202304/14/130815z777aira2smflyom.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "X72H@BSA]_1UE~(2YSXH3UJ.png")
# 线性插值代码:
```cpp
Eigen::Vector3f getBilinnerColor(float u, float v)
{
// 坐标限定
if (u < 0) u = 0;
if (u > 1) u = 1;
if (v < 0) v = 0;
if (v > 1) v = 1;
float u_img = u * width;
float v_img = (1 - v) * height;
// find center coordinates
int cx = u_img;
int cy = v_img;
cx = (u_img - cx) > 0.5 ? std::ceil(u_img) : std::floor(u_img);
cy = (v_img - cy) > 0.5 ? std::ceil(v_img) : std::floor(v_img);
// 注意 image_data 第一个坐标对应 v,参考getColor()
// 并且uv map和image的 v 是相反方向 !!
auto u00 = image_data.at<cv::Vec3b>(cy + 0.5, cx - 0.5);
auto u10 = image_data.at<cv::Vec3b>(cy + 0.5, cx + 0.5);
auto u01 = image_data.at<cv::Vec3b>(cy - 0.5, cx - 0.5);
auto u11 = image_data.at<cv::Vec3b>(cy - 0.5, cx + 0.5);
float s = u * width - (cx - 0.5);
float t = (1 - v) * height - (cy - 0.5);
auto u0 = (1 - s) * u00 + s * u10; // at the top
auto u1 = (1 - s) * u01 + s * u11; // at the bottom
auto res = (1 - t) * u1 + t * u0;
return Eigen::Vector3f(res, res, res);
}
```
具体参考:(https://zhuanlan.zhihu.com/p/460967740)
页:
[1]