Browse Source

颜色处理

ManualUV
hesuicong 1 month ago
parent
commit
e1258c2d3e
  1. 38
      libs/MVS/SceneTexture.cpp

38
libs/MVS/SceneTexture.cpp

@ -9746,28 +9746,36 @@ bool PointInTriangle(const Point2f& p, const Point2f& a, const Point2f& b, const @@ -9746,28 +9746,36 @@ bool PointInTriangle(const Point2f& p, const Point2f& a, const Point2f& b, const
}
// 辅助函数:从图像中双线性插值采样颜色
// SampleImageBilinear 函数可能存在错误
Pixel8U SampleImageBilinear(const Image8U3& image, const Point2f& point) {
int x = (int)point.x;
int y = (int)point.y;
float x = point.x, y = point.y;
int x0 = (int)x, y0 = (int)y;
int x1 = x0 + 1, y1 = y0 + 1;
// 确保在图像范围内
if (x < 0 || x >= image.cols-1 || y < 0 || y >= image.rows-1) {
return Pixel8U(0, 0, 0);
}
// 边界检查
x1 = MIN(x1, image.cols-1);
y1 = MIN(y1, image.rows-1);
float dx = point.x - x;
float dy = point.y - y;
float dx = x - x0;
float dy = y - y0;
const Pixel8U& p00 = image(y, x);
const Pixel8U& p01 = image(y, x+1);
const Pixel8U& p10 = image(y+1, x);
const Pixel8U& p11 = image(y+1, x+1);
// 正确获取像素(注意OpenCV是BGR顺序)
const Pixel8U& p00 = image(y0, x0);
const Pixel8U& p01 = image(y0, x1);
const Pixel8U& p10 = image(y1, x0);
const Pixel8U& p11 = image(y1, x1);
// 双线性插值计算
Pixel8U result;
for (int c = 0; c < 3; ++c) {
float top = p00[c] * (1-dx) + p01[c] * dx;
float bottom = p10[c] * (1-dx) + p11[c] * dx;
result[c] = (uint8_t)(top * (1-dy) + bottom * dy);
float v00 = p00[c];
float v01 = p01[c];
float v10 = p10[c];
float v11 = p11[c];
float top = v00 + (v01 - v00) * dx;
float bottom = v10 + (v11 - v10) * dx;
result[c] = (uint8_t)(top + (bottom - top) * dy);
}
return result;

Loading…
Cancel
Save