本文整理汇总了Python中cv2.estimateAffinePartial2D方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.estimateAffinePartial2D方法的具体用法?Python cv2.estimateAffinePartial2D怎么用?Python cv2.estimateAffinePartial2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.estimateAffinePartial2D方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: align_to_shape
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import estimateAffinePartial2D [as 别名]
def align_to_shape(image, labels, target, extend=1.0, rotate=False):
image = np.array(image)
labels = np.array(labels).astype(np.float32)
target = np.array(target).astype(np.float32)
m, _ = cv2.estimateAffinePartial2D(labels, target)
image_t = cv2.warpAffine(image, m, (128, 128))
labels_t = np.dot(labels, m[:,:2].T) + m[np.newaxis,:,2]
return image_t, labels_t
示例2: find_homography
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import estimateAffinePartial2D [as 别名]
def find_homography(keypoints_pic1, keypoints_pic2, matches) -> (List, np.float32, np.float32):
# Find an Homography matrix between two pictures
# From two list of keypoints and a list of matches, extrat
# A list of good matches found by RANSAC and two transformation matrix (an homography and a rigid homography/affine)
# Instanciate outputs
good = []
# Transforming keypoints to list of points
src_pts = np.float32([keypoints_pic1[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2)
dst_pts = np.float32([keypoints_pic2[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)
# Find the transformation between points
transformation_matrix, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
# Compute a rigid transformation (without depth, only scale + rotation + translation)
transformation_rigid_matrix, rigid_mask = cv2.estimateAffinePartial2D(src_pts, dst_pts)
# Get a mask list for matches = A list that says "This match is an in/out-lier"
matchesMask = mask.ravel().tolist()
# Filter the matches list thanks to the mask
for i, element in enumerate(matchesMask):
if element == 1:
good.append(matches[i])
return good, transformation_matrix, transformation_rigid_matrix
示例3: cv2_estimateRigidTransform
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import estimateAffinePartial2D [as 别名]
def cv2_estimateRigidTransform(from_pts, to_pts, full=False):
"""Estimate transforms in OpenCV 3 or OpenCV 4"""
if not from_pts.shape[0] or not to_pts.shape[0]:
return None
if imutils.is_cv4():
transform = cv2.estimateAffinePartial2D(from_pts, to_pts)[0]
else:
# noinspection PyUnresolvedReferences
transform = cv2.estimateRigidTransform(from_pts, to_pts, full)
return transform
示例4: find_affine
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import estimateAffinePartial2D [as 别名]
def find_affine(i1, i2):
# quick sanity checks
if i1 == i2:
return None
if not i2.name in i1.match_list:
return None
if len(i1.match_list[i2.name]) == 0:
return None
if not i1.kp_list or not len(i1.kp_list):
i1.load_features()
if not i2.kp_list or not len(i2.kp_list):
i2.load_features()
# affine transformation from i2 uv coordinate system to i1
uv1 = []; uv2 = []; indices = []
for pair in i1.match_list[i2.name]:
uv1.append( i1.kp_list[ pair[0] ].pt )
uv2.append( i2.kp_list[ pair[1] ].pt )
uv1 = np.float32([uv1])
uv2 = np.float32([uv2])
affine, status = \
cv2.estimateAffinePartial2D(uv2, uv1)
return affine
# return individual components of affine transform: rot, tx, ty, sx,
# sy (units are degrees and pixels)
示例5: findAffine
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import estimateAffinePartial2D [as 别名]
def findAffine(src, dst, fullAffine=False):
#print("src:", src)
#print("dst:", dst)
if len(src) >= affine_minpts:
# affine = cv2.estimateRigidTransform(np.array([src]), np.array([dst]), fullAffine)
affine, status = \
cv2.estimateAffinePartial2D(np.array([src]).astype(np.float32),
np.array([dst]).astype(np.float32))
else:
affine = None
#print str(affine)
return affine