diff --git a/sdk/samples/3d_files/Zaghetto.pcd b/sdk/samples/3d_files/Zaghetto.pcd new file mode 100644 index 0000000..a7cb48d Binary files /dev/null and b/sdk/samples/3d_files/Zaghetto.pcd differ diff --git a/sdk/samples/3d_files/__init__.py b/sdk/samples/3d_files/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sdk/samples/3d_files/add_3d_file.ipynb b/sdk/samples/3d_files/add_3d_file.ipynb new file mode 100644 index 0000000..d17d893 --- /dev/null +++ b/sdk/samples/3d_files/add_3d_file.ipynb @@ -0,0 +1,364 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "tVRzePkximnk" + }, + "source": [ + "# 3D Annotation Guide\n", + "\n", + "This guide will help you upload a Point Cloud to Diffgram using the Diffgram SDK, we will then visualize the point cloud in the 3D Annotation tool and draw some cuboids to annotate the point cloud data. Finally we will generate an export JSON for ingestion on any training model you have.\n", + "\n", + "If you want to read the docs and see some UI screenshots you can visit this same guide on our docs: https://diffgram.readme.io/docs/3d-lidar-annotation-guide\n", + "# Pre-Requisites\n", + "\n", + "\n", + "1. A Working Diffgram Installation (either with docker or directly on diffgram.com)\n", + "2. An API Key for usage with the SDK\n", + "3. A Point Cloud File. (Already Included in the Notebook)\n", + "4. Diffgram SDK installed (>=0.6.0)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000.0 + }, + "id": "okLYrWm1jUTv", + "outputId": "5b8e7d65-0c79-42d8-b8eb-9671d16e4be0" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: diffgram==0.6.0 in /usr/local/lib/python3.7/dist-packages (0.6.0)\n", + "Collecting open3d\n", + " Downloading open3d-0.14.1-cp37-cp37m-manylinux_2_27_x86_64.whl (395.5 MB)\n", + "\u001b[K |████████████████████████████████| 395.5 MB 30 kB/s \n", + "\u001b[?25hRequirement already satisfied: requests>=2.20.1 in /usr/local/lib/python3.7/dist-packages (from diffgram==0.6.0) (2.23.0)\n", + "Requirement already satisfied: imageio>=2.9.0 in /usr/local/lib/python3.7/dist-packages (from diffgram==0.6.0) (2.13.3)\n", + "Requirement already satisfied: opencv-python>=4.0.0.21 in /usr/local/lib/python3.7/dist-packages (from diffgram==0.6.0) (4.1.2.30)\n", + "Requirement already satisfied: scipy>=1.1.0 in /usr/local/lib/python3.7/dist-packages (from diffgram==0.6.0) (1.4.1)\n", + "Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.7/dist-packages (from diffgram==0.6.0) (1.15.0)\n", + "Requirement already satisfied: pillow>=6.1.0 in /usr/local/lib/python3.7/dist-packages (from diffgram==0.6.0) (8.4.0)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from imageio>=2.9.0->diffgram==0.6.0) (1.19.5)\n", + "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.1->diffgram==0.6.0) (3.0.4)\n", + "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.1->diffgram==0.6.0) (2.10)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.1->diffgram==0.6.0) (2021.10.8)\n", + "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.1->diffgram==0.6.0) (1.24.3)\n", + "Requirement already satisfied: scikit-learn>=0.21 in /usr/local/lib/python3.7/dist-packages (from open3d) (1.0.1)\n", + "Collecting pyyaml>=5.4.1\n", + " Downloading PyYAML-6.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (596 kB)\n", + "\u001b[K |████████████████████████████████| 596 kB 41.0 MB/s \n", + "\u001b[?25hRequirement already satisfied: wheel>=0.36.0 in /usr/local/lib/python3.7/dist-packages (from open3d) (0.37.0)\n", + "Requirement already satisfied: pandas>=1.0 in /usr/local/lib/python3.7/dist-packages (from open3d) (1.1.5)\n", + "Requirement already satisfied: ipywidgets>=7.6.0 in /usr/local/lib/python3.7/dist-packages (from open3d) (7.6.5)\n", + "Collecting jupyterlab==3.*,>=3.0.0\n", + " Downloading jupyterlab-3.2.5-py3-none-any.whl (8.6 MB)\n", + "\u001b[K |████████████████████████████████| 8.6 MB 44.1 MB/s \n", + "\u001b[?25hRequirement already satisfied: setuptools>=40.8.0 in /usr/local/lib/python3.7/dist-packages (from open3d) (57.4.0)\n", + "Requirement already satisfied: matplotlib>=3 in /usr/local/lib/python3.7/dist-packages (from open3d) (3.2.2)\n", + "Collecting pygments>=2.7.4\n", + " Downloading Pygments-2.10.0-py3-none-any.whl (1.0 MB)\n", + "\u001b[K |████████████████████████████████| 1.0 MB 55.4 MB/s \n", + "\u001b[?25hCollecting jupyter-packaging~=0.10\n", + " Downloading jupyter_packaging-0.11.1-py2.py3-none-any.whl (14 kB)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from open3d) (4.62.3)\n", + "Collecting addict\n", + " Downloading addict-2.4.0-py3-none-any.whl (3.8 kB)\n", + "Collecting jupyter-server~=1.4\n", + " Downloading jupyter_server-1.13.1-py3-none-any.whl (396 kB)\n", + "\u001b[K |████████████████████████████████| 396 kB 55.3 MB/s \n", + "\u001b[?25hCollecting nbclassic~=0.2\n", + " Downloading nbclassic-0.3.4-py3-none-any.whl (25 kB)\n", + "Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from jupyterlab==3.*,>=3.0.0->open3d) (21.3)\n", + "Requirement already satisfied: jinja2>=2.1 in /usr/local/lib/python3.7/dist-packages (from jupyterlab==3.*,>=3.0.0->open3d) (2.11.3)\n", + "Collecting tornado>=6.1.0\n", + " Downloading tornado-6.1-cp37-cp37m-manylinux2010_x86_64.whl (428 kB)\n", + "\u001b[K |████████████████████████████████| 428 kB 56.6 MB/s \n", + "\u001b[?25hRequirement already satisfied: jupyter-core in /usr/local/lib/python3.7/dist-packages (from jupyterlab==3.*,>=3.0.0->open3d) (4.9.1)\n", + "Collecting jupyterlab-server~=2.3\n", + " Downloading jupyterlab_server-2.9.0-py3-none-any.whl (58 kB)\n", + "\u001b[K |████████████████████████████████| 58 kB 5.7 MB/s \n", + "\u001b[?25hRequirement already satisfied: ipython in /usr/local/lib/python3.7/dist-packages (from jupyterlab==3.*,>=3.0.0->open3d) (5.5.0)\n", + "Requirement already satisfied: widgetsnbextension~=3.5.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.6.0->open3d) (3.5.2)\n", + "Requirement already satisfied: ipykernel>=4.5.1 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.6.0->open3d) (4.10.1)\n", + "Requirement already satisfied: ipython-genutils~=0.2.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.6.0->open3d) (0.2.0)\n", + "Requirement already satisfied: traitlets>=4.3.1 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.6.0->open3d) (5.1.1)\n", + "Requirement already satisfied: nbformat>=4.2.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.6.0->open3d) (5.1.3)\n", + "Requirement already satisfied: jupyterlab-widgets>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.6.0->open3d) (1.0.2)\n", + "Requirement already satisfied: jupyter-client in /usr/local/lib/python3.7/dist-packages (from ipykernel>=4.5.1->ipywidgets>=7.6.0->open3d) (5.3.5)\n", + "Requirement already satisfied: decorator in /usr/local/lib/python3.7/dist-packages (from ipython->jupyterlab==3.*,>=3.0.0->open3d) (4.4.2)\n", + "Requirement already satisfied: simplegeneric>0.8 in /usr/local/lib/python3.7/dist-packages (from ipython->jupyterlab==3.*,>=3.0.0->open3d) (0.8.1)\n", + "Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.4 in /usr/local/lib/python3.7/dist-packages (from ipython->jupyterlab==3.*,>=3.0.0->open3d) (1.0.18)\n", + "Requirement already satisfied: pickleshare in /usr/local/lib/python3.7/dist-packages (from ipython->jupyterlab==3.*,>=3.0.0->open3d) (0.7.5)\n", + "Requirement already satisfied: pexpect in /usr/local/lib/python3.7/dist-packages (from ipython->jupyterlab==3.*,>=3.0.0->open3d) (4.8.0)\n", + "Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from jinja2>=2.1->jupyterlab==3.*,>=3.0.0->open3d) (2.0.1)\n", + "Collecting tomlkit\n", + " Downloading tomlkit-0.7.2-py2.py3-none-any.whl (32 kB)\n", + "Collecting deprecation\n", + " Downloading deprecation-2.1.0-py2.py3-none-any.whl (11 kB)\n", + "Requirement already satisfied: terminado>=0.8.3 in /usr/local/lib/python3.7/dist-packages (from jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.12.1)\n", + "Collecting jupyter-client\n", + " Downloading jupyter_client-7.1.0-py3-none-any.whl (129 kB)\n", + "\u001b[K |████████████████████████████████| 129 kB 63.6 MB/s \n", + "\u001b[?25hRequirement already satisfied: Send2Trash in /usr/local/lib/python3.7/dist-packages (from jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (1.8.0)\n", + "Requirement already satisfied: pyzmq>=17 in /usr/local/lib/python3.7/dist-packages (from jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (22.3.0)\n", + "Collecting websocket-client\n", + " Downloading websocket_client-1.2.3-py3-none-any.whl (53 kB)\n", + "\u001b[K |████████████████████████████████| 53 kB 1.9 MB/s \n", + "\u001b[?25hCollecting anyio<4,>=3.1.0\n", + " Downloading anyio-3.4.0-py3-none-any.whl (78 kB)\n", + "\u001b[K |████████████████████████████████| 78 kB 7.0 MB/s \n", + "\u001b[?25hRequirement already satisfied: prometheus-client in /usr/local/lib/python3.7/dist-packages (from jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.12.0)\n", + "Requirement already satisfied: argon2-cffi in /usr/local/lib/python3.7/dist-packages (from jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (21.1.0)\n", + "Requirement already satisfied: nbconvert in /usr/local/lib/python3.7/dist-packages (from jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (5.6.1)\n", + "Collecting sniffio>=1.1\n", + " Downloading sniffio-1.2.0-py3-none-any.whl (10 kB)\n", + "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from anyio<4,>=3.1.0->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (3.10.0.2)\n", + "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets>=7.6.0->open3d) (2.8.2)\n", + "Requirement already satisfied: nest-asyncio>=1.5 in /usr/local/lib/python3.7/dist-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets>=7.6.0->open3d) (1.5.4)\n", + "Requirement already satisfied: entrypoints in /usr/local/lib/python3.7/dist-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets>=7.6.0->open3d) (0.3)\n", + "Collecting jsonschema>=3.0.1\n", + " Downloading jsonschema-4.2.1-py3-none-any.whl (69 kB)\n", + "\u001b[K |████████████████████████████████| 69 kB 7.0 MB/s \n", + "\u001b[?25hCollecting json5\n", + " Downloading json5-0.9.6-py2.py3-none-any.whl (18 kB)\n", + "Requirement already satisfied: babel in /usr/local/lib/python3.7/dist-packages (from jupyterlab-server~=2.3->jupyterlab==3.*,>=3.0.0->open3d) (2.9.1)\n", + "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from jsonschema>=3.0.1->jupyterlab-server~=2.3->jupyterlab==3.*,>=3.0.0->open3d) (4.8.2)\n", + "Requirement already satisfied: importlib-resources>=1.4.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=3.0.1->jupyterlab-server~=2.3->jupyterlab==3.*,>=3.0.0->open3d) (5.4.0)\n", + "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=3.0.1->jupyterlab-server~=2.3->jupyterlab==3.*,>=3.0.0->open3d) (0.18.0)\n", + "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=3.0.1->jupyterlab-server~=2.3->jupyterlab==3.*,>=3.0.0->open3d) (21.2.0)\n", + "Requirement already satisfied: zipp>=3.1.0 in /usr/local/lib/python3.7/dist-packages (from importlib-resources>=1.4.0->jsonschema>=3.0.1->jupyterlab-server~=2.3->jupyterlab==3.*,>=3.0.0->open3d) (3.6.0)\n", + "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3->open3d) (0.11.0)\n", + "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3->open3d) (3.0.6)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3->open3d) (1.3.2)\n", + "Requirement already satisfied: notebook<7 in /usr/local/lib/python3.7/dist-packages (from nbclassic~=0.2->jupyterlab==3.*,>=3.0.0->open3d) (5.3.1)\n", + "Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.0->open3d) (2018.9)\n", + "Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython->jupyterlab==3.*,>=3.0.0->open3d) (0.2.5)\n", + "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.21->open3d) (1.1.0)\n", + "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.21->open3d) (3.0.0)\n", + "Requirement already satisfied: ptyprocess in /usr/local/lib/python3.7/dist-packages (from terminado>=0.8.3->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.7.0)\n", + "Requirement already satisfied: cffi>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from argon2-cffi->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (1.15.0)\n", + "Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.0.0->argon2-cffi->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (2.21)\n", + "Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.7/dist-packages (from nbconvert->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.8.4)\n", + "Requirement already satisfied: bleach in /usr/local/lib/python3.7/dist-packages (from nbconvert->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (4.1.0)\n", + "Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.7/dist-packages (from nbconvert->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (1.5.0)\n", + "Requirement already satisfied: defusedxml in /usr/local/lib/python3.7/dist-packages (from nbconvert->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.7.1)\n", + "Requirement already satisfied: testpath in /usr/local/lib/python3.7/dist-packages (from nbconvert->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.5.0)\n", + "Requirement already satisfied: webencodings in /usr/local/lib/python3.7/dist-packages (from bleach->nbconvert->jupyter-server~=1.4->jupyterlab==3.*,>=3.0.0->open3d) (0.5.1)\n", + "Installing collected packages: tornado, pygments, jsonschema, sniffio, jupyter-client, websocket-client, anyio, jupyter-server, json5, tomlkit, nbclassic, jupyterlab-server, deprecation, pyyaml, jupyterlab, jupyter-packaging, addict, open3d\n", + " Attempting uninstall: tornado\n", + " Found existing installation: tornado 5.1.1\n", + " Uninstalling tornado-5.1.1:\n", + " Successfully uninstalled tornado-5.1.1\n", + " Attempting uninstall: pygments\n", + " Found existing installation: Pygments 2.6.1\n", + " Uninstalling Pygments-2.6.1:\n", + " Successfully uninstalled Pygments-2.6.1\n", + " Attempting uninstall: jsonschema\n", + " Found existing installation: jsonschema 2.6.0\n", + " Uninstalling jsonschema-2.6.0:\n", + " Successfully uninstalled jsonschema-2.6.0\n", + " Attempting uninstall: jupyter-client\n", + " Found existing installation: jupyter-client 5.3.5\n", + " Uninstalling jupyter-client-5.3.5:\n", + " Successfully uninstalled jupyter-client-5.3.5\n", + " Attempting uninstall: pyyaml\n", + " Found existing installation: PyYAML 3.13\n", + " Uninstalling PyYAML-3.13:\n", + " Successfully uninstalled PyYAML-3.13\n", + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "google-colab 1.0.0 requires tornado~=5.1.0; python_version >= \"3.0\", but you have tornado 6.1 which is incompatible.\n", + "datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible.\u001b[0m\n", + "Successfully installed addict-2.4.0 anyio-3.4.0 deprecation-2.1.0 json5-0.9.6 jsonschema-4.2.1 jupyter-client-7.1.0 jupyter-packaging-0.11.1 jupyter-server-1.13.1 jupyterlab-3.2.5 jupyterlab-server-2.9.0 nbclassic-0.3.4 open3d-0.14.1 pygments-2.10.0 pyyaml-6.0 sniffio-1.2.0 tomlkit-0.7.2 tornado-6.1 websocket-client-1.2.3\n" + ] + }, + { + "data": {}, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--2021-12-14 21:23:07-- https://github.com/mrdoob/three.js/raw/master/examples/models/pcd/binary/Zaghetto.pcd\n", + "Resolving github.com (github.com)... 192.30.255.113\n", + "Connecting to github.com (github.com)|192.30.255.113|:443... connected.\n", + "HTTP request sent, awaiting response... 302 Found\n", + "Location: https://raw.githubusercontent.com/mrdoob/three.js/master/examples/models/pcd/binary/Zaghetto.pcd [following]\n", + "--2021-12-14 21:23:07-- https://raw.githubusercontent.com/mrdoob/three.js/master/examples/models/pcd/binary/Zaghetto.pcd\n", + "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n", + "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 721096 (704K) [application/octet-stream]\n", + "Saving to: ‘Zaghetto.pcd.3’\n", + "\n", + "\rZaghetto.pcd.3 0%[ ] 0 --.-KB/s \rZaghetto.pcd.3 100%[===================>] 704.20K --.-KB/s in 0.02s \n", + "\n", + "2021-12-14 21:23:07 (27.9 MB/s) - ‘Zaghetto.pcd.3’ saved [721096/721096]\n", + "\n" + ] + } + ], + "source": [ + "!pip install diffgram==0.6.0 open3d\n", + "!wget https://github.com/mrdoob/three.js/raw/master/examples/models/pcd/binary/Zaghetto.pcd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "U8NhdfoLjbat" + }, + "source": [ + "# 1. Ingest The Data Using the SDK\n", + "For the data ingestion, we will use the Diffgram SDK. The basic idea is to iterate over the points in the point cloud to create a Diffgram File3D object. Here's the sample code to open our test Point cloud file and upload it to Diffgram.\n", + "\n", + "Some notes:\n", + "\n", + "* We are assuming the filename is Zaghetto.pcd as we are sing the PCD file from the pre-requisites section. Feel free to change this to whatever path you point cloud file is.\n", + "* We are using open3d library to read the point cloud, but feel free to use whatever method you have to get the points data. It can be from a lidar sensor directly, a .obj file, glb file, etc. As long as the correct parameters are provided to the add_point method. You should be good to go.\n", + "\n", + "\n", + "Let's start by importing some librarie and creating a small function to read a PCD file." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "ovv9pSvAju_L" + }, + "outputs": [], + "source": [ + "from diffgram.file.file_3d import File3D\n", + "from diffgram.core.core import Project\n", + "import time\n", + "import open3d as o3d\n", + "import numpy as np \n", + "\n", + "# For reading the PCD file\n", + "def read_pcd_o3d(file_name):\n", + " pcd = o3d.io.read_point_cloud(file_name)\n", + " out_arr = np.asarray(pcd.points)\n", + " return out_arr\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2DwwOD0B13vp" + }, + "source": [ + "Now we can go ahead and setup our Diffgram project. Make sure to replace the credentials with the ones on your project. Check https://diffgram.readme.io/reference/authentication for more info on how to get your credentials." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "vs45iFWQ180U", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "b57fdfe5-9603-4802-8a91-3a8e0791f95c" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO - 2021-12-14 21:23:25,556 - directory - Using Default Dataset ID 6897\n" + ] + } + ], + "source": [ + "project = Project(project_string_id = \"your_project_name\",\n", + " client_id = \"your_client_id\",\n", + " client_secret = \"your_client_secret\")\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "zeLAVr5X2GZ7" + }, + "source": [ + "No we can go ahead and upload the PCD file, we will read each point and append it to our File3D object. After all point are added, we call the upload() function to send it to Diffgram." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "5T4ukfO62RPE", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "b6bdfdfe-ad71-4355-cd90-8b6940d7c05a" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "points_arr = read_pcd_o3d('Zaghetto.pcd')\n", + "\n", + "diffgram_3d_file = File3D(client = project, name = 'face{}.pcd'.format(time.time()))\n", + "\n", + "for i in range(0, len(points_arr)):\n", + " point = points_arr[i]\n", + " diffgram_3d_file.add_point(\n", + " x = point[0],\n", + " y = point[1],\n", + " z = point[2],\n", + " )\n", + "diffgram_3d_file.upload()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WdU1cA7J2U26" + }, + "source": [ + "That's it! You can now visit your project at diffgram.com to see the uploaded PCD file and start annotating it. " + ] + } + ], + "metadata": { + "colab": { + "name": "3d_annotation_guide.ipynb", + "provenance": [], + "collapsed_sections": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/sdk/samples/3d_files/add_3d_file.py b/sdk/samples/3d_files/add_3d_file.py new file mode 100644 index 0000000..b21d39f --- /dev/null +++ b/sdk/samples/3d_files/add_3d_file.py @@ -0,0 +1,37 @@ +from diffgram.file.file_3d import File3D +from diffgram.core.core import Project +import time +import open3d as o3d +import numpy as np + +""" + + This example show how you can upload a 3D point cloud into diffgram using the File3D object. + + Please make sure to replace the project_string_id, client_id and client_secret of your project. +""" + + +# For reading the PCD file +def read_pcd_o3d(file_name): + pcd = o3d.io.read_point_cloud(file_name) + out_arr = np.asarray(pcd.points) + return out_arr + + +project = Project(project_string_id = "your_project_name", + client_id = "your_client_id", + client_secret = "your_client_secret") + +points_arr = read_pcd_o3d('Zaghetto.pcd') + +diffgram_3d_file = File3D(client = project, name = 'face{}.pcd'.format(time.time())) + +for i in range(0, len(points_arr)): + point = points_arr[i] + diffgram_3d_file.add_point( + x = point[0], + y = point[1], + z = point[2], + ) +diffgram_3d_file.upload()