{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimage_folder='../input/3d-object-detection-for-autonomous-vehicles/train_images'\nimgs=os.listdir(image_folder)\ntype(imgs)\nimgs.sort()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:36:52.220858Z","iopub.execute_input":"2021-10-01T06:36:52.221555Z","iopub.status.idle":"2021-10-01T06:36:54.923797Z","shell.execute_reply.started":"2021-10-01T06:36:52.221518Z","shell.execute_reply":"2021-10-01T06:36:54.922782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom tqdm import tqdm\nfrom PIL import Image\nfrom numpy import asarray\nimg=[]\nfor d in tqdm(range(500)):\n    a=Image.open(image_folder+'/'+imgs[d])\n    img.append(asarray(a))","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:36:54.928741Z","iopub.execute_input":"2021-10-01T06:36:54.930708Z","iopub.status.idle":"2021-10-01T06:37:09.32101Z","shell.execute_reply.started":"2021-10-01T06:36:54.930663Z","shell.execute_reply":"2021-10-01T06:37:09.320325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.cm as cm\nimport matplotlib.animation as animation\n\n # some array of images\nframes = [] # for storing the generated images\nfig = plt.figure()\nfor i in tqdm(range(500)):\n    frames.append([plt.imshow(img[i],animated=True)])\n\nani = animation.ArtistAnimation(fig, frames, interval=50, blit=True,\n                                repeat_delay=1000)\na=ani.save('movie3.mp4')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:37:09.322505Z","iopub.execute_input":"2021-10-01T06:37:09.322774Z","iopub.status.idle":"2021-10-01T06:38:03.424363Z","shell.execute_reply.started":"2021-10-01T06:37:09.32274Z","shell.execute_reply":"2021-10-01T06:38:03.422554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import Video\nVideo(\"./movie3.mp4\")","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:03.425441Z","iopub.status.idle":"2021-10-01T06:38:03.426238Z","shell.execute_reply.started":"2021-10-01T06:38:03.425998Z","shell.execute_reply":"2021-10-01T06:38:03.426036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport json\n\nwith open('../input/3d-object-detection-for-autonomous-vehicles/train_data/category.json') as f:\n  data = json.load(f)","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:21.045125Z","iopub.execute_input":"2021-10-01T06:38:21.045845Z","iopub.status.idle":"2021-10-01T06:38:21.057361Z","shell.execute_reply.started":"2021-10-01T06:38:21.045806Z","shell.execute_reply":"2021-10-01T06:38:21.056622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"attr_tokens=[]\nfor i in data:\n    attr_tokens.append(i['token'])","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:21.059171Z","iopub.execute_input":"2021-10-01T06:38:21.059667Z","iopub.status.idle":"2021-10-01T06:38:21.06693Z","shell.execute_reply.started":"2021-10-01T06:38:21.059632Z","shell.execute_reply":"2021-10-01T06:38:21.066218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# import pandas module \nimport pandas as pd \nfrom tqdm import tqdm\n    \n# making dataframe \ntrain = pd.read_csv(\"../input/3d-object-detection-for-autonomous-vehicles/train.csv\") ","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:21.068387Z","iopub.execute_input":"2021-10-01T06:38:21.068808Z","iopub.status.idle":"2021-10-01T06:38:22.302413Z","shell.execute_reply.started":"2021-10-01T06:38:21.068774Z","shell.execute_reply":"2021-10-01T06:38:22.301599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_columns = ['sample_id', 'object_id', 'center_x', 'center_y', 'center_z',\n                  'width', 'length', 'height', 'yaw', 'class_name']\nobjects = []\nfor sample_id, ps in tqdm(train.values[:1]):\n    object_params = ps.split()\n    n_objects = len(object_params)\n    for i in range(n_objects // 8):\n        x, y, z, w, l, h, yaw, c = tuple(object_params[i * 8: (i + 1) * 8])\n        objects.append([sample_id, i, x, y, z, w, l, h, yaw, c])\n    train_objects = pd.DataFrame(\n    objects,\n    columns = object_columns\n)","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:22.306499Z","iopub.execute_input":"2021-10-01T06:38:22.306735Z","iopub.status.idle":"2021-10-01T06:38:22.322627Z","shell.execute_reply.started":"2021-10-01T06:38:22.306708Z","shell.execute_reply":"2021-10-01T06:38:22.32164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nnumerical_cols = ['object_id', 'center_x', 'center_y', 'center_z', 'width', 'length', 'height', 'yaw']\ntrain_objects[numerical_cols] = np.float32(train_objects[numerical_cols].values)","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:22.324247Z","iopub.execute_input":"2021-10-01T06:38:22.324972Z","iopub.status.idle":"2021-10-01T06:38:22.343371Z","shell.execute_reply.started":"2021-10-01T06:38:22.324932Z","shell.execute_reply":"2021-10-01T06:38:22.342468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_objects","metadata":{"execution":{"iopub.status.busy":"2021-10-01T06:38:22.345972Z","iopub.execute_input":"2021-10-01T06:38:22.346171Z","iopub.status.idle":"2021-10-01T06:38:22.395171Z","shell.execute_reply.started":"2021-10-01T06:38:22.346147Z","shell.execute_reply":"2021-10-01T06:38:22.394293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_objects['center_x'].tolist()\ny=train_objects['center_y'].tolist()\nw=train_objects['width'].tolist()\nh=train_objects['height'].tolist()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T07:03:26.074815Z","iopub.execute_input":"2021-10-01T07:03:26.075548Z","iopub.status.idle":"2021-10-01T07:03:26.080879Z","shell.execute_reply.started":"2021-10-01T07:03:26.075509Z","shell.execute_reply":"2021-10-01T07:03:26.079983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(type(x[0]))\nprint(x[0],y[0],w[0],h[0])\nimage = cv2.imread(\"../input/3d-object-detection-for-autonomous-vehicles/train_images/host-a101-lidar0-1241893239199111666-1241893264098084346.jpeg\",cv2.IMREAD_UNCHANGED)\nplt.imshow(image)\nimage.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-01T07:26:26.357231Z","iopub.execute_input":"2021-10-01T07:26:26.35797Z","iopub.status.idle":"2021-10-01T07:26:26.547715Z","shell.execute_reply.started":"2021-10-01T07:26:26.357929Z","shell.execute_reply":"2021-10-01T07:26:26.545961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nfrom matplotlib import pyplot as plt\nimage = cv2.imread(\"../input/3d-object-detection-for-autonomous-vehicles/train_images/host-a101-lidar0-1241893239199111666-1241893264098084346.jpeg\",cv2.IMREAD_UNCHANGED)\nplt.imshow(image)\n\"\"\"x1=100\ny1=100\nw1=200\nh1=200\ncv2.rectangle(image,(x1,y1),(x1+w1,y1+h1),(255,0,0),2)\"\"\"\n# plt.figure(figsize = (10,20))\nfor x1,y1,w1,h1 in zip(x,y,w,h):\n#     print(x1,y1,w1,h1)\n    m=image.shape\n    x2=int(x1/1024)\n    y2=int(y1/1224)\n    w2=int(w1)*100\n    h2=int(h1)*100\n#     print(x2,y2,w2,h2)\n    cv2.rectangle(image,(x2,y2),(x2+w2,y2+h2),(255,0,0),3)\nplt.imshow(image)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-01T07:26:11.776903Z","iopub.execute_input":"2021-10-01T07:26:11.777384Z","iopub.status.idle":"2021-10-01T07:26:11.974311Z","shell.execute_reply.started":"2021-10-01T07:26:11.777349Z","shell.execute_reply":"2021-10-01T07:26:11.972451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}