Skip to content

Instantly share code, notes, and snippets.

@klintan
Last active January 31, 2018 07:28
Show Gist options
  • Save klintan/d16bc352799c1aae6d421cee74e6689f to your computer and use it in GitHub Desktop.
Save klintan/d16bc352799c1aae6d421cee74e6689f to your computer and use it in GitHub Desktop.
Load Semantic3D data
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Most code is adapted from https://github.com/yangyanli/PointCNN/blob/master/data_conversions/prepare_scannet_cls_data.py"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"# the point cloud filename from semantic3D\n",
"filename_pts = \"./data/train/bildstein_station3_xyz_intensity_rgb.txt\""
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"# get each point one per line into a list if the line has 7 components: xyzirgb\n",
"xyzrgb = [pnt.strip().split(' ') for pnt in open(filename_pts, 'r') if len(pnt.strip().split(' ')) == 7]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"# get the x, y, z and r, g, b components as floats of each point \n",
"xyzrgbs = np.array([[float(value) for value in pnt] for pnt in xyzrgb])"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"# better to do all operations per line instead of looping through it twice\n",
"xyzrgbs = [[float(value) for value in pnt.strip().split(' ')] for pnt \n",
" in open(filename_pts, 'r') if len(pnt.strip().split(' ')) == 7]"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(23995481, 7)"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.shape(xyzrgbs)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"# load everything into a pandas dataframe for easier handling\n",
"df = pd.DataFrame(xyzrgbs, columns=['x', 'y', 'z', 'i', 'r', 'g', 'b'])"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" <th>z</th>\n",
" <th>i</th>\n",
" <th>r</th>\n",
" <th>g</th>\n",
" <th>b</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-0.003</td>\n",
" <td>-31.752</td>\n",
" <td>-2.618</td>\n",
" <td>-134.0</td>\n",
" <td>130.0</td>\n",
" <td>146.0</td>\n",
" <td>162.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>-0.001</td>\n",
" <td>-31.756</td>\n",
" <td>-2.807</td>\n",
" <td>-89.0</td>\n",
" <td>142.0</td>\n",
" <td>157.0</td>\n",
" <td>178.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.002</td>\n",
" <td>-31.759</td>\n",
" <td>-2.899</td>\n",
" <td>-281.0</td>\n",
" <td>144.0</td>\n",
" <td>157.0</td>\n",
" <td>176.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>-0.002</td>\n",
" <td>-31.759</td>\n",
" <td>-2.902</td>\n",
" <td>-162.0</td>\n",
" <td>143.0</td>\n",
" <td>156.0</td>\n",
" <td>175.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>-0.003</td>\n",
" <td>-31.759</td>\n",
" <td>-2.902</td>\n",
" <td>-113.0</td>\n",
" <td>143.0</td>\n",
" <td>156.0</td>\n",
" <td>175.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" x y z i r g b\n",
"0 -0.003 -31.752 -2.618 -134.0 130.0 146.0 162.0\n",
"1 -0.001 -31.756 -2.807 -89.0 142.0 157.0 178.0\n",
"2 -0.002 -31.759 -2.899 -281.0 144.0 157.0 176.0\n",
"3 -0.002 -31.759 -2.902 -162.0 143.0 156.0 175.0\n",
"4 -0.003 -31.759 -2.902 -113.0 143.0 156.0 175.0"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment