当前位置: 首页>>代码示例>>Python>>正文


Python cv2.DMatch方法代码示例

本文整理汇总了Python中cv2.DMatch方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.DMatch方法的具体用法?Python cv2.DMatch怎么用?Python cv2.DMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.DMatch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: thin_plate_transform

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DMatch [as 别名]
def thin_plate_transform(x,y,offw,offh,imshape,shift_l=-0.05,shift_r=0.05,num_points=5,offsetMatrix=False):
    rand_p=np.random.choice(x.size,num_points,replace=False)
    movingPoints=np.zeros((1,num_points,2),dtype='float32')
    fixedPoints=np.zeros((1,num_points,2),dtype='float32')

    movingPoints[:,:,0]=x[rand_p]
    movingPoints[:,:,1]=y[rand_p]
    fixedPoints[:,:,0]=movingPoints[:,:,0]+offw*(np.random.rand(num_points)*(shift_r-shift_l)+shift_l)
    fixedPoints[:,:,1]=movingPoints[:,:,1]+offh*(np.random.rand(num_points)*(shift_r-shift_l)+shift_l)

    tps=cv2.createThinPlateSplineShapeTransformer()
    good_matches=[cv2.DMatch(i,i,0) for i in range(num_points)]
    tps.estimateTransformation(movingPoints,fixedPoints,good_matches)

    imh,imw=imshape
    x,y=np.meshgrid(np.arange(imw),np.arange(imh))
    x,y=x.astype('float32'),y.astype('float32')
    newxy=tps.applyTransformation(np.dstack((x.ravel(),y.ravel())))[1]
    newxy=newxy.reshape([imh,imw,2])

    if offsetMatrix:
        return newxy,newxy-np.dstack((x,y))
    else:
        return newxy 
开发者ID:yelantingfeng,项目名称:pyLucid,代码行数:26,代码来源:lucidDream.py

示例2: draw_match_2_side

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DMatch [as 别名]
def draw_match_2_side(img1, kp1, img2, kp2, N):
    """Draw matches on 2 sides
    Args:
        img1 (HxW(xC) array): image 1
        kp1 (Nx2 array): keypoint for image 1
        img2 (HxW(xC) array): image 2
        kp2 (Nx2 array): keypoint for image 2
        N (int): number of matches to draw
    Returns:
        out_img (Hx2W(xC) array): output image with drawn matches
    """
    kp_list = np.linspace(0, min(kp1.shape[0], kp2.shape[0])-1, N,
                                            dtype=np.int
                                            )

    # Convert keypoints to cv2.Keypoint object
    cv_kp1 = [cv2.KeyPoint(x=pt[0], y=pt[1], _size=1) for pt in kp1[kp_list]]
    cv_kp2 = [cv2.KeyPoint(x=pt[0], y=pt[1], _size=1) for pt in kp2[kp_list]]

    out_img = np.array([])
    good_matches = [cv2.DMatch(_imgIdx=0, _queryIdx=idx, _trainIdx=idx,_distance=0) for idx in range(N)]
    out_img = cv2.drawMatches(img1, cv_kp1, img2, cv_kp2, matches1to2=good_matches, outImg=out_img)

    return out_img 
开发者ID:Huangying-Zhan,项目名称:DF-VO,代码行数:26,代码来源:frame_drawer.py

示例3: feature_matcher

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DMatch [as 别名]
def feature_matcher(self, sess, ref_feat, test_feat):
        matches = self.bf_matcher(sess, ref_feat, test_feat)
        matches = [cv2.DMatch(matches[i][0], matches[i][1], 0) for i in range(matches.shape[0])]
        return matches 
开发者ID:luigifreda,项目名称:pyslam,代码行数:6,代码来源:evaluator.py

示例4: to_cv2_dmatch

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DMatch [as 别名]
def to_cv2_dmatch(m):
        return cv2.DMatch(m, m, m, m) 
开发者ID:Xylon-Sean,项目名称:rfnet,代码行数:4,代码来源:example.py

示例5: showImWarpEx

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DMatch [as 别名]
def showImWarpEx(im_fl, save):
	"""
	Show an example of warped images and their corresponding four corner points.
	"""

	im = cv2.resize(cv2.cvtColor(cv2.imread(im_fl), cv2.COLOR_BGR2GRAY), (256,int(120./160*256)))
	r = Random(0)
	r.seed(time.time())
	h, w = im.shape
	im_warp, pts_warp = randPerspectiveWarp(im, w, h, r, ret_pts=True) # get the perspective warped picture	
	
	pts_orig = np.zeros((4, 2), dtype=np.float32) # four original points
	ofst = 3
	pts_orig[0, 0] = ofst
	pts_orig[0, 1] = ofst	
	pts_orig[1, 0] = ofst
	pts_orig[1, 1] = h-ofst
	pts_orig[2, 0] = w-ofst
	pts_orig[2, 1] = ofst
	pts_orig[3, 0] = w-ofst
	pts_orig[3, 1] = h-ofst

	kpts_warp = []
	kpts_orig = []
	matches = []

	pts_rect = np.zeros((4, 2), dtype=np.float32) # for creating rectangles
	pts_rect[0, 0] = w/4
	pts_rect[0, 1] = h/4	
	pts_rect[1, 0] = w/4
	pts_rect[1, 1] = 3*h/4
	pts_rect[2, 0] = 3*w/4
	pts_rect[2, 1] = h/4
	pts_rect[3, 0] = 3*w/4
	pts_rect[3, 1] = 3*h/4
	if save: # save orig before placing rectangles on it
		cv2.imwrite("Original.jpg", im)

	for i in range(4):
		kpts_warp.append(cv2.KeyPoint(pts_warp[i,0], pts_warp[i,1], 0))
		kpts_orig.append(cv2.KeyPoint(pts_orig[i,0], pts_orig[i,1], 0))
		matches.append(cv2.DMatch(i,i,0))
		im = cv2.rectangle(im, (pts_orig[i,0], pts_orig[i,1]), (pts_rect[i,0], pts_rect[i,1]), (255,255,255), thickness=2)	
	draw_params = dict(matchColor=(0,0,250),flags = 4)
	out_im = cv2.drawMatches(im, kpts_warp, im_warp, kpts_orig, matches, None, **draw_params)
	plots = os.path.join(os.getcwd(), "plots")
	from matplotlib import rcParams
	rcParams['savefig.directory'] = plots
	if not os.path.isdir(plots):
		os.makedirs(plots)
	plt.imshow(out_im)
	plt.axis('off')
	plt.show()
	if save:
		cv2.imwrite("Warped.jpg", im_warp)
		print "Images saved in current directory" 
开发者ID:rpng,项目名称:calc,代码行数:58,代码来源:writeDatabase.py


注:本文中的cv2.DMatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。