{"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":"example code to generate your own dataset\n\n\n'''\npip install mediapipe==0.9.0.1 \n'''\n\nvideo_file = '/home/titanx/Downloads/cat.mp4'\ncap = cv2.VideoCapture(video_file)\nholistic = mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.1)\n\nvideo_df = []\nframe_no=0\nwhile cap.isOpened():\n\tprint('\\r',frame_no,end='')\n\tsuccess, image = cap.read()\n\n\tif not success: break\n\timage = cv2.resize(image, dsize=None, fx=4, fy=4)\n\theight,width,_ = image.shape\n\n\t#print(image.shape)\n\timage.flags.writeable = False\n\timage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\tresult = holistic.process(image)\n\n\t#---\n\tdata = [] \n\tfy = height/width\n\n\t# -----------------------------------------------------\n\tif result.face_landmarks is None:\n\t\tfor i in range(468): #\n\t\t\tdata.append({\n\t\t\t\t'type' : 'face',\n\t\t\t\t'landmark_index' : i,\n\t\t\t\t'x' : np.nan,\n\t\t\t\t'y' : np.nan,\n\t\t\t\t'z' : np.nan,\n\t\t\t})\n\telse:\n\t\tassert(len(result.face_landmarks.landmark)==468)\n\t\tfor i in range(468): #\n\t\t\txyz = result.face_landmarks.landmark[i]\n\t\t\tdata.append({\n\t\t\t\t'type' : 'face',\n\t\t\t\t'landmark_index' : i,\n\t\t\t\t'x' : xyz.x,\n\t\t\t\t'y' : xyz.y *fy,\n\t\t\t\t'z' : xyz.z,\n\t\t\t})\n\n\t# -----------------------------------------------------\n\tif result.left_hand_landmarks is None:\n\t\tfor i in range(21):  #\n\t\t\tdata.append({\n\t\t\t\t'type': 'left_hand',\n\t\t\t\t'landmark_index': i,\n\t\t\t\t'x': np.nan,\n\t\t\t\t'y': np.nan,\n\t\t\t\t'z': np.nan,\n\t\t\t})\n\telse:\n\t\tassert (len(result.left_hand_landmarks.landmark) == 21)\n\t\tfor i in range(21):  #\n\t\t\txyz = result.left_hand_landmarks.landmark[i]\n\t\t\tdata.append({\n\t\t\t\t'type': 'left_hand',\n\t\t\t\t'landmark_index': i,\n\t\t\t\t'x': xyz.x,\n\t\t\t\t'y': xyz.y *fy,\n\t\t\t\t'z': xyz.z,\n\t\t\t})\n\n\t# -----------------------------------------------------\n\t#if result.pose_world_landmarks is None:\n\tif result.pose_landmarks is None:\n\t\tfor i in range(33):  #\n\t\t\tdata.append({\n\t\t\t\t'type': 'pose',\n\t\t\t\t'landmark_index': i,\n\t\t\t\t'x': np.nan,\n\t\t\t\t'y': np.nan,\n\t\t\t\t'z': np.nan,\n\t\t\t})\n\telse:\n\t\tassert (len(result.pose_landmarks.landmark) == 33)\n\t\tfor i in range(33):  #\n\t\t\txyz = result.pose_landmarks.landmark[i]\n\t\t\tdata.append({\n\t\t\t\t'type': 'pose',\n\t\t\t\t'landmark_index': i,\n\t\t\t\t'x': xyz.x,\n\t\t\t\t'y': xyz.y *fy,\n\t\t\t\t'z': xyz.z,\n\t\t\t})\n\n\t# -----------------------------------------------------\n\tif result.right_hand_landmarks is None:\n\t\tfor i in range(21):  #\n\t\t\tdata.append({\n\t\t\t\t'type': 'right_hand',\n\t\t\t\t'landmark_index': i,\n\t\t\t\t'x': np.nan,\n\t\t\t\t'y': np.nan,\n\t\t\t\t'z': np.nan,\n\t\t\t})\n\telse:\n\t\tassert (len(result.right_hand_landmarks.landmark) == 21)\n\t\tfor i in range(21):  #\n\t\t\txyz = result.right_hand_landmarks.landmark[i]\n\t\t\tdata.append({\n\t\t\t\t'type': 'right_hand',\n\t\t\t\t'landmark_index': i,\n\t\t\t\t'x': xyz.x,\n\t\t\t\t'y': xyz.y *fy,\n\t\t\t\t'z': xyz.z,\n\t\t\t})\n\t\tzz=0\n\n\tframe_df = pd.DataFrame(data)\n\tframe_df.loc[:,'frame'] =  frame_no\n\tframe_df.loc[:, 'height'] = height/width\n\tframe_df.loc[:, 'width'] = width/width\n\tvideo_df.append(frame_df)\n\n\n\t#=========================\n\tframe_no +=1\n\nvideo_df = pd.concat(video_df)\nprint(video_df)\nholistic.close()\nvideo_df.to_csv('video_df.csv')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]}]}