Created
March 26, 2020 09:56
-
-
Save nils-holmberg/48a8ccee65064d0d71b0c08e09873b6d to your computer and use it in GitHub Desktop.
image-stitching-200326.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "image-stitching-200326.ipynb", | |
"provenance": [], | |
"toc_visible": true, | |
"authorship_tag": "ABX9TyPR5GrlHQKQltLOn8Ivba4q", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/nils-holmberg/48a8ccee65064d0d71b0c08e09873b6d/image-stitching-200326.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Ki-gNi4oEbDE", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import cv2" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "UeDRFI3EFZtp", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "a240b44a-5530-418b-ecbf-9ea82a19e1a8" | |
}, | |
"source": [ | |
"cv2.__version__" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'4.1.2'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 2 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "_B0-VsSlFeBl", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#mode=0 photos, mode=1 scans\n", | |
"stitcher = cv2.Stitcher.create(mode=1)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ZKpiqKBXFohG", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#!pip3 install opencv-python==4.1.0.25" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7nzm0XdIF23E", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#upload images in google colab left pane" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NgJFcTxLIUi4", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "b231a8d0-1736-401d-c68d-200a884bc934" | |
}, | |
"source": [ | |
"!ls ./" | |
], | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"frame-0021.png\tframe-0022.png\tframe-0023.png\tsample_data\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "eU_X77_4IY7H", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"img1 = cv2.imread(\"frame-0021.png\")\n", | |
"img2 = cv2.imread(\"frame-0022.png\")" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Zd3Pnk6WJd1-", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"result = stitcher.stitch((img1, img2))" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "jqkZtQ8NJrN0", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "ce1f0627-6f2e-413c-ccc6-f7157872af06" | |
}, | |
"source": [ | |
"cv2.imwrite(\"stitched.png\", result[1])" | |
], | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 15 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "QIERRDSXJ3Wk", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "d8bef544-ed0c-4259-9a64-1a9df72d8bd9" | |
}, | |
"source": [ | |
"!ls" | |
], | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"frame-0021.png\tframe-0022.png\tframe-0023.png\tsample_data stitched.png\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Ifo0dnYoJ4lU", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"fl = [\"frame-0021.png\",\"frame-0022.png\",\"frame-0023.png\"]" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "AOBemvzpL-nA", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "15722037-9b3d-4b74-e26b-7f5babb63827" | |
}, | |
"source": [ | |
"print(fl)" | |
], | |
"execution_count": 18, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"['frame-0021.png', 'frame-0022.png', 'frame-0023.png']\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "8AGStPqUMCDe", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "c77d45d4-5804-451d-d852-4104b8534244" | |
}, | |
"source": [ | |
"type(fl)" | |
], | |
"execution_count": 19, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"list" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 19 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "56VTYGk_MF3g", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "fbf7709d-0893-4630-ff3b-c73040c1bede" | |
}, | |
"source": [ | |
"fl[0]" | |
], | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'frame-0021.png'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 20 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PvpHOvVFMR1j", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"img1 = cv2.imread(fl[0])" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Zbx-FU6DMaxZ", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "d430c88d-3c5b-4467-ceaa-cc91a8f665a5" | |
}, | |
"source": [ | |
"img1 = cv2.imread(fl[0])\n", | |
"for f in fl[1:]:\n", | |
" #print(f)\n", | |
" img2 = cv2.imread(f)\n", | |
" result = stitcher.stitch((img1, img2))\n", | |
" img1 = result[1]\n", | |
"cv2.imwrite(\"stitched.png\", img1)" | |
], | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 24 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "40IZzeqcM-lx", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment