dataset_88kps+some-updates
This commit is contained in:
100
Karussell/Supervisely/karusell_create_3d_88.ipynb
Normal file
100
Karussell/Supervisely/karusell_create_3d_88.ipynb
Normal file
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"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",
|
||||
"%cd ..\n",
|
||||
"from utils import *\n",
|
||||
"%cd Karusell_implantation\n",
|
||||
"from __init__ import *\n",
|
||||
"box_pict = pict_points(425)\n",
|
||||
"logo, pts_pict = readShield(\"mercedes2.png\")\n",
|
||||
"%cd -\n",
|
||||
"%cd keypoints_88\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'sputnik_88_kps.json', 'r') as file:\n",
|
||||
" img_json = json.load(file)\n",
|
||||
" \n",
|
||||
"img = cv.imread(r'sputnik.png')\n",
|
||||
"\n",
|
||||
"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,89))\n",
|
||||
"df_raw = df.copy()\n",
|
||||
"center = (732, 758)\n",
|
||||
"df -= center\n",
|
||||
"# df[['x', 'y']] = df.values[:, :2]@roration(90) # поворот x и y в плоскости земли\n",
|
||||
"df['z'] = 0\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"df = df.astype(float)\n",
|
||||
"\n",
|
||||
"# img = cv.circle(img, center, 5, (255,255,255), -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'))\n",
|
||||
"\n",
|
||||
"df[['x', 'y']] = df.values[:, :2]@roration(-3)\n",
|
||||
"\n",
|
||||
"rvec, tvec, camMatrx, dist = fit(img.shape[:2], df_raw, df)\n",
|
||||
"imgpts = cv.projectPoints(box_pict, rvec, tvec, camMatrx, dist)[0][:, 0].astype(int)\n",
|
||||
"img = overlaying(logo, img, pts_pict, imgpts[1:])\n",
|
||||
"px.imshow(img)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "12fa21fb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# df.to_csv('karussel_88kps.csv')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
Reference in New Issue
Block a user