示例#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_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
示例#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)
示例#4
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)