我想使用numpy / tensorflow实现cv2.solvePnP
和cv2.projectPoints。
但有意想不到的价值。
我引用了这个公式:How to change text of a TextView in navigation drawer header?
来自formula
我的参数是:
OBJ_POINTS=np.array([[ 6.825897, 1.330353, -1.330353, -6.825897, 5.311432, 1.78993 ,
-1.78993 , -5.311432, 2.005628, -2.005628, 2.774015, -2.774015,
0. , 0. ],
[ 6.760612, 7.122144, 7.122144, 6.760612, 5.485328, 5.393625,
5.393625, 5.485328, 1.409845, 1.409845, -2.080775, -2.080775,
-3.116408, -7.415691],
[ 4.402142, 6.903745, 6.903745, 4.402142, 3.987654, 4.413414,
4.413414, 3.987654, 6.165652, 6.165652, 5.048531, 5.048531,
6.097667, 4.070434],
[ 1. , 1. , 1. , 1. , 1. , 1. ,
1. , 1. , 1. , 1. , 1. , 1. ,
1. , 1. ]])
label=np.array([[391., 206.],
[430., 197.],
[459., 191.],
[479., 195.],
[408., 219.],
[428., 217.],
[457., 213.],
[472., 211.],
[441., 255.],
[459., 253.],
[430., 277.],
[466., 275.],
[452., 288.],
[446., 312.]], dtype=float32)
cam_mat=np.array([[1.28e+03, 0.00e+00, 6.40e+02],
[0.00e+00, 1.28e+03, 3.60e+02],
[0.00e+00, 0.00e+00, 1.00e+00]])
我使用cv2.solvePnP
计算了rvec和tvec:
rvec=np.array([[ 0.14683954],
[-0.77872218],
[-0.1339505 ]])
tvec=array([[ 27.37206706],
[ 12.89076055],
[-160.68589399]])
然后我使用cv2.Rodrigues(rvec)[0]
rmat=np.array([[ 0.70427006, 0.06582738, -0.70687371],
[-0.17415072, 0.98128827, -0.08212712],
[ 0.68824066, 0.18094224, 0.70255583]])
所以矩阵[R | t]是:
Rt=np.concatenate([rmat,translation_vector],axis=-1)
我通过以下方式计算重新投影的地标:
y=(cam_mat.dot(Rt)).dot(obj_pts)
得到了:
y=np.array([[-59293.93250522, -67734.92848781, -71305.43549652,
-77613.81683607, -61392.72974225, -66330.50940479,
-71134.46565557, -75647.97266068, -67635.61225272,
-73018.47592188, -66794.35222396, -74239.47393207,
-71201.63145976, -71139.03429556],
[-31594.43367234, -30883.63615633, -30949.7645763 ,
-31933.73142526, -33378.22414678, -33523.97724932,
-33612.95005786, -33642.24174657, -38522.96324169,
-38622.65784207, -43280.73944318, -43418.62858157,
-44562.89054421, -50542.67218909],
[ -151.67200329, -153.63132795, -155.46253401,
-161.06772304, -153.23627339, -155.37738704,
-157.84119226, -160.54736035, -154.71872396,
-157.47943345, -155.60632927, -159.42470911,
-156.96583233, -159.1679986 ]])
那是出乎意料的......