{"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 numpy as np \nimport pandas as pd \nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation\nfrom IPython.display import HTML\n","metadata":{"execution":{"iopub.status.busy":"2023-08-24T07:57:27.482981Z","iopub.execute_input":"2023-08-24T07:57:27.483450Z","iopub.status.idle":"2023-08-24T07:57:27.495450Z","shell.execute_reply.started":"2023-08-24T07:57:27.483415Z","shell.execute_reply":"2023-08-24T07:57:27.494333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv('/kaggle/input/asl-signs/train.csv')\ntrain","metadata":{"execution":{"iopub.status.busy":"2023-08-24T07:57:34.342985Z","iopub.execute_input":"2023-08-24T07:57:34.343408Z","iopub.status.idle":"2023-08-24T07:57:34.527033Z","shell.execute_reply.started":"2023-08-24T07:57:34.343375Z","shell.execute_reply":"2023-08-24T07:57:34.525511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# num = nubber og the sign \nnum=3\ndf = pd.read_parquet('/kaggle/input/asl-signs/'+train[\"path\"][num])\ndf","metadata":{"execution":{"iopub.status.busy":"2023-08-24T08:25:48.365188Z","iopub.execute_input":"2023-08-24T08:25:48.366397Z","iopub.status.idle":"2023-08-24T08:25:48.450594Z","shell.execute_reply.started":"2023-08-24T08:25:48.366351Z","shell.execute_reply":"2023-08-24T08:25:48.449379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['y']=df['y']*-1\n","metadata":{"execution":{"iopub.status.busy":"2023-08-24T08:25:52.158151Z","iopub.execute_input":"2023-08-24T08:25:52.158603Z","iopub.status.idle":"2023-08-24T08:25:52.165724Z","shell.execute_reply.started":"2023-08-24T08:25:52.158566Z","shell.execute_reply":"2023-08-24T08:25:52.164484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Sample data - replace these arrays with your actual landmark data\n# def extract(data,frame_num):\n#     df=data[data['frame']==frame_num]\n#     face_landmarks = df[df['type']=='face'][[\"x\",\"y\",\"z\"]].values\n#     pose_landmarks = df[df['type']=='pose'][[\"x\",\"y\",\"z\"]].values\n#     left_hand_landmarks =df[df['type']=='left_hand'][[\"x\",\"y\",\"z\"]].values\n#     right_hand_landmarks = df[df['type']=='right_hand'][[\"x\",\"y\",\"z\"]].values\n#     return face_landmarks,pose_landmarks , left_hand_landmarks ,right_hand_landmarks\n# face_landmarks,pose_landmarks , left_hand_landmarks ,right_hand_landmarks=extract(df,20)\n# # Set up the mediapipe drawing module","metadata":{"execution":{"iopub.status.busy":"2023-08-24T06:32:35.728594Z","iopub.execute_input":"2023-08-24T06:32:35.729082Z","iopub.status.idle":"2023-08-24T06:32:35.745739Z","shell.execute_reply.started":"2023-08-24T06:32:35.729046Z","shell.execute_reply":"2023-08-24T06:32:35.744793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_hand_points(hand):\n    x = [[hand.iloc[0].x, hand.iloc[1].x, hand.iloc[2].x, hand.iloc[3].x, hand.iloc[4].x], # Thumb\n         [hand.iloc[5].x, hand.iloc[6].x, hand.iloc[7].x, hand.iloc[8].x], # Index\n         [hand.iloc[9].x, hand.iloc[10].x, hand.iloc[11].x, hand.iloc[12].x], \n         [hand.iloc[13].x, hand.iloc[14].x, hand.iloc[15].x, hand.iloc[16].x], \n         [hand.iloc[17].x, hand.iloc[18].x, hand.iloc[19].x, hand.iloc[20].x], \n         [hand.iloc[0].x, hand.iloc[5].x, hand.iloc[9].x, hand.iloc[13].x, hand.iloc[17].x, hand.iloc[0].x]]\n\n    y = [[hand.iloc[0].y, hand.iloc[1].y, hand.iloc[2].y, hand.iloc[3].y, hand.iloc[4].y],  #Thumb\n         [hand.iloc[5].y, hand.iloc[6].y, hand.iloc[7].y, hand.iloc[8].y], # Index\n         [hand.iloc[9].y, hand.iloc[10].y, hand.iloc[11].y, hand.iloc[12].y], \n         [hand.iloc[13].y, hand.iloc[14].y, hand.iloc[15].y, hand.iloc[16].y], \n         [hand.iloc[17].y, hand.iloc[18].y, hand.iloc[19].y, hand.iloc[20].y], \n         [hand.iloc[0].y, hand.iloc[5].y, hand.iloc[9].y, hand.iloc[13].y, hand.iloc[17].y, hand.iloc[0].y]] \n    return x, y\n\ndef get_pose_points(pose):\n    x = [[pose.iloc[8].x, pose.iloc[6].x, pose.iloc[5].x, pose.iloc[4].x, pose.iloc[0].x, pose.iloc[1].x, pose.iloc[2].x, pose.iloc[3].x, pose.iloc[7].x], \n         [pose.iloc[10].x, pose.iloc[9].x], \n         [pose.iloc[22].x, pose.iloc[16].x, pose.iloc[20].x, pose.iloc[18].x, pose.iloc[16].x, pose.iloc[14].x, pose.iloc[12].x, \n          pose.iloc[11].x, pose.iloc[13].x, pose.iloc[15].x, pose.iloc[17].x, pose.iloc[19].x, pose.iloc[15].x, pose.iloc[21].x], \n         [pose.iloc[12].x, pose.iloc[24].x, pose.iloc[26].x, pose.iloc[28].x, pose.iloc[30].x, pose.iloc[32].x, pose.iloc[28].x], \n         [pose.iloc[11].x, pose.iloc[23].x, pose.iloc[25].x, pose.iloc[27].x, pose.iloc[29].x, pose.iloc[31].x, pose.iloc[27].x], \n         [pose.iloc[24].x, pose.iloc[23].x]\n        ]\n\n    y = [[pose.iloc[8].y, pose.iloc[6].y, pose.iloc[5].y, pose.iloc[4].y, pose.iloc[0].y, pose.iloc[1].y, pose.iloc[2].y, pose.iloc[3].y, pose.iloc[7].y], \n         [pose.iloc[10].y, pose.iloc[9].y], \n         [pose.iloc[22].y, pose.iloc[16].y, pose.iloc[20].y, pose.iloc[18].y, pose.iloc[16].y, pose.iloc[14].y, pose.iloc[12].y, \n          pose.iloc[11].y, pose.iloc[13].y, pose.iloc[15].y, pose.iloc[17].y, pose.iloc[19].y, pose.iloc[15].y, pose.iloc[21].y], \n         [pose.iloc[12].y, pose.iloc[24].y, pose.iloc[26].y, pose.iloc[28].y, pose.iloc[30].y, pose.iloc[32].y, pose.iloc[28].y], \n         [pose.iloc[11].y, pose.iloc[23].y, pose.iloc[25].y, pose.iloc[27].y, pose.iloc[29].y, pose.iloc[31].y, pose.iloc[27].y], \n         [pose.iloc[24].y, pose.iloc[23].y]\n        ]\n    return x, y","metadata":{"execution":{"iopub.status.busy":"2023-08-24T08:26:01.988672Z","iopub.execute_input":"2023-08-24T08:26:01.989145Z","iopub.status.idle":"2023-08-24T08:26:02.027564Z","shell.execute_reply.started":"2023-08-24T08:26:01.989110Z","shell.execute_reply":"2023-08-24T08:26:02.026184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def animation_frame(f):\n    frame = df[df.frame==f]\n    left = frame[frame.type=='left_hand']\n    right = frame[frame.type=='right_hand']\n    pose = frame[frame.type=='pose']\n    face = frame[frame.type=='face'][['x', 'y']].values\n    lx, ly = get_hand_points(left)\n    rx, ry = get_hand_points(right)\n    px, py = get_pose_points(pose)\n    ax.clear()\n    ax.plot(face[:,0], face[:,1], '.')\n    for i in range(len(lx)):\n        ax.plot(lx[i], ly[i])\n    for i in range(len(rx)):\n        ax.plot(rx[i], ry[i])\n    for i in range(len(px)):\n        ax.plot(px[i], py[i])\n    plt.xlim(xmin, xmax)\n    plt.ylim(ymin, ymax)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T08:26:05.063084Z","iopub.execute_input":"2023-08-24T08:26:05.063515Z","iopub.status.idle":"2023-08-24T08:26:05.073814Z","shell.execute_reply.started":"2023-08-24T08:26:05.063478Z","shell.execute_reply":"2023-08-24T08:26:05.072730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"The phrase being shown here is: \"+train[\"sign\"][num])\n\n## These values set the limits on the graph to stabilize the video\nxmin = df.x.min() - 0.2\nxmax = df.x.max() + 0.2\nymin = df.y.min() - 0.2\nymax = df.y.max() + 0.2","metadata":{"execution":{"iopub.status.busy":"2023-08-24T08:26:08.983393Z","iopub.execute_input":"2023-08-24T08:26:08.983826Z","iopub.status.idle":"2023-08-24T08:26:11.572212Z","shell.execute_reply.started":"2023-08-24T08:26:08.983793Z","shell.execute_reply":"2023-08-24T08:26:11.570876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots()\nl, = ax.plot([], [])\nanimation = FuncAnimation(fig, func=animation_frame, frames=df.frame.unique())\n\nHTML(animation.to_html5_video())","metadata":{"execution":{"iopub.status.busy":"2023-08-24T08:26:08.983393Z","iopub.execute_input":"2023-08-24T08:26:08.983826Z","iopub.status.idle":"2023-08-24T08:26:11.572212Z","shell.execute_reply.started":"2023-08-24T08:26:08.983793Z","shell.execute_reply":"2023-08-24T08:26:11.570876Z"},"trusted":true},"execution_count":null,"outputs":[]}]}