我目前在Python中使用OpenCV來校正航拍圖像中的圖像失真。我有滾動,俯仰和偏航的數據。我知道我需要創建一個扭曲矩陣,並將該矩陣應用到我的原始座標點以創建圖像的輸出點。我能夠影響圖像的移動方式,但是我覺得有一個錯誤,因爲唯一的值似乎適用於非常小的值。使用滾動,俯仰和偏航來翹曲圖像
這裏是我當前的代碼:
warp_mat = np.array([[math.cos(theta)*math.cos(psy), math.cos(phi)*math.sin(psy)+math.sin(phi)*math.sin(theta)*math.cos(psy), math.sin(phi)*math.sin(psy)-math.cos(phi)*math.sin(theta)*math.cos(psy)],\
[-1*math.cos(theta)*math.sin(psy), math.cos(phi)*math.cos(psy)-math.sin(phi)*math.sin(theta)*math.sin(psy), math.sin(phi)*math.cos(psy)+math.cos(phi)*math.sin(theta)*math.sin(psy)],\
[math.sin(theta), -1*math.sin(phi)*math.cos(theta), math.cos(phi)*math.cos(theta)]], dtype='float32')
srcPts = np.array([[-2064, 1161, 1],\
[2064, 1161, 1],\
[2064, -1161, 1],\
[-2064, -1161, 1]], dtype='float32')
dstPts = np.empty(shape = (4,3), dtype='float32')
dstPts[0][0] = srcPts[0][0] * warp_mat[0][0] + srcPts[0][1] * warp_mat[1][0] + srcPts[0][2] * warp_mat[2][0];
dstPts[0][1] = srcPts[0][0] * warp_mat[0][1] + srcPts[0][1] * warp_mat[1][1] + srcPts[0][2] * warp_mat[2][1];
dstPts[0][2] = srcPts[0][0] * warp_mat[0][2] + srcPts[0][1] * warp_mat[1][2] + srcPts[0][2] * warp_mat[2][2];
dstPts[1][0] = srcPts[1][0] * warp_mat[0][0] + srcPts[1][1] * warp_mat[1][0] + srcPts[1][2] * warp_mat[2][0];
dstPts[1][1] = srcPts[1][0] * warp_mat[0][1] + srcPts[1][1] * warp_mat[1][1] + srcPts[1][2] * warp_mat[2][1];
dstPts[1][2] = srcPts[1][0] * warp_mat[0][2] + srcPts[1][1] * warp_mat[1][2] + srcPts[1][2] * warp_mat[2][2];
dstPts[2][0] = srcPts[2][0] * warp_mat[0][0] + srcPts[2][1] * warp_mat[1][0] + srcPts[2][2] * warp_mat[2][0];
dstPts[2][1] = srcPts[2][0] * warp_mat[0][1] + srcPts[2][1] * warp_mat[1][1] + srcPts[2][2] * warp_mat[2][1];
dstPts[2][2] = srcPts[2][0] * warp_mat[0][2] + srcPts[2][1] * warp_mat[1][2] + srcPts[2][2] * warp_mat[2][2];
dstPts[3][0] = srcPts[3][0] * warp_mat[0][0] + srcPts[3][1] * warp_mat[1][0] + srcPts[3][2] * warp_mat[2][0];
dstPts[3][1] = srcPts[3][0] * warp_mat[0][1] + srcPts[3][1] * warp_mat[1][1] + srcPts[3][2] * warp_mat[2][1];
dstPts[3][2] = srcPts[3][0] * warp_mat[0][2] + srcPts[3][1] * warp_mat[1][2] + srcPts[3][2] * warp_mat[2][2];
dstPts[0][0] = dstPts[0][0]/dstPts[0][2];
dstPts[0][1] = dstPts[0][1]/dstPts[0][2];
dstPts[0][2] = dstPts[0][2]/dstPts[0][2];
dstPts[1][0] = dstPts[1][0]/dstPts[1][2];
dstPts[1][1] = dstPts[1][1]/dstPts[1][2];
dstPts[1][2] = dstPts[1][2]/dstPts[1][2];
dstPts[2][0] = dstPts[2][0]/dstPts[2][2];
dstPts[2][1] = dstPts[2][1]/dstPts[2][2];
dstPts[2][2] = dstPts[2][2]/dstPts[2][2];
dstPts[3][0] = dstPts[3][0]/dstPts[3][2];
dstPts[3][1] = dstPts[3][1]/dstPts[3][2];
dstPts[3][2] = dstPts[3][2]/dstPts[3][2];
srcPts2 = np.array([[srcPts[0][0],srcPts[0][1]],\
[srcPts[1][0],srcPts[1][1]],\
[srcPts[2][0],srcPts[2][1]],\
[srcPts[3][0],srcPts[3][1]]], dtype='float32')
dstPts2 = np.array([[dstPts[0][0],dstPts[0][1]],\
[dstPts[1][0],dstPts[1][1]],\
[dstPts[2][0],dstPts[2][1]],\
[dstPts[3][0],dstPts[3][1]]], dtype='float32')
transMatrix = cv.getPerspectiveTransform(srcPts2, dstPts2)
dst = cv.warpPerspective(imgFile,transMatrix,(4128,2322) ,borderMode = cv.BORDER_CONSTANT,borderValue = 0)