{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exploration of 3D Indoor Scenes Datasets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Install useful dependencies for data exploration" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "hideCode": false, "hideOutput": true, "hidePrompt": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting xmltodict\n", " Downloading xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)\n", "Installing collected packages: xmltodict\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.\n", "Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.\n", "To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Successfully installed xmltodict-0.12.0\n" ] } ], "source": [ "import pip\n", "\n", "def install(package):\n", " if hasattr(pip, 'main'):\n", " pip.main(['install', package])\n", " else:\n", " pip._internal.main(['install', package])\n", "\n", "# install('panda3d')\n", "# install('ursina')\n", "# install('ipyvolume')\n", "# install('plotly')\n", "# install('pyquaternion')\n", "# install('xmltodict')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Explore SceneNN scene" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Copy minimalist scene data as string \"sample_scene_data\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "hideCode": true, "hideOutput": true, "hidePrompt": false }, "outputs": [], "source": [ "sample_scene_data = \"\"\"\n", "\n", "\n", "\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load scene data as xml tree element" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('@id', '716508'),\n", " ('@color', '21 156 162'),\n", " ('@text', ''),\n", " ('@nyu_class', 'wall'),\n", " ('@note', ''),\n", " ('@area', '492477'),\n", " ('@obbox',\n", " '-1.2153 -2.52873 -1.90061 4.76056 2.89713 3.58827 0.999386 0.0115122 0.0173149 0.02819'),\n", " ('@aabbox',\n", " '-1.19997 -0.368718 -1.66073 3.51822 2.43698 1.86119'),\n", " ('@local_pose', '1 0 0 0')])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import xmltodict\n", "labels = xmltodict.parse(sample_scene_data)['annotation']['label']\n", "sample_label = labels[0]\n", "# sample_label" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "import pyquaternion\n", "\n", "def obbox_properties_to_vertices(obbox_properties)\n", " \"\"\"\n", " Convert 3D box properties (center, dimensions, and quaternion)\n", " \"\"\"\n", " if isinstance(obbox_properties, str):\n", " obbox_properties = a = map(float, obbox_properties.split())\n", " \n", "# TODO ADD EXTRA CHECKS\n", "# if isinstance(obbox_properties, iterable) and len(obbox_properties == 10) and \n", " \n", " # Extract properties\n", " cx, cy, cz = [0:3]\n", " dx, dy, dz = [3:6]\n", " qx, qy, qz, qw = [6:10]\n", "\n", " # Constants for converting properties to vertices\n", " X = [0, 0, 1, 1, 0, 0, 1, 1]\n", " Y = [0, 1, 1, 0, 0, 1, 1, 0]\n", " Z = [0, 0, 0, 0, 1, 1, 1, 1]\n", "\n", " # Properties to unrotated vertices\n", " x = [c_x + (-0.5 * d_x if v == 0 else 0.5 * d_x) for v in X]\n", " y = [c_y + (-0.5 * d_y if v == 0 else 0.5 * d_y) for v in Y]\n", " z = [c_z + (-0.5 * d_z if v == 0 else 0.5 * d_z) for v in Z]\n", " unrotated_vertices = zip(x, y, z)\n", " \n", " # Apply quaternion\n", " quaternion = pyquaternion.Quaternion(qw, qx, qy, qz)\n", " unrotated_vectors = [(v[0] - cx, v[1] - cy, v[2] - cz) for v in unrotated_vertices]\n", " vectors = [quaternion.rotate(v) for v in unrotated_vectors]\n", " vertices = [(v[0] + cx, v[1] + cy, v[2] + cz) for v in vectors]\n", " \n", " x, y, z = zip(*vertices)\n", " \n", " return x, y, z\n", "\n", "def box_vertices" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'np' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 11\u001b[0m [1, 'magenta']],\n\u001b[1;32m 12\u001b[0m \u001b[0;31m# Intensity of each vertex, which will be interpolated and color-coded\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0mintensity\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinspace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m12\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mendpoint\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 14\u001b[0m \u001b[0mintensitymode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'cell'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;31m# i, j and k give the vertices of triangles\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'np' is not defined" ] } ], "source": [ "import plotly.graph_objects as go\n", "fig = go.Figure(data=[\n", " go.Mesh3d(\n", " # 8 vertices of a cube\n", " x=[0, 0, 1, 1, 0, 0, 1, 1],\n", " y=[0, 1, 1, 0, 0, 1, 1, 0],\n", " z=[0, 0, 0, 0, 1, 1, 1, 1],\n", " colorbar_title='z',\n", " colorscale=[[0, 'gold'],\n", " [0.5, 'mediumturquoise'],\n", " [1, 'magenta']],\n", " # Intensity of each vertex, which will be interpolated and color-coded\n", " intensity = np.linspace(0, 1, 12, endpoint=True),\n", " intensitymode='cell',\n", " # i, j and k give the vertices of triangles\n", " i = [7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2],\n", " j = [3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],\n", " k = [0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],\n", " name='y',\n", " showscale=True\n", " )\n", "])\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Hide code", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }