{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "import open3d as o3d\n", "import numpy as np\n", "import os\n", "import sys\n", "\n", "# monkey patches visualization and provides helpers to load geometries\n", "sys.path.append('..')\n", "import open3d_tutorial as o3dtut\n", "# change to True if you want to interact with the visualization windows\n", "o3dtut.interactive = not \"CI\" in os.environ" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# File IO\n", "This tutorial shows how basic geometries are read and written by Open3D." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Point cloud\n", "This code below reads and writes a point cloud." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Testing IO for point cloud ...\")\n", "pcd = o3d.io.read_point_cloud(\"../../TestData/fragment.pcd\")\n", "print(pcd)\n", "o3d.io.write_point_cloud(\"copy_of_fragment.pcd\", pcd)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`print()` can be used for displaying a summary of pcd.\n", "\n", "By default, Open3D tries to infer the file type by the filename extension. Below is a list of supported point cloud file types.\n", "\n", "Format | Description\n", "---------|---------------\n", "`xyz` | Each line contains `[x, y, z]`, where `x`, `y`, `z` are the 3D coordinates\n", "`xyzn` | Each line contains `[x, y, z, nx, ny, nz]`, where `nx`, `ny`, `nz` are the normals\n", "`xyzrgb` | Each line contains `[x, y, z, r, g, b]`, where `r`, `g`, `b` are in floats of range `[0, 1]`\n", "`pts` | The first line is an integer representing the number of points. Each subsequent line contains `[x, y, z, i, r, g, b]`, where `r`, `g`, `b` are in `uint8`\n", "`ply` | See [Polygon File Format](http://paulbourke.net/dataformats/ply), the ply file can contain both point cloud and mesh data\n", "`pcd` | See [Point Cloud Data](http://pointclouds.org/documentation/tutorials/pcd_file_format.php)\n", "\n", "It’s also possible to specify the file type explicitly. In this case, the file extension will be ignored." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pcd = o3d.io.read_point_cloud(\"../../TestData/my_points.txt\", format='xyz')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mesh\n", "This code below reads and writes a mesh." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Testing IO for meshes ...\")\n", "mesh = o3d.io.read_triangle_mesh(\"../../TestData/knot.ply\")\n", "print(mesh)\n", "o3d.io.write_triangle_mesh(\"copy_of_knot.ply\", mesh)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compared to the data structure of point cloud, mesh has triangles that define the 3D surface.\n", "\n", "By default, Open3D tries to infer the file type by the filename extension. Below is a list of supported triangle mesh file types.\n", "\n", "Format | Description\n", "---------|---------------\n", "`ply` | See [Polygon File Format](http://paulbourke.net/dataformats/ply/), the ply file can contain both point cloud and mesh data\n", "`stl` | See [StereoLithography](http://www.fabbers.com/tech/STL_Format)\n", "`obj` | See [Object Files](http://paulbourke.net/dataformats/obj/)\n", "`off` | See [Object File Format](http://www.geomview.org/docs/html/OFF.html)\n", "`gltf` | See [GL Transmission Format](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Image\n", "The code below reads and writes an image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Testing IO for images ...\")\n", "img = o3d.io.read_image(\"../../TestData/lena_color.jpg\")\n", "print(img)\n", "o3d.io.write_image(\"copy_of_lena_color.jpg\", img)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The size of the image is readily displayed using `print(img)`." ] } ], "metadata": { "celltoolbar": "Edit Metadata", "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.7.7" } }, "nbformat": 4, "nbformat_minor": 2 }