{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "MR2.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "TZh8CZsjwfD1", "colab_type": "text" }, "source": [ "\n", "**Meshroom for GoogleColab**\n", "\n", "This is an example on how to use Meshroom in GoogleColab with uploaded images to generate a textured mesh (OBJ) that can be downloaded.\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "3wBFjbjIz9ZX", "colab_type": "text" }, "source": [ "**0. Connect to Google Drive (optional)**\n", "\n", "Paste your authorisation code and resume with Enter\n" ] }, { "cell_type": "code", "metadata": { "id": "NB2T3gnb1GY4", "colab_type": "code", "colab": {} }, "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "Ubwkqcdb5NG_", "colab_type": "text" }, "source": [ "Navigate to the root folder of your Google Drive" ] }, { "cell_type": "code", "metadata": { "id": "HIsZd9i70xVT", "colab_type": "code", "colab": {} }, "source": [ "%cd drive/My Drive" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "ps9PVfiK5WDl", "colab_type": "text" }, "source": [ "Now you can open an existing project folder **or** create a new one" ] }, { "cell_type": "code", "metadata": { "id": "h19HySRO4fC3", "colab_type": "code", "colab": {} }, "source": [ "# open existing\n", "%cd YOUR/PROJECT/FOLDER" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "o0sl70x46PdQ", "colab_type": "text" }, "source": [ "**or**" ] }, { "cell_type": "code", "metadata": { "id": "WIQjlbAP4ncy", "colab_type": "code", "colab": {} }, "source": [ "# create new (replace test with your new folder name)\n", "!mkdir test\n", "%cd test" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "7kShJYbj6GS6", "colab_type": "text" }, "source": [ "**1. Download Meshroom 2019.2**" ] }, { "cell_type": "code", "metadata": { "id": "b4HH_r8CwZXa", "colab_type": "code", "colab": {} }, "source": [ "!wget -N https://github.com/alicevision/meshroom/releases/download/v2019.2.0/Meshroom-2019.2.0-linux.tar.gz\n", "!mkdir meshroom\n", "!tar xzf Meshroom-2019.2.0-linux.tar.gz -C ./meshroom" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "mmSZ5le1wl1r", "colab_type": "text" }, "source": [ "Create folder for image upload (§ can be skipped when using Google Drive)\n" ] }, { "cell_type": "code", "metadata": { "id": "BP3p_lGEq69X", "colab_type": "code", "colab": {} }, "source": [ "!mkdir input" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "bnYMYBQlrL0u", "colab_type": "text" }, "source": [ "Change dir before upload (§)" ] }, { "cell_type": "code", "metadata": { "id": "d9NW_koxq-wj", "colab_type": "code", "colab": {} }, "source": [ "%cd input" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "GqxXyUJYrdV5", "colab_type": "text" }, "source": [ "Test directory (§)" ] }, { "cell_type": "code", "metadata": { "id": "KI9G_jvtrgOm", "colab_type": "code", "colab": {} }, "source": [ "!ls" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "zUd42W__QE2p", "colab_type": "text" }, "source": [ "**2. Upload images** (§)\n", "\n", "(It is possible to link to a GoogleDrive folder instead. Might be added in the future to this notepad)" ] }, { "cell_type": "code", "metadata": { "id": "MpXT0L6ywoSa", "colab_type": "code", "colab": {} }, "source": [ "from google.colab import files\n", "\n", "# optional upload for the images\n", "\n", "uploaded = files.upload()\n", "\n", "for fn in uploaded.keys():\n", " print('User uploaded file \"{name}\" with length {length} bytes'.format( name=fn, length=len(uploaded[fn])))" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "Pc_52Wh9ruQF", "colab_type": "text" }, "source": [ "List uploaded images (§)" ] }, { "cell_type": "code", "metadata": { "id": "RcIHvaherrAb", "colab_type": "code", "colab": {} }, "source": [ "!ls" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "QMspCFLAs_K7", "colab_type": "text" }, "source": [ "Navigate back to content folder (§)" ] }, { "cell_type": "code", "metadata": { "id": "2TywJh4lsNDK", "colab_type": "code", "colab": {} }, "source": [ "%cd ../\n", "!ls" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "4E_kAx-2wq3O", "colab_type": "text" }, "source": [ "\n", "**3. Run Meshroom**\n", "\n", "The node temp files are stored in the **temp** folder, the **out** is only for the final result.\n", "\n", "(It is possible to use a Meshroom graph file (.mg) with costumized parameters and nodes instead of the following default pipeline. Might be added to this notepad in the future)\n", "\n", "When using Google Drive, provide the path to your image folder: --input YOUR/IMAGEs/FOLDER/PATH (the easiest solution is to create a input folder in ./yourprojectfolder/meshroom/Meshroom-2019.2.0/meshroom_photogrammetry with all your images)" ] }, { "cell_type": "code", "metadata": { "id": "3GimHqrGwsmu", "colab_type": "code", "colab": {} }, "source": [ "!mkdir ./out\n", "!./meshroom/Meshroom-2019.2.0/meshroom_photogrammetry --input ./input --output ./out\n" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "49aKN-I0Oddu", "colab_type": "text" }, "source": [ "**4. Preview Mesh using Trimesh (optional)** \n", "\n", "This is experimental and not optimized" ] }, { "cell_type": "code", "metadata": { "id": "uY7p1hKj81Uq", "colab_type": "code", "colab": {} }, "source": [ "!pip install numpy" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "JjZ84tdLRi9b", "colab_type": "code", "colab": {} }, "source": [ "!pip install trimesh" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "exhdh1bu_8VY", "colab_type": "code", "colab": {} }, "source": [ "!ls" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "9SwOo0WCRtmw", "colab_type": "code", "colab": {} }, "source": [ "%cd out" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "kTYgiJauVF26", "colab_type": "text" }, "source": [ "Start preview" ] }, { "cell_type": "code", "metadata": { "id": "fWi3nrpn8_ZT", "colab_type": "code", "colab": {} }, "source": [ "import numpy as np\n", "import trimesh\n", "mesh = trimesh.load_mesh('texturedMesh.obj')\n", "mesh.show()" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "dV3uF6ZmCX-x", "colab_type": "text" }, "source": [ "Read https://trimsh.org/examples/quick_start.html for details\n", "\n", "**Before downloading, change back to the contents folder:**" ] }, { "cell_type": "code", "metadata": { "id": "-6dc2xQ8SJYT", "colab_type": "code", "colab": {} }, "source": [ "%cd ../" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "_EZJtblswuZy", "colab_type": "text" }, "source": [ "\n", "**5. Download**\n", "\n", "Use the prefered download format (tar.gz or zip)\n" ] }, { "cell_type": "code", "metadata": { "id": "IirusdKJwz-6", "colab_type": "code", "colab": {} }, "source": [ "!tar -czvf out.tar.gz ./out\n", "from google.colab import files\n", "\n", "\n", "files.download('out.tar.gz')" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "VQ8F_rxPw4dK", "colab_type": "code", "colab": {} }, "source": [ "!zip -r out.zip ./out\n", "files.download('out.zip')" ], "execution_count": 0, "outputs": [] } ] }