當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.findEssentialMat方法代碼示例

本文整理匯總了Python中cv2.findEssentialMat方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.findEssentialMat方法的具體用法?Python cv2.findEssentialMat怎麽用?Python cv2.findEssentialMat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.findEssentialMat方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reset

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def reset(self):
        self.frames.clear()
        self.f_ref = None         

    # fit essential matrix E with RANSAC such that:  p2.T * E * p1 = 0  where  E = [t21]x * R21
    # out: Trc  homogeneous transformation matrix with respect to 'ref' frame,  pr_= Trc * pc_
    # N.B.1: trc is estimated up to scale (i.e. the algorithm always returns ||trc||=1, we need a scale in order to recover a translation which is coherent with previous estimated poses)
    # N.B.2: this function has problems in the following cases: [see Hartley/Zisserman Book]
    # - 'geometrical degenerate correspondences', e.g. all the observed features lie on a plane (the correct model for the correspondences is an homography) or lie a ruled quadric 
    # - degenerate motions such a pure rotation (a sufficient parallax is required) or anum_edges viewpoint change (where the translation is almost zero)
    # N.B.3: the five-point algorithm (used for estimating the Essential Matrix) seems to work well in the degenerate planar cases [Five-Point Motion Estimation Made Easy, Hartley]
    # N.B.4: as reported above, in case of pure rotation, this algorithm will compute a useless fundamental matrix which cannot be decomposed to return the rotation     
    # N.B.5: the OpenCV findEssentialMat function uses the five-point algorithm solver by D. Nister => hence it should work well in the degenerate planar cases 
開發者ID:luigifreda,項目名稱:pyslam,代碼行數:15,代碼來源:initializer.py

示例2: estimate_relative_pose_from_correspondence

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def estimate_relative_pose_from_correspondence(pts1, pts2, K1, K2):
        f_avg = (K1[0, 0] + K2[0, 0]) / 2
        pts1, pts2 = np.ascontiguousarray(pts1, np.float32), np.ascontiguousarray(pts2, np.float32)

        pts_l_norm = cv2.undistortPoints(np.expand_dims(pts1, axis=1), cameraMatrix=K1, distCoeffs=None)
        pts_r_norm = cv2.undistortPoints(np.expand_dims(pts2, axis=1), cameraMatrix=K2, distCoeffs=None)

        E, mask = cv2.findEssentialMat(pts_l_norm, pts_r_norm, focal=1.0, pp=(0., 0.),
                                       method=cv2.RANSAC, prob=0.999, threshold=3.0 / f_avg)
        points, R_est, t_est, mask_pose = cv2.recoverPose(E, pts_l_norm, pts_r_norm)
        return mask[:,0].astype(np.bool), R_est, t_est 
開發者ID:zju3dv,項目名稱:GIFT,代碼行數:13,代碼來源:evaluation.py

示例3: check_dist_epipolar_line

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def check_dist_epipolar_line(kp1,kp2,F12,sigma2_kp2):
    # Epipolar line in second image l = kp1' * F12 = [a b c]
    l = np.dot(F12.T,np.array([kp1[0],kp1[1],1]))
    num = l[0]*kp2[0] + l[1]*kp2[1] + l[2]  # kp1' * F12 * kp2
    den = l[0]*l[0] + l[1]*l[1]   # a*a+b*b

    if(den==0):
    #if(den < 1e-20):
        return False

    dist_sqr = num*num/den              # squared (minimum) distance of kp2 from the epipolar line l
    return dist_sqr < 3.84 * sigma2_kp2 # value of inverse cumulative chi-square for 1 DOF (Hartley Zisserman pag 567)



# fit essential matrix E with RANSAC such that:  p2.T * E * p1 = 0  where  E = [t21]x * R21
# input: kpn_ref and kpn_cur are two arrays of [Nx2] normalized coordinates of matched keypoints 
# out: a) Trc: homogeneous transformation matrix containing Rrc, trc  ('cur' frame with respect to 'ref' frame)    pr = Trc * pc 
#      b) mask_match: array of N elements, every element of which is set to 0 for outliers and to 1 for the other points (computed only in the RANSAC and LMedS methods)
# N.B.1: trc is estimated up to scale (i.e. the algorithm always returns ||trc||=1, we need a scale in order to recover a translation which is coherent with previous estimated poses)
# N.B.2: this function has problems in the following cases: [see Hartley/Zisserman Book]
# - 'geometrical degenerate correspondences', e.g. all the observed features lie on a plane (the correct model for the correspondences is an homography) or lie a ruled quadric 
# - degenerate motions such a pure rotation (a sufficient parallax is required) or an infinitesimal viewpoint change (where the translation is almost zero)
# N.B.3: the five-point algorithm (used for estimating the Essential Matrix) seems to work well in the degenerate planar cases [Five-Point Motion Estimation Made Easy, Hartley]
# N.B.4: as reported above, in case of pure rotation, this algorithm will compute a useless fundamental matrix which cannot be decomposed to return a correct rotation 
# N.B.5: the OpenCV findEssentialMat function uses the five-point algorithm solver by D. Nister => hence it should work well in the degenerate planar cases 
開發者ID:luigifreda,項目名稱:pyslam,代碼行數:28,代碼來源:utils_geom.py

示例4: estimate_pose_ess_mat

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def estimate_pose_ess_mat(kpn_ref, kpn_cur, method=cv2.RANSAC, prob=0.999, threshold=0.0003):	
    # here, the essential matrix algorithm uses the five-point algorithm solver by D. Nister (see the notes and paper above )     
    E, mask_match = cv2.findEssentialMat(kpn_cur, kpn_ref, focal=1, pp=(0., 0.), method=method, prob=prob, threshold=threshold)                         
    _, R, t, mask = cv2.recoverPose(E, kpn_cur, kpn_ref, focal=1, pp=(0., 0.))   
    return poseRt(R,t.T), mask_match  # Trc, mask_mat         


# z rotation, input in radians 
開發者ID:luigifreda,項目名稱:pyslam,代碼行數:10,代碼來源:utils_geom.py

示例5: estimatePose

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def estimatePose(self, kpn_ref, kpn_cur):	     
        # here, the essential matrix algorithm uses the five-point algorithm solver by D. Nister (see the notes and paper above )     
        E, self.mask_match = cv2.findEssentialMat(kpn_cur, kpn_ref, focal=1, pp=(0., 0.), method=cv2.RANSAC, prob=kRansacProb, threshold=kRansacThresholdNormalized)                         
        _, R, t, mask = cv2.recoverPose(E, kpn_cur, kpn_ref, focal=1, pp=(0., 0.))                                                     
        return poseRt(R,t.T)  # Trc  homogeneous transformation matrix with respect to 'ref' frame,  pr_= Trc * pc_        

    # push the first image 
開發者ID:luigifreda,項目名稱:pyslam,代碼行數:9,代碼來源:initializer.py

示例6: estimatePose

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def estimatePose(self, kps_ref, kps_cur):	
        kp_ref_u = self.cam.undistort_points(kps_ref)	
        kp_cur_u = self.cam.undistort_points(kps_cur)	        
        self.kpn_ref = self.cam.unproject_points(kp_ref_u)
        self.kpn_cur = self.cam.unproject_points(kp_cur_u)
        if kUseEssentialMatrixEstimation:
            # the essential matrix algorithm is more robust since it uses the five-point algorithm solver by D. Nister (see the notes and paper above )
            E, self.mask_match = cv2.findEssentialMat(self.kpn_cur, self.kpn_ref, focal=1, pp=(0., 0.), method=cv2.RANSAC, prob=kRansacProb, threshold=kRansacThresholdNormalized)
        else:
            # just for the hell of testing fundamental matrix fitting ;-) 
            F, self.mask_match = self.computeFundamentalMatrix(kp_cur_u, kp_ref_u)
            E = self.cam.K.T @ F @ self.cam.K    # E = K.T * F * K 
        #self.removeOutliersFromMask(self.mask)  # do not remove outliers, the last unmatched/outlier features can be matched and recognized as inliers in subsequent frames                          
        _, R, t, mask = cv2.recoverPose(E, self.kpn_cur, self.kpn_ref, focal=1, pp=(0., 0.))   
        return R,t  # Rrc, trc (with respect to 'ref' frame) 
開發者ID:luigifreda,項目名稱:pyslam,代碼行數:17,代碼來源:visual_odometry.py

示例7: processSecondFrame

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def processSecondFrame(self):
		self.px_ref, self.px_cur = featureTracking(self.last_frame, self.new_frame, self.px_ref)
		E, mask = cv2.findEssentialMat(self.px_cur, self.px_ref, focal=self.focal, pp=self.pp, method=cv2.RANSAC, prob=0.999, threshold=1.0)
		_, self.cur_R, self.cur_t, mask = cv2.recoverPose(E, self.px_cur, self.px_ref, focal=self.focal, pp = self.pp)
		self.frame_stage = STAGE_DEFAULT_FRAME 
		self.px_ref = self.px_cur 
開發者ID:karanchawla,項目名稱:Monocular-Visual-Inertial-Odometry,代碼行數:8,代碼來源:visual_odometry.py

示例8: processFrame

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def processFrame(self, frame_id):
		self.px_ref, self.px_cur = featureTracking(self.last_frame, self.new_frame, self.px_ref)
		E, mask = cv2.findEssentialMat(self.px_cur, self.px_ref, focal=self.focal, pp=self.pp, method=cv2.RANSAC, prob=0.999, threshold=1.0)
		_, R, t, mask = cv2.recoverPose(E, self.px_cur, self.px_ref, focal=self.focal, pp = self.pp)
		absolute_scale = self.getAbsoluteScale(frame_id)
		if(absolute_scale > 0.1):
			self.cur_t = self.cur_t + absolute_scale*self.cur_R.dot(t) 
			self.cur_R = R.dot(self.cur_R)
		if(self.px_ref.shape[0] < kMinNumFeature):
			self.px_cur = self.detector.detect(self.new_frame)
			self.px_cur = np.array([x.pt for x in self.px_cur], dtype=np.float32)
		self.px_ref = self.px_cur 
開發者ID:karanchawla,項目名稱:Monocular-Visual-Inertial-Odometry,代碼行數:14,代碼來源:visual_odometry.py

示例9: filterFeatures

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def filterFeatures(p1, p2, K, method):
    inliers = 0
    total = len(p1)
    space = ""
    status = []
    M = None
    if len(p1) < 7:
        # not enough points
        return None, np.zeros(total), [], []
    if method == 'homography':
        M, status = cv2.findHomography(p1, p2, cv2.LMEDS, tol)
    elif method == 'fundamental':
        M, status = cv2.findFundamentalMat(p1, p2, cv2.LMEDS, tol)
    elif method == 'essential':
        M, status = cv2.findEssentialMat(p1, p2, K, cv2.LMEDS, threshold=tol)
    elif method == 'none':
        M = None
        status = np.ones(total)
    newp1 = []
    newp2 = []
    for i, flag in enumerate(status):
        if flag:
            newp1.append(p1[i])
            newp2.append(p2[i])
    p1 = np.float32(newp1)
    p2 = np.float32(newp2)
    inliers = np.sum(status)
    total = len(status)
    #print '%s%d / %d  inliers/matched' % (space, np.sum(status), len(status))
    return M, status, np.float32(newp1), np.float32(newp2) 
開發者ID:UASLab,項目名稱:ImageAnalysis,代碼行數:32,代碼來源:1a-est-gyro-rates.py

示例10: filterFeatures

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def filterFeatures(p1, p2, K, method):
    inliers = 0
    total = len(p1)
    space = ""
    status = []
    while inliers < total and total >= 7:
        if method == 'homography':
            M, status = cv2.findHomography(p1, p2, cv2.LMEDS, tol)
        elif method == 'fundamental':
            M, status = cv2.findFundamentalMat(p1, p2, cv2.LMEDS, tol)
        elif method == 'essential':
            M, status = cv2.findEssentialMat(p1, p2, K, cv2.LMEDS, threshold=tol)
        elif method == 'none':
            M = none
            status = np.ones(total)
        newp1 = []
        newp2 = []
        for i, flag in enumerate(status):
            if flag:
                newp1.append(p1[i])
                newp2.append(p2[i])
        p1 = np.float32(newp1)
        p2 = np.float32(newp2)
        inliers = np.sum(status)
        total = len(status)
        #print '%s%d / %d  inliers/matched' % (space, np.sum(status), len(status))
        space += " "
    return M, status, np.float32(newp1), np.float32(newp2) 
開發者ID:UASLab,項目名稱:ImageAnalysis,代碼行數:30,代碼來源:1b-est-gyro-rates.py

示例11: filter_by_transform

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import findEssentialMat [as 別名]
def filter_by_transform(K, i1, i2, transform):
    clean = True

    # tol = float(i1.width) / 200.0 # rejection range in pixels
    tol = math.pow(i1.width, 0.25)
    if tol < 1.0:
        tol = 1.0
    # print "tol = %.4f" % tol 
    matches = i1.match_list[i2.name]
    if len(matches) < min_pairs:
        i1.match_list[i2.name] = []
        return True
    p1 = []
    p2 = []
    for k, pair in enumerate(matches):
        use_raw_uv = False
        if use_raw_uv:
            p1.append( i1.kp_list[pair[0]].pt )
            p2.append( i2.kp_list[pair[1]].pt )
        else:
            # undistorted uv points should be better if the camera
            # calibration is known, right?
            p1.append( i1.uv_list[pair[0]] )
            p2.append( i2.uv_list[pair[1]] )

    p1 = np.float32(p1)
    p2 = np.float32(p2)
    #print "p1 = %s" % str(p1)
    #print "p2 = %s" % str(p2)
    method = cv2.RANSAC
    #method = cv2.LMEDS
    if transform == "homography":
        M, status = cv2.findHomography(p1, p2, method, tol)
    elif transform == "fundamental":
        M, status = cv2.findFundamentalMat(p1, p2, method, tol)
    elif transform == "essential":
        M, status = cv2.findEssentialMat(p1, p2, K, method, threshold=tol)
    elif transform == "none":
        status = np.ones(len(matches))
    else:
        # fail
        M, status = None, None
    log("  %s vs %s: %d / %d  inliers/matched" % (i1.name, i2.name, np.sum(status), len(status)))
    # remove outliers
    for k, flag in enumerate(status):
        if not flag:
            # print("    deleting: " + str(matches[k]))
            clean = False
            matches[k] = (-1, -1)
    for pair in reversed(matches):
        if pair == (-1, -1):
            matches.remove(pair)
    return clean

# Filter duplicate features.  SIFT (for example) can detect the same
# feature at different scales/orientations which can lead to duplicate
# match pairs, or possibly one feature in image1 matching two or more
# features in images2.  Find and remove these from the set. 
開發者ID:UASLab,項目名稱:ImageAnalysis,代碼行數:60,代碼來源:matcher.py


注:本文中的cv2.findEssentialMat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。