Files
place6D_Nurburgring/Karussell/Supervisely/karusel_create_3d.ipynb
2022-05-18 12:01:01 +03:00

103 lines
2.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9b13894c",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import pandas as pd\n",
"import numpy as np\n",
"import cv2 as cv\n",
"import plotly.express as px\n",
"import plotly.graph_objects as go\n",
"\n",
"def roration(x):\n",
" x = np.deg2rad(x)\n",
" return np.array([[np.cos(x), -np.sin(x)],\n",
" [np.sin(x), np.cos(x)]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3fc452a2",
"metadata": {},
"outputs": [],
"source": [
"with open(r'karusel.png.json', 'r') as file:\n",
" img_json = json.load(file)\n",
" \n",
"img = cv.imread(r'karusel.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfc4d7b9",
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame([img_json['objects'][i]['points']['exterior'][0]\\\n",
" for i in range(len(img_json['objects']))], columns=['x','y'], index=range(1,25))\n",
"center = (1165, 874)\n",
"df -= center\n",
"df[['x', 'y']] = df.values[:, :2]@roration(90) # поворот x и y в плоскости земли\n",
"df['z'] = 0\n",
"\n",
"df = df.loc[[1, 7, 6, 20, 2, 3, 4, 17, 18, 5, 22, 19, 8,\n",
" 16, 9, 10, 11, 21, 15, 12, 14, 13, 24, 23]] # упорядочивание индексов\n",
"\n",
"df.index = list(range(1, 25))\n",
"df = df.astype(float)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "07361259",
"metadata": {},
"outputs": [],
"source": [
"img = cv.circle(img, center, 5, (0,0,0), -1)\n",
"fig = px.imshow(img)\n",
"fig.add_trace(go.Scatter(x=df.x+center[0], y=df.y+center[1], text=df.index,\n",
" marker=dict(color='red', size=5), mode='markers'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f18693d",
"metadata": {},
"outputs": [],
"source": [
"df[['x', 'y']] = df.values[:, :2]@roration(44)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}