def get_vectors(image, points, mtx, dist):
# order points
points = _order_points(points)
# set up criteria, image, points and axis
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
imgp = np.array(points, dtype='float32')
objp = np.array([[0.,0.,0.],[1.,0.,0.],
[1.,1.,0.],[0.,1.,0.]], dtype='float32')
# calculate rotation and translation vectors
cv2.cornerSubPix(gray,imgp,(11,11),(-1,-1),criteria)
rvecs, tvecs, _ = cv2.solvePnPRansac(objp, imgp, mtx, dist)
return rvecs, tvecs
评论列表
文章目录