def main():
    cards_1 = cv2.imread("cards_1.jpg")
    cards_2 = cv2.imread("cards_2.jpg")
    cards_3 = cv2.imread("cards_3.jpg")

    H_1 = pano_stitcher.homography(cards_2, cards_1)
    H_2 = pano_stitcher.homography(cards_2, cards_2)
    H_3 = pano_stitcher.homography(cards_2, cards_3)

    cards_1_warped, cards_1_origin = pano_stitcher.warp_image(cards_1, H_1)
    cards_2_warped, cards_2_origin = pano_stitcher.warp_image(cards_2, H_2)
    cards_3_warped, cards_3_origin = pano_stitcher.warp_image(cards_3, H_3)

    images = (cards_1_warped, cards_3_warped, cards_2_warped)
    origins = (cards_1_origin, cards_3_origin, cards_2_origin)

    pano = pano_stitcher.create_mosaic(images, origins)

    cv2.imwrite("pano.png", pano)
    def test_warp_image_translate(self):
        """Tests warping an image by a translation-only homography."""
        image = cv2.imread("test_data/houses_left.png")
        rows, cols, _ = image.shape

        # A homography that only translates the image should not change shape.
        t_x = 101
        t_y = 42
        H_translate = self._translate_homography(t_x, t_y)
        image_translated, origin = pano_stitcher.warp_image(image, H_translate)
        translated_rows, translated_cols, _ = image_translated.shape
        self.assertEqual(rows, translated_rows)
        self.assertEqual(cols, translated_cols)
        self.assertEqual((t_x, t_y), origin)
    def test_warp_image_scale(self):
        """Tests warping an image by a scale-only homography."""
        image = cv2.imread("test_data/houses_left.png")
        rows, cols, _ = image.shape

        # A homography that scales the image by 2x returns an image with
        # correct shape.
        scale = 2.0
        H_scale = self._scale_homography(scale)
        image_scaled, origin = pano_stitcher.warp_image(image, H_scale)
        scaled_rows, scaled_cols, _ = image_scaled.shape
        self.assertEqual(rows * scale, scaled_rows)
        self.assertEqual(cols * scale, scaled_cols)
        self.assertEqual((0, 0), origin)
예제 #4
0
def create_pano1():
    gray_left = cv2.imread("my_panos/images/left.png",
                           cv2.CV_LOAD_IMAGE_GRAYSCALE)
    left = cv2.imread("my_panos/images/left.png")  # , -1)
    gray_middle = cv2.imread("my_panos/images/middle.png",
                             cv2.CV_LOAD_IMAGE_GRAYSCALE)
    middle = cv2.imread("my_panos/images/middle.png")
    # ***middle = cv2.cvtColor(middle, cv2.COLOR_BGR2BGRA)
    gray_right = cv2.imread("my_panos/images/right.png",
                            cv2.CV_LOAD_IMAGE_GRAYSCALE)
    right = cv2.imread("my_panos/images/right.png")  # , -1)
    # rows, cols = left_image.shape

    # cv2.namedWindow('image', cv2.WINDOW_NORMAL)
    # cv2.imshow("image", left_image)
    # cv2.waitKey(0)

    # compute homography for left image
    homography1 = pano_stitcher.homography(gray_middle, gray_left)
    # warp left image
    warped_left, origin1 = pano_stitcher.warp_image(left, homography1)

    # compute homography for right image
    homography2 = pano_stitcher.homography(gray_middle, gray_right)
    # warp right image
    warped_right, origin2 = pano_stitcher.warp_image(right, homography2)

    # print("warped_left: ", warped_left.shape)
    # print("middle: ", middle.shape)
    # print("warped_right: ", warped_right.shape)

    images = (warped_left, warped_right, middle)
    origins = (origin1, origin2, (0, 0))
    mosaic1 = pano_stitcher.create_mosaic(images, origins)

    cv2.imwrite("feetMosaic.png", mosaic1)
예제 #5
0
panorama.
"""

import cv2
import numpy as np
import pano_stitcher as ps

# Open all of the images
b1 = cv2.imread('my_panos/src/part1.jpg')
b2 = cv2.imread('my_panos/src/part2.jpg')
b3 = cv2.imread('my_panos/src/part3.jpg')

# Find a homography to warp image 1
# onto image 2, warp it
b1_homog = ps.homography(b2, b1)
b1_warped, b1_origins = ps.warp_image(b1, b1_homog)
print 'origins for warped b1:', b1_origins

# Set b2 to be at the origin
b2_origins = (0, 0)

# Find a homography to warp image 3
# onto image 2, warp it
b3_homog = ps.homography(b2, b3)
b3_warped, b3_origins = ps.warp_image(b3, b3_homog)
print 'origins for warped b3:', b3_origins

# Convert b2 to a 4-channel image
b2 = cv2.cvtColor(b2, cv2.COLOR_BGR2BGRA)

# Create the mosaic, write it out
예제 #6
0
import cv2
import numpy as np
import pano_stitcher as ps

# Load source images
p1 = cv2.imread('my_panos/src/part1.jpg')
p2 = cv2.imread('my_panos/src/part2.jpg')
p3 = cv2.imread('my_panos/src/part3.jpg')

# Warp first image by the homography mapping
# the first image to the second image
p1_homography = ps.homography(p2, p1)
p1_warped, p1_origin = ps.warp_image(p1, p1_homography)

# Warp third image by the homography mapping
# the third image to the second image
p3_homography = ps.homography(p2, p3)
p3_warped, p3_origin = ps.warp_image(p3, p3_homography)

# Add alpha channel to second image
blue, green, red = cv2.split(p2)
alpha = np.zeros(green.shape, dtype=np.uint8)
alpha.fill(255)
p2 = cv2.merge([blue, green, red, alpha])


# Composite warped images and image in target plane
pano = ps.create_mosaic(
    [p1_warped, p2, p3_warped], [p1_origin, (0, 0), p3_origin])

cv2.imwrite('my_panos/pano.jpg', pano)
import cv2
import numpy as np
import pano_stitcher as ps

# Load source images
p1 = cv2.imread('my_panos/src/part1.jpg')
p2 = cv2.imread('my_panos/src/part2.jpg')
p3 = cv2.imread('my_panos/src/part3.jpg')

# Warp first image by the homography mapping
# the first image to the second image
p1_homography = ps.homography(p2, p1)
p1_warped, p1_origin = ps.warp_image(p1, p1_homography)

# Warp third image by the homography mapping
# the third image to the second image
p3_homography = ps.homography(p2, p3)
p3_warped, p3_origin = ps.warp_image(p3, p3_homography)

# Add alpha channel to second image
blue, green, red = cv2.split(p2)
alpha = np.zeros(green.shape, dtype=np.uint8)
alpha.fill(255)
p2 = cv2.merge([blue, green, red, alpha])

# Composite warped images and image in target plane
pano = ps.create_mosaic([p1_warped, p2, p3_warped],
                        [p1_origin, (0, 0), p3_origin])

cv2.imwrite('my_panos/pano.jpg', pano)
예제 #8
0
left = cv2.imread("3.jpg", -1)
right = cv2.imread("5.jpg", -1)
right2 = cv2.imread("6.jpg", -1)
middle = cv2.imread("4.jpg", -1)
left1 = cv2.imread("2.jpg", -1)
left2 = cv2.imread("1.jpg", -1)

leftImages = [left2, left1, left]
rightImages = [right2, right]

while len(leftImages) > 1:
    print "Left Image Loop"
    image = leftImages.pop(0)
    h**o = pano_stitcher.homography(leftImages[0], image)
    warped, origin = pano_stitcher.warp_image(image, h**o)
    leftImages[0] = pano_stitcher.create_mosaic(
        [warped, cv2.cvtColor(leftImages[0], cv2.COLOR_BGR2BGRA)],
        [origin, (0, 0)])
    leftImages[0] = cv2.cvtColor(leftImages[0], cv2.COLOR_BGRA2BGR)

left_pano = leftImages[0]
cv2.imshow("sup", left_pano)
cv2.waitKey()

while len(rightImages) > 1:
    print "Right Image Loop"
    image = rightImages.pop(0)
    h**o = pano_stitcher.homography(rightImages[0], image)
    warped, origin = pano_stitcher.warp_image(image, h**o)
    rightImages[0] = pano_stitcher.create_mosaic(
예제 #9
0
panorama.
"""

import cv2
import numpy as np
import pano_stitcher as ps

# Open all of the images
b1 = cv2.imread('my_panos/src/part1.jpg')
b2 = cv2.imread('my_panos/src/part2.jpg')
b3 = cv2.imread('my_panos/src/part3.jpg')

# Find a homography to warp image 1
# onto image 2, warp it
b1_homog = ps.homography(b2, b1)
b1_warped, b1_origins = ps.warp_image(b1, b1_homog)
print 'origins for warped b1:', b1_origins

# Set b2 to be at the origin
b2_origins = (0, 0)

# Find a homography to warp image 3
# onto image 2, warp it
b3_homog = ps.homography(b2, b3)
b3_warped, b3_origins = ps.warp_image(b3, b3_homog)
print 'origins for warped b3:', b3_origins

# Convert b2 to a 4-channel image
b2 = cv2.cvtColor(b2, cv2.COLOR_BGR2BGRA)

# Create the mosaic, write it out
for i in left:
    # Show the name of the image
    print sys.argv[i]

    # Open it and append it to the left images list
    left_images.append(cv2.imread(sys.argv[i]))

    # If closest to the middle image, warp into that perspective
    # Otherwise, warp into the perspective of the last image
    # that was warped
    if a is 0:
        h = ps.homography(middle_image, left_images[a])
    else:
        h = ps.homography(left_warped_images[a - 1], left_images[a])
    warped, origins = ps.warp_image(left_images[a], h)
    left_warped_images.append(warped)

    # If closest to the middle image, use normal origins
    # Otherwise, use the origins + the origins of the
    # last image that was warped
    if a is 0:
        left_images_origins.append(origins)
    else:
        prev_origins = left_images_origins[a - 1]
        new_origins = (origins[0] + prev_origins[0],
                       origins[1] + prev_origins[1])
        left_images_origins.append(new_origins)

    left_warped_images = list(reversed(left_warped_images))
    left_images_origins = list(reversed(left_images_origins))
예제 #11
0
left = cv2.imread("3.jpg",-1)
right = cv2.imread("5.jpg",-1)
right2 = cv2.imread("6.jpg",-1)
middle = cv2.imread("4.jpg",-1)
left1 = cv2.imread("2.jpg",-1)
left2 = cv2.imread("1.jpg",-1)

leftImages = [left2, left1, left]
rightImages = [right2, right]

while len(leftImages) > 1:
	print "Left Image Loop"
	image = leftImages.pop(0)
	h**o = pano_stitcher.homography(leftImages[0], image)
	warped, origin = pano_stitcher.warp_image(image, h**o)
	leftImages[0] = pano_stitcher.create_mosaic([warped, cv2.cvtColor(leftImages[0],cv2.COLOR_BGR2BGRA)], [origin, (0,0)])
	leftImages[0] = cv2.cvtColor(leftImages[0],cv2.COLOR_BGRA2BGR)

left_pano = leftImages[0]
cv2.imshow("sup", left_pano)
cv2.waitKey()

while len(rightImages) > 1:
	print "Right Image Loop"
	image = rightImages.pop(0)
	h**o = pano_stitcher.homography(rightImages[0], image)
	warped, origin = pano_stitcher.warp_image(image, h**o)
	rightImages[0] = pano_stitcher.create_mosaic([warped, cv2.cvtColor(rightImages[0],cv2.COLOR_BGR2BGRA)], [origin, (0,0)])
	leftImages[0] = cv2.cvtColor(leftImages[0],cv2.COLOR_BGRA2BGR)
예제 #12
0
    rawimages.append(cv2.imread(imgdir+"3-" + str(i)+".jpg"))

rightmost -= leftmost
middle -= leftmost
leftmost -= leftmost

rawimages[middle] = cv2.cvtColor(rawimages[middle], cv2.COLOR_BGR2BGRA)

warpedimages = []
warpedcorners = []
for i in range(0,middle):
    l = rawimages[i]
    r = rawimages[i+1]
    h = pano_stitcher.homography(r, l)
    print("Finished left homography #"+str(i))
    warpedimage, warpedcorner = pano_stitcher.warp_image(l, h)
    print("Warped image #"+str(i))
    warpedimages.append(warpedimage)
    warpedcorners.append(warpedcorner)



for i in range(middle,rightmost) :
    l = rawimages[i]
    r = rawimages[i+1]
    h = pano_stitcher.homography(l,r)
    print("Finished right homography #"+str(i))
    warpedimage, warpedcorner = pano_stitcher.warp_image(r, h)
    print("Warped image #"+str(i))
    warpedimages.append(warpedimage)
    warpedcorners.append(warpedcorner)
예제 #13
0
for i in left:
    # Show the name of the image
    print sys.argv[i]

    # Open it and append it to the left images list
    left_images.append(cv2.imread(sys.argv[i]))

    # If closest to the middle image, warp into that perspective
    # Otherwise, warp into the perspective of the last image
    # that was warped
    if a is 0:
        h = ps.homography(middle_image, left_images[a])
    else:
        h = ps.homography(left_warped_images[a - 1], left_images[a])
    warped, origins = ps.warp_image(left_images[a], h)
    left_warped_images.append(warped)

    # If closest to the middle image, use normal origins
    # Otherwise, use the origins + the origins of the
    # last image that was warped
    if a is 0:
        left_images_origins.append(origins)
    else:
        prev_origins = left_images_origins[a - 1]
        new_origins = (
            origins[0] + prev_origins[0],
            origins[1] + prev_origins[1]
        )
        left_images_origins.append(new_origins)