{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":46105,"databundleVersionId":5087314,"sourceType":"competition"},{"sourceId":2632847,"sourceType":"datasetVersion","datasetId":1589971}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-06T02:31:10.810669Z","iopub.execute_input":"2024-02-06T02:31:10.811420Z","iopub.status.idle":"2024-02-06T02:31:11.240282Z","shell.execute_reply.started":"2024-02-06T02:31:10.811385Z","shell.execute_reply":"2024-02-06T02:31:11.239333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install mediapipe --quiet","metadata":{"execution":{"iopub.status.busy":"2024-02-06T02:31:11.241728Z","iopub.execute_input":"2024-02-06T02:31:11.242220Z","iopub.status.idle":"2024-02-06T02:31:23.745725Z","shell.execute_reply.started":"2024-02-06T02:31:11.242184Z","shell.execute_reply":"2024-02-06T02:31:23.744698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nwith open('/kaggle/input/wlasl-processed/WLASL_v0.3.json') as f:\n    f = json.load(f)\nids = [i for i in f if i['gloss'] == 'cloud']\neg = [(os.path.join('/kaggle/input/wlasl-processed/videos',i['video_id'] + '.mp4') , i['frame_start'], i['frame_end'] , i['fps']) for i in ids[0]['instances']]","metadata":{"execution":{"iopub.status.busy":"2024-02-06T02:31:23.747919Z","iopub.execute_input":"2024-02-06T02:31:23.749130Z","iopub.status.idle":"2024-02-06T02:31:24.036422Z","shell.execute_reply.started":"2024-02-06T02:31:23.749078Z","shell.execute_reply":"2024-02-06T02:31:24.034887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_parquet('/kaggle/input/asl-signs/train_landmark_files/16069/100015657.parquet')","metadata":{"execution":{"iopub.status.busy":"2024-02-05T15:56:22.655781Z","iopub.execute_input":"2024-02-05T15:56:22.656747Z","iopub.status.idle":"2024-02-05T15:56:22.916143Z","shell.execute_reply.started":"2024-02-05T15:56:22.656694Z","shell.execute_reply":"2024-02-05T15:56:22.914908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[(df.frame == 103) & (df.type == 'pose')].shape","metadata":{"execution":{"iopub.status.busy":"2024-02-05T15:59:03.605471Z","iopub.execute_input":"2024-02-05T15:59:03.605876Z","iopub.status.idle":"2024-02-05T15:59:03.628119Z","shell.execute_reply.started":"2024-02-05T15:59:03.605843Z","shell.execute_reply":"2024-02-05T15:59:03.626694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport mediapipe as mp\nfrom IPython.display import Image, display\nimport matplotlib.pyplot as plt\n\nmp_drawing = mp.solutions.drawing_utils\nmp_drawing_styles = mp.solutions.drawing_styles\nmp_holistic = mp.solutions.holistic\n\n# def transform(path , start_frame , end_frame , fps):\ndef transform(path ):\n    frame_number = 0\n    frame = []\n    type_ = []\n    index = []\n    x = []\n    y = []\n    z = []\n    \n    cap = cv2.VideoCapture(path)\n#     cap.set(cv2.CAP_PROP_FPS, fps)\n    with mp_holistic.Holistic(min_detection_confidence=0.5,min_tracking_confidence=0.5) as holistic:\n        while cap.isOpened():\n            success, image = cap.read()\n            if not success:\n                break\n            frame_number += 1\n            image.flags.writeable = False\n            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n            results = holistic.process(image)\n            #face\n            if(results.face_landmarks is None):\n                for i in range(468):\n                    frame.append(frame_number)\n                    type_.append(\"face\")\n                    index.append(ind)\n                    x.append(None)\n                    y.append(None)\n                    z.append(None)\n            else:\n                for ind,val in enumerate(results.face_landmarks.landmark):\n                    frame.append(frame_number)\n                    type_.append(\"face\")\n                    index.append(ind)\n                    x.append(val.x)\n                    y.append(val.y)\n                    z.append(val.z)\n            #left hand\n            if(results.left_hand_landmarks is None):\n                for i in range(21):\n                    frame.append(frame_number)\n                    type_.append(\"left_hand\")\n                    index.append(ind)\n                    x.append(None)\n                    y.append(None)\n                    z.append(None)\n            else:\n                for ind,val in enumerate(results.left_hand_landmarks.landmark):\n                    frame.append(frame_number)\n                    type_.append(\"left_hand\")\n                    index.append(ind)\n                    x.append(val.x)\n                    y.append(val.y)\n                    z.append(val.z)\n            #pose\n            if(results.pose_landmarks is None):\n                for i in range(33):\n                    frame.append(frame_number)\n                    type_.append(\"pose\")\n                    index.append(ind)\n                    x.append(None)\n                    y.append(None)\n                    z.append(None)\n            else:\n                for ind,val in enumerate(results.pose_landmarks.landmark):\n                    frame.append(frame_number)\n                    type_.append(\"pose\")\n                    index.append(ind)\n                    x.append(val.x)\n                    y.append(val.y)\n                    z.append(val.z)\n            #right hand\n            if(results.right_hand_landmarks is None):\n                for i in range(21):\n                    frame.append(frame_number)\n                    type_.append(\"right_hand\")\n                    index.append(ind)\n                    x.append(None)\n                    y.append(None)\n                    z.append(None)\n            else:\n                for ind,val in enumerate(results.right_hand_landmarks.landmark):\n                    frame.append(frame_number)\n                    type_.append(\"right_hand\")\n                    index.append(ind)\n                    x.append(val.x)\n                    y.append(val.y)\n                    z.append(val.z)\n            \n    return pd.DataFrame({\n        \"frame\" : frame,\n        \"type\"  : type_,\n        \"landmark_index\" : index,\n        \"x\" : x,\n        \"y\" : y,\n        \"z\" : z\n    })","metadata":{"execution":{"iopub.status.busy":"2024-02-06T02:31:53.491522Z","iopub.execute_input":"2024-02-06T02:31:53.491973Z","iopub.status.idle":"2024-02-06T02:32:09.666918Z","shell.execute_reply.started":"2024-02-06T02:31:53.491941Z","shell.execute_reply":"2024-02-06T02:32:09.665712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = transform(eg[1][0])","metadata":{"execution":{"iopub.status.busy":"2024-02-06T02:32:16.071697Z","iopub.execute_input":"2024-02-06T02:32:16.072176Z","iopub.status.idle":"2024-02-06T02:32:20.120546Z","shell.execute_reply.started":"2024-02-06T02:32:16.072136Z","shell.execute_reply":"2024-02-06T02:32:20.119528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1.shape[0]","metadata":{"execution":{"iopub.status.busy":"2024-02-06T02:32:27.155190Z","iopub.execute_input":"2024-02-06T02:32:27.155623Z","iopub.status.idle":"2024-02-06T02:32:27.163581Z","shell.execute_reply.started":"2024-02-06T02:32:27.155591Z","shell.execute_reply":"2024-02-06T02:32:27.162232Z"},"trusted":true},"execution_count":null,"outputs":[]}]}