Пример #1
0
def triangulateWithImagesAndPointFile(filename1, filename2, pointFile, projections_file=None):
    ''' 
    Read images and detect features 
    '''
    current_dir = os.path.dirname(os.path.realpath(__file__))
    img1 = Image(os.path.join(current_dir, filename1))
    # img1.detect_features()
    img2 = Image(os.path.join(current_dir, filename2))
    # img2.detect_features()

    # Match keypoints
    # pts1, pts2, matches = CVFuncs.findMatches(img1, img2, filter=True)
    pts1, pts2, matches = readPointsFromFile(pointFile)

    # CREATE KEYPOINTS
    kp1, kp2 = [], []
    for point1, point2 in zip(pts1, pts2):
        kp1.append(cv2.KeyPoint(point1[0], point1[1], 1))
        kp2.append(cv2.KeyPoint(point2[0], point2[1], 1))

    img1.kps = kp1
    img2.kps = kp2

    # CVFuncs.drawMatches(img1, img2, matches, "new.png")
    # print pts1
    # print pts2

    ''' 
    Find K 
    '''
    K = img1.K

    ''' 
    Get essential or fundamental matrix
    '''

    # F, mask = CVFuncs.findFundamentalMat(pts1, pts2)
    # test.testFundamentalMat(F, pts1, pts2)

    E, mask = CVFuncs.findEssentialMat(pts1, pts2, K)
    # E = CVFuncs.EFromF(F, K)
    # test.testEssentialMat(E, K, pts1, pts2)

    '''
    Get R and T (using artificial ones for now)
    '''
    points, r, t, newMask = CVFuncs.recoverPose(E, pts1, pts2, K)


    ''' 
    Draw image projections using R and T
    '''
    if projections_file:
        draw.drawProjections(pts1, pts2, K.matrix, r, t, projections_file)
    # draw.drawProjections(pts1, pts2, K.matrix, r, t, "manualprojections.ply")
    # draw.drawRandTTransformation(pts1, pts2, K.matrix, r, t, "projections.ply")

    '''
    Triangulate and draw points
    '''
    triangulated = CVFuncs.naiveTriangulate(pts1, pts2, K.matrix, r, t)
    triangulated = draw.transformPointsToViewingCoordinates(triangulated)

    return triangulated, r, t