Skip to content

Instantly share code, notes, and snippets.

@raphael2692
Forked from natowi/MeshroomColab.ipynb
Last active December 3, 2020 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphael2692/a8a47fa9c23edda0c01b9178c31a4dca to your computer and use it in GitHub Desktop.
Save raphael2692/a8a47fa9c23edda0c01b9178c31a4dca to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"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": {
"base_uri": "https://localhost:8080/",
"height": 55
},
"outputId": "12ea6b64-046c-4a76-81be-6a226d4f76fd"
},
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "kpxHm8UdUpzc",
"colab_type": "text"
},
"source": [
"Create a temp folder in your istance"
]
},
{
"cell_type": "code",
"metadata": {
"id": "HIsZd9i70xVT",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 90
},
"outputId": "b8860bf9-5239-4383-fbd3-a0b797e77929"
},
"source": [
"%cd /content\n",
"!mkdir temp\n",
"!mkdir meshroom\n",
"!ls # check dir"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "7kShJYbj6GS6",
"colab_type": "text"
},
"source": [
"**1. Download Meshroom 2019.2**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "oDLXn_M6R-zz",
"colab_type": "code",
"colab": {}
},
"source": [
"%cd temp\n",
"!wget -N https://github.com/alicevision/meshroom/releases/download/v2019.2.0/Meshroom-2019.2.0-linux.tar.gz\n",
"!tar -xvf Meshroom-2019.2.0-linux.tar.gz -C ../meshroom"
],
"execution_count": null,
"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": {
"base_uri": "https://localhost:8080/",
"height": 72
},
"outputId": "915c1df4-72bc-4510-a6b5-4a3ede8466e3"
},
"source": [
"%cd /content\n",
"!mkdir input\n",
"!ls # check dir"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "zUd42W__QE2p",
"colab_type": "text"
},
"source": [
"**2. Upload images** (§ optional)\n",
"\n",
"(It is possible to link to a GoogleDrive folder instead. Just comment the following cell and use the next one.)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "MpXT0L6ywoSa",
"colab_type": "code",
"colab": {}
},
"source": [
"%cd input\n",
"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])))\n",
"\n",
"!ls # list uploaded images"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "QMspCFLAs_K7",
"colab_type": "text"
},
"source": [
"Copy image from your drive to /content/input (§)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "nlqgbqAHZbeM",
"colab_type": "code",
"colab": {}
},
"source": [
"# !cp -r \"/content/drive/My Drive/path/to/your/images\" /content/input"
],
"execution_count": null,
"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 **/tmp/MeshroomCache** folder, the **/content/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",
"!/content/meshroom/Meshroom-2019.2.0/meshroom_photogrammetry --input input --output out"
],
"execution_count": null,
"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": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "f7270208-2bc2-47c3-8e11-fbb81e823a53"
},
"source": [
"!pip install numpy"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "JjZ84tdLRi9b",
"colab_type": "code",
"colab": {}
},
"source": [
"!pip install trimesh"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "exhdh1bu_8VY",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "0d587e70-65cc-4fdb-ead5-44d30fe1ab48"
},
"source": [
"!ls"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "9SwOo0WCRtmw",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "35b0665b-76f3-4966-f7f9-dfabbdba3a81"
},
"source": [
"%cd out"
],
"execution_count": null,
"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": null,
"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": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "77a89d5b-88d0-4c79-bff0-692fc2005180"
},
"source": [
"%cd ../"
],
"execution_count": null,
"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": null,
"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": null,
"outputs": []
}
],
"metadata": {
"colab": {
"name": "MeshroomColab.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment