diff --git a/module2/exo4/exercice.ipynb b/module2/exo4/exercice.ipynb index 254ad3a9ab79f356d51413c146530c591862314b..e7d905194d730a65fc093bec6af0c5e8ca84863d 100644 --- a/module2/exo4/exercice.ipynb +++ b/module2/exo4/exercice.ipynb @@ -16,17 +16,59 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "metadata": { "hideCode": false, "hideOutput": true, "hidePrompt": false }, "outputs": [ + { + "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": [ + "Collecting plotly\n", + " Downloading plotly-4.9.0-py2.py3-none-any.whl (12.9 MB)\n", + "Requirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from plotly) (1.14.0)\n", + "Collecting retrying>=1.3.3\n", + " Downloading retrying-1.3.3.tar.gz (10 kB)\n", + "Building wheels for collected packages: retrying\n", + " Building wheel for retrying (setup.py): started\n", + " Building wheel for retrying (setup.py): finished with status 'done'\n", + " Created wheel for retrying: filename=retrying-1.3.3-py3-none-any.whl size=11430 sha256=aadcf7c4fb481ad4c17a17895314b11482e582e1588b81c4feca2294d100700d\n", + " Stored in directory: /home/jovyan/.cache/pip/wheels/ac/cb/8a/b27bf6323e2f4c462dcbf77d70b7c5e7868a7fbe12871770cf\n", + "Successfully built retrying\n", + "Installing collected packages: retrying, plotly\n", + "Successfully installed plotly-4.9.0 retrying-1.3.3\n", + "Collecting pyquaternion\n", + " Downloading pyquaternion-0.9.5-py3-none-any.whl (14 kB)\n", + "Requirement already satisfied: numpy in /opt/conda/lib/python3.6/site-packages (from pyquaternion) (1.15.2)\n", + "Installing collected packages: pyquaternion\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 pyquaternion-0.9.5\n", "Collecting xmltodict\n", " Downloading xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)\n", "Installing collected packages: xmltodict\n" @@ -61,9 +103,9 @@ "# install('panda3d')\n", "# install('ursina')\n", "# install('ipyvolume')\n", - "# install('plotly')\n", - "# install('pyquaternion')\n", - "# install('xmltodict')" + "install('plotly')\n", + "install('pyquaternion')\n", + "install('xmltodict')" ] }, { @@ -82,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "hideCode": true, "hideOutput": true, @@ -338,30 +380,9 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 3, "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" - } - ], + "outputs": [], "source": [ "import xmltodict\n", "labels = xmltodict.parse(sample_scene_data)['annotation']['label']\n", @@ -371,7 +392,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -411,12 +432,38 @@ " \n", " x, y, z = zip(*vertices)\n", " \n", - " return x, y, z" + " return x, y, z\n", + "\n", + "def aabbox_properties_to_vertices(aabbox_properties):\n", + " \"\"\"\n", + " Convert axis-aligned 3D box properties (center, dimensions, and quaternion)\n", + " \"\"\"\n", + " if isinstance(aabbox_properties, str):\n", + " aabbox_properties = list(map(float, aabbox_properties.split()))\n", + " \n", + " # Extract properties\n", + " minx, miny, minz = aabbox_properties[0:3]\n", + " maxx, maxy, maxz = aabbox_properties[3:6]\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 vertices\n", + " x = [(minx if v == 0 else maxx) for v in X]\n", + " y = [(miny if v == 0 else maxy) for v in Y]\n", + " z = [(minz if v == 0 else maxz) for v in Z]\n", + " vertices = zip(x, y, z)\n", + " \n", + " x, y, z = zip(*vertices)\n", + " \n", + " return x, y, z\n" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -424,7 +471,8 @@ "import numpy as np\n", "\n", "def label_to_mesh_3d(label, color='magenta'):\n", - " x, y, z = obbox_properties_to_vertices(label['@obbox'])\n", + "# x, y, z = obbox_properties_to_vertices(label['@obbox'])\n", + " x, y, z = aabbox_properties_to_vertices(label['@aabbox'])\n", " mesh_3d = go.Mesh3d(\n", " x=x, y=y, z=z,\n", " color=color,\n", @@ -460,7 +508,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 43, "metadata": { "scrolled": true }, @@ -1364,20 +1412,20 @@ "