예제 #1
0
def test_warpImagePair():
    image_1 = cv2.imread("images/source/panorama_1/1.jpg")
    image_2 = cv2.imread("images/source/panorama_1/2.jpg")
    image_1_kp, image_2_kp, matches = assignment6.findMatchesBetweenImages(
        image_1, image_2, 20)
    homography = assignment6.findHomography(image_1_kp, image_2_kp, matches)
    warped_image = assignment6.warpImagePair(image_1, image_2, homography)

    # Read in answer that has the correct type / shape.
    type_answer = cv2.imread("images/testing/warped_image_1_2.jpg")

    print "Evaluating warpImagePair."
    # Test for type.
    if not type(warped_image) == type(type_answer):
        raise TypeError(
            ("Error - warped_image has type {}. " +
             "Expected type is {}.").format(type(warped_image),
                                            type(type_answer)))
    # Test for shape.
    if abs(np.sum(np.subtract(warped_image.shape, type_answer.shape))) > 200:
        print("WARNING - warped_image has shape {}. " +
              "Expected shape is around {}.").format(warped_image.shape,
                                                     type_answer.shape)
    print "warpImagePair testing passed."

    return True
예제 #2
0
def test_findMatchesBetweenImages():
    """ This script will perform a unit test on the matching function.
    """
    # Hard code output matches.
    image_1 = cv2.imread("images/source/panorama_1/1.jpg")
    image_2 = cv2.imread("images/source/panorama_1/2.jpg")

    print "Evaluating findMatchesBetweenImages."

    image_1_kp, image_2_kp, matches = \
        assignment6.findMatchesBetweenImages(image_1, image_2, 20)

    if not type(image_1_kp) == list:
        raise TypeError(
            "Error - image_1_kp has type {}. Expected type is {}.".format(
                type(image_1_kp), list))

    if len(image_1_kp) > 0 and \
        not type(image_1_kp[0]) == type(cv2.KeyPoint()):
        raise TypeError(("Error - The items in image_1_kp have type {}. " + \
                         "Expected type is {}.").format(type(image_1_kp[0]),
                                                        type(cv2.KeyPoint())))

    if not type(image_2_kp) == list:
        raise TypeError(
            "Error - image_2_kp has type {}. Expected type is {}.".format(
                type(image_2_kp), list))

    if len(image_2_kp) > 0 and \
        not type(image_2_kp[0]) == type(cv2.KeyPoint()):
        raise TypeError(("Error - The items in image_2_kp have type {}. " + \
                         "Expected type is {}.").format(type(image_2_kp[0]),
                                                        type(cv2.KeyPoint())))

    if not type(matches) == list:
        raise TypeError(
            "Error - matches has type {}. Expected type is {}. ".format(
                type(matches), list))

    if len(matches) > 0 and not type(matches[0]) == type(cv2.DMatch()):
        raise TypeError(("Error - The items in matches have type {}. " + \
                         "Expected type is {}.").format(type(matches[0]),
                                                        type(cv2.DMatch())))
    print "findMatchesBetweenImages testing passed."
    return True
예제 #3
0
        panorama_filepaths = []

        for filename in filenames:
            name, ext = os.path.splitext(filename)
            if ext.lower() in exts:
                panorama_filepaths.append(os.path.join(dirname, filename))
        panorama_filepaths.sort()

        for pan_fp in panorama_filepaths:
            panorama_inputs.append(cv2.imread(pan_fp))

        if len(panorama_inputs) > 1:
            print ("Found {} images in folder {}. " + \
                   "Processing them.").format(len(panorama_inputs), dirname)
        else:
            continue

        print "Computing matches."
        cur_img = panorama_inputs[0]
        for new_img in panorama_inputs[1:]:
            image_1_kp, image_2_kp, matches = \
                assignment6.findMatchesBetweenImages(cur_img, new_img, 5)
            print "Computing homography."
            homography = assignment6.findHomography(image_1_kp, image_2_kp,
                                                    matches)
            print "Warping the image pair."
            cur_img = assignment6.warpImagePair(cur_img, new_img, homography)

        print "Writing output image to {}".format(outfolder)
        cv2.imwrite(os.path.join(outfolder, setname) + ".jpg", cur_img)