opencv 双目匹配中的remap前后的像素对应关系如何求出?
rectifiedL = cv2.remap(imgreL, left_map_x, left_map_y, cv2.INTER_LINEAR, borderValue=cv2.BORDER_REPLICATE)
rectifiedR = cv2.remap(imgreR, right_map_x, right_map_y, cv2.INTER_LINEAR, borderValue=cv2.BORDER_REPLICATE)
void Imgremap(Mat srcImg, Mat &dstImg, float *mapx, float *mapy)
{
int x, y;
float u, v;
/* 纯浮点运算,执行映射+插值过程 */
for (int i = 0; i < srcImg.rows; i++)
{
for (int j = 0; j < srcImg.cols; j++)
{
x = (int)mapx[i*srcImg.cols + j];
y = (int)mapy[i*srcImg.cols + j];
if (x > 1 && x < (srcImg.cols - 1) && y > 1 && y < (srcImg.rows - 1))
{
u = mapx[i*srcImg.cols + j] - x;
v = mapy[i*srcImg.cols + j] - y;
dstImg.ptr<uchar>(i)[j] = (uchar)((1 - u)*(1 - v)*srcImg.ptr<uchar>(int(y))[int(x)] + (1 - u)*v*srcImg.ptr<uchar>(int(y + 1))[int(x)]
+ u * (1 - v)*srcImg.ptr<uchar>(int(y))[int(x + 1)] + u * v*srcImg.ptr<uchar>(int(y + 1))[int(x + 1)]);
//cout << (int)(dstImg.ptr<uchar>(i)[j]) << endl;
}
else
{
dstImg.ptr<uchar>(i)[j] = 0;
}
}
}
}
参考链接 https://cloud.tencent.com/developer/ask/sof/1141000/answer/1592870