def test_create_mosaic_pano(self):
        """Tests creation of a mosaic from warped input images."""
        # Read the origins in the shared warped space.
        books_1_origin, books_2_origin, books_3_origin = self._read_origins()
        read_alpha = -1

        # Read the component images.
        books_1_warped = cv2.imread("test_data/books_1_warped.png", read_alpha)
        books_2 = cv2.imread("test_data/books_2.png")
        books_2 = cv2.cvtColor(books_2, cv2.COLOR_BGR2BGRA)
        books_3_warped = cv2.imread("test_data/books_3_warped.png", read_alpha)

        # Create the panorama mosaic.
        images = (books_1_warped, books_3_warped, books_2)
        origins = (books_1_origin, books_3_origin, books_2_origin)
        pano = pano_stitcher.create_mosaic(images, origins)

        cv2.imwrite("test_data/books_pano.png", pano)
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)
Beispiel #3
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)
Beispiel #4
0
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
pano = ps.create_mosaic([b1_warped, b2, b3_warped],
                        [b1_origins, b2_origins, b3_origins])
cv2.imwrite('my_panos/pano_test.png', pano)
Beispiel #5
0
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 pano_stitcher as ps

print "Loading images..."
# read warped images in
img_1_warped = cv2.imread("my_panos/warp_img1_test.png", -1)
img_2 = cv2.imread("my_panos/warp_img2_test.png")
img_2 = cv2.cvtColor(img_2, cv2.COLOR_BGR2BGRA)
img_3_warped = cv2.imread("my_panos/warp_img3_test.png", -1)

# Create the panorama mosaic.
print "Creating panorama..."
images = (img_1_warped, img_3_warped, img_2)
origins = ((-876, -107), (683, 2), (0, 0))
pano = ps.create_mosaic(images, origins)

print "Writing panaroma to my_panos/our_stitched_image.png"
cv2.imwrite("my_panos/our_stitched_image.png", 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)
Beispiel #8
0
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)])
Beispiel #9
0
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
pano = ps.create_mosaic(
    [b1_warped, b2, b3_warped], [b1_origins, b2_origins, b3_origins])
cv2.imwrite('my_panos/pano_test.png', pano)
    # last image that was warped
    if a is 0:
        right_images_origins.append(origins)
    else:
        prev_origins = right_images_origins[a - 1]
        new_origins = (origins[0] + prev_origins[0],
                       origins[1] + prev_origins[1])
        right_images_origins.append(new_origins)

    a += 1

# PUT IT ALL TOGETHER
print "CREATING MOSAIC!"

# Warped images
all_warped_images = []
all_warped_images.extend(left_warped_images)
middle_image = cv2.cvtColor(middle_image, cv2.COLOR_BGR2BGRA)
all_warped_images.append(middle_image)
all_warped_images.extend(right_warped_images)

# Origins
all_origins = []
all_origins.extend(left_images_origins)
all_origins.append((0, 0))
all_origins.extend(right_images_origins)

res = ps.create_mosaic(all_warped_images, all_origins)

cv2.imwrite(output_mosaic_name, res)
Beispiel #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)

right_pano = rightImages[0]
Beispiel #12
0
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)

warpedimages.append(rawimages[middle])
warpedcorners.append((0, 0))

k = pano_stitcher.create_mosaic(warpedimages, warpedcorners)
cv2.imshow("image", k)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("images/smallPano.png", k)
    else:
        prev_origins = right_images_origins[a - 1]
        new_origins = (
            origins[0] + prev_origins[0],
            origins[1] + prev_origins[1]
        )
        right_images_origins.append(new_origins)

    a += 1

# PUT IT ALL TOGETHER
print "CREATING MOSAIC!"

# Warped images
all_warped_images = []
all_warped_images.extend(left_warped_images)
middle_image = cv2.cvtColor(middle_image, cv2.COLOR_BGR2BGRA)
all_warped_images.append(middle_image)
all_warped_images.extend(right_warped_images)

# Origins
all_origins = []
all_origins.extend(left_images_origins)
all_origins.append((0, 0))
all_origins.extend(right_images_origins)

res = ps.create_mosaic(all_warped_images, all_origins)

cv2.imwrite(output_mosaic_name,
            res)