for i in range(dh):
base_x = int((M[0][1] * i + M[0][2]) * 1024) + 512
base_y = int((M[1][1] * i + M[1][2]) * 1024) + 512
for j in range(dw):
ox = (base_x + adelta[j]) >> 10
oy = (base_y + bdelta[j]) >> 10
if ox < iw and ox >= 0 and oy < ih and oy >= 0:
img1[i, j] = data[oy, ox]
else :
img1[i, j] = borderValue[0]
python实现warpaffine最近邻有些坐标取整有误
input shape: h=1920 w=1080 wp=1088 hp=1920
output shape: h=2121 w=2121 wp=2176 hp=2176
M data: [[ 0.70710678 0.70710678 -520.66017178]
[ -0.70710678 0.70710678 663.0151519 ]]
M inverse matrix data: [[ 7.07106781e-01 -7.07106781e-01 8.36984848e+02]
[ 7.07106781e-01 7.07106781e-01 -1.00660172e+02]]
输出坐标: h = 77 w = 65
输入坐标: h = 0 w = 828
取整前的值: h = -0.25100885133157647 w = 828.4995667241113
放大计算的值: h = 255 w = 848895
opencv结果: 47
input[0][828] = 21
input[0][829] = 47
input[0][827] = 150