Estimate CV2中的转换与文档有所不同

时间:2018-09-12 00:56:55

标签: python reverse transformation cv2

文档为https://docs.opencv.org/3.0-beta/modules/shape/doc/shape_transformers.html void EstimateTransformation(InputArray transformingShape,InputArray targetShape,std :: vector&匹配) 这样我就可以运行代码

import cv2
import numpy as np
import matplotlib.pyplot as plt

tps = cv2.createThinPlateSplineShapeTransformer()

sshape = np.array ([[67, 90], [206, 90], [67, 228], [206, 227]], np.float32)
tshape = np.array ([[64, 63], [205, 122], [67, 263], [207, 192]], np.float32)
sshape = sshape.reshape (1, -1, 2)
tshape = tshape.reshape (1, -1, 2)
matches = list ()
matches.append (cv2.DMatch (0, 0, 0))
matches.append (cv2.DMatch (1,1,0))
matches.append (cv2.DMatch (2, 2, 0))
matches.append (cv2.DMatch (3, 3, 0))
tps.estimateTransformation (tshape, sshape, matches)
ret, tshape  = tps.applyTransformation (sshape)


img = cv2.imread ('tiger.jpg', 1)
out_img = tps.warpImage (img)

plt.imshow(cv2.cvtColor(out_img, cv2.COLOR_BGR2RGB))
plt.show()

cv2.waitKey(0)

cv2.waitKey(0) 结果看起来像我期望的相反 enter image description here

所以,我更改了代码tps.estimateTransformation(tshape,sshape,matchs)

我得到了预期的结果。 enter image description here

这在文档中是错误的,或者我的代码失败了。

0 个答案:

没有答案