コード例 #1
0
ファイル: assignment8_test.py プロジェクト: Faye413/Panorama-
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 = assignment8.findMatchesBetweenImages(
        image_1, image_2, 20)
    homography = assignment8.findHomography(image_1_kp, image_2_kp, matches)
    warped_image = assignment8.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
ファイル: assignment8_test.py プロジェクト: Faye413/Panorama-
        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 = \
                assignment8.findMatchesBetweenImages(cur_img, new_img, 20)
            print "Computing homography."
            homography = assignment8.findHomography(image_1_kp, image_2_kp,
                                                    matches)
            print "Warping the image pair."
            cur_img = assignment8.warpImagePair(cur_img, new_img, homography)
        
        print "Writing output image to {}".format(outfolder)
        cv2.imwrite(os.path.join(outfolder, setname) + ".jpg", cur_img)