Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

trying to make the combo video thing

Jon4a39a9b87ac2
diff --git a/jon_scratch/create_retina_centered_video_from_pupil_labs_data.ipynb b/jon_scratch/create_retina_centered_video_from_pupil_labs_data.ipynb
index 6009b894..6753d12e 100644
--- a/jon_scratch/create_retina_centered_video_from_pupil_labs_data.ipynb
+++ b/jon_scratch/create_retina_centered_video_from_pupil_labs_data.ipynb
@@ -15,7 +15,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -31,19 +31,12 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Using matplotlib backend: TkAgg\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
- "%matplotlib "
+ "# !pip install pyqt5\n",
+ "%matplotlib qt"
]
},
{
@@ -55,7 +48,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -90,7 +83,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -110,19 +103,9 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "video_width : 1280\n",
- "video_height: 720\n",
- "video_framerate: 59\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"video_width = int(pupil_export_video_cap_object.get(cv2.CAP_PROP_FRAME_WIDTH))\n",
"video_height = int(pupil_export_video_cap_object.get(cv2.CAP_PROP_FRAME_HEIGHT))\n",
@@ -141,7 +124,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -152,7 +135,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -163,7 +146,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -183,20 +166,9 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "nans in gaze_on_screen_x: 0\n",
- "nans in gaze_on_screen_y: 0\n",
- "nans in gaze_on_screen_x_filtered: 0\n",
- "nans in gaze_on_screen_y_filtered: 0\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"\n",
"\n",
@@ -214,41 +186,18 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([604.55319855, 604.96959393, 605.31206249, ..., 475.75659332,\n",
- " 475.6162116 , 475.47394065])"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"gaze_on_screen_x_filtered"
]
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "<matplotlib.legend.Legend at 0x2b6409dab88>"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"\n",
"plt.cla()\n",
@@ -271,18 +220,9 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "c:\\Users\\jonma\\miniconda3\\envs\\freemocap-env\\lib\\site-packages\\numpy\\lib\\nanfunctions.py:1111: RuntimeWarning: Mean of empty slice\n",
- " return np.nanmean(a, axis, out=out, keepdims=keepdims)\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"number_of_frames = np.max(world_camera_frame_index_all)\n",
"number_of_frames\n",
@@ -357,25 +297,6 @@
"gaze_on_screen_y_downsampled_smoothed = savgol_filter(gaze_on_screen_y_downsampled, smoothWinLength, smoothOrder)"
]
},
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.close(\"all\")\n",
- "fig2 = plt.Figure()\n",
- "ax = plt.gca()\n",
- "ax.plot(gaze_on_screen_x_downsampled, '.-', label = 'gaze_on_screen_x_downsampled')\n",
- "ax.plot(gaze_on_screen_y_downsampled, '.-',label = 'gaze_on_screen_y_downsampled')\n",
- "ax.plot(gaze_on_screen_x_downsampled_smoothed, '.-', label = 'gaze_on_screen_x_downsampled_smoothed')\n",
- "ax.plot(gaze_on_screen_y_downsampled_smoothed, '.-',label = 'gaze_on_screen_y_downsampled_smoothed')\n",
- "\n",
- "ax.set_ylim((0-100, video_width+100))\n",
- "ax.legend(loc='upper left')\n",
- "\n"
- ]
- },
{
"cell_type": "code",
"execution_count": null,
@@ -397,6 +318,27 @@
"print(f\"nans in gaze_on_screen_y_downsampled_gapfilled: {np.isnan(gaze_on_screen_y_downsampled_gapfilled).sum()}\")"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.close(\"all\")\n",
+ "fig2 = plt.Figure()\n",
+ "ax = plt.gca()\n",
+ "ax.plot(gaze_on_screen_x_downsampled, '.-', label = 'gaze_on_screen_x_downsampled')\n",
+ "ax.plot(gaze_on_screen_y_downsampled, '.-',label = 'gaze_on_screen_y_downsampled')\n",
+ "ax.plot(gaze_on_screen_x_downsampled_smoothed, '.-', label = 'gaze_on_screen_x_downsampled_smoothed')\n",
+ "ax.plot(gaze_on_screen_y_downsampled_smoothed, '.-',label = 'gaze_on_screen_y_downsampled_smoothed')\n",
+ "ax.plot(gaze_on_screen_x_downsampled_gapfilled, '.-', label = 'gaze_on_screen_x_downsampled_gapfilled')\n",
+ "ax.plot(gaze_on_screen_y_downsampled_gapfilled, '.-',label = 'gaze_on_screen_y_downsampled_gapfilled')\n",
+ "\n",
+ "ax.set_ylim((0-100, video_width+100))\n",
+ "ax.legend(loc='upper left')\n",
+ "\n"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -469,114 +411,183 @@
"metadata": {},
"outputs": [],
"source": [
- "pupil_world_video_cap_object = cv2.VideoCapture(str(pupil_world_video_path))\n",
- "\n",
- "this_retinal_aligned_image = big_blank_image.copy()\n",
- "this_retinal_aligned_image[:, video_width-video_height:(video_width-video_height)+2*video_height,:]\n",
- "\n",
"retinal_video_save_path = pupil_data_exports_path / 'retinal_aligned_video.mp4'\n",
- "retinal_video_writer = cv2.VideoWriter(str(retinal_video_save_path),\n",
- " cv2.VideoWriter_fourcc(*\"MP4V\"),\n",
- " video_framerate, \n",
- " (this_retinal_aligned_image.shape[0], this_retinal_aligned_image.shape[0]))\n",
- "\n",
- "success = True\n",
- "for frame_number in range(gaze_on_screen_x_downsampled_gapfilled.shape[0]):\n",
- " success, image= pupil_world_video_cap_object.read()\n",
- " if not success:\n",
- " print('failed to read frame')\n",
- " break\n",
"\n",
- " # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
+ "make_retinal_video = False\n",
+ "if make_retinal_video:\n",
+ " pupil_world_video_cap_object = cv2.VideoCapture(str(pupil_world_video_path))\n",
+ "\n",
" this_retinal_aligned_image = big_blank_image.copy()\n",
+ " this_retinal_aligned_image[:, video_width-video_height:(video_width-video_height)+2*video_height,:]\n",
"\n",
- " #pull out gaze data to align image to retinal coordinates\n",
- " gx = int(gaze_on_screen_x_downsampled_gapfilled[frame_number])\n",
- " gy = int(gaze_on_screen_y_downsampled_gapfilled[frame_number])\n",
+ " retinal_video_writer = cv2.VideoWriter(str(retinal_video_save_path),\n",
+ " cv2.VideoWriter_fourcc(*\"MP4V\"),\n",
+ " video_framerate, \n",
+ " (this_retinal_aligned_image.shape[0], this_retinal_aligned_image.shape[0]))\n",
"\n",
- " bottom_edge_row = int(video_height)*2-(int(video_height)-gy)\n",
- " top_edge_row = int(video_height) -(int(video_height)-gy)\n",
- " left_col = (int(video_width)-gx)\n",
- " right_col = int(video_width)+(int(video_width)-gx)\n",
+ " success = True\n",
+ " for frame_number in range(gaze_on_screen_x_downsampled_gapfilled.shape[0]):\n",
+ " success, image= pupil_world_video_cap_object.read()\n",
+ " if not success:\n",
+ " print('failed to read frame')\n",
+ " break\n",
"\n",
- " cols = np.arange(top_edge_row,bottom_edge_row)\n",
+ " # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
+ " this_retinal_aligned_image = big_blank_image.copy()\n",
"\n",
- " #if things are going off screen, use whatever gaze data worked most recently\n",
- " if top_edge_row < 0:\n",
- " gy = previous_gy\n",
- " top_edge_row = int(video_height) -(int(video_height)-gy)\n",
- " bottom_edge_row = int(video_height)*2-(int(video_height)-gy)\n",
+ " #pull out gaze data to align image to retinal coordinates\n",
+ " gx = int(gaze_on_screen_x_downsampled_gapfilled[frame_number])\n",
+ " gy = int(gaze_on_screen_y_downsampled_gapfilled[frame_number])\n",
"\n",
- " if bottom_edge_row > int(video_height)*2:\n",
- " gy = previous_gy\n",
- " top_edge_row = int(video_height) -(int(video_height)-gy)\n",
" bottom_edge_row = int(video_height)*2-(int(video_height)-gy)\n",
- " \n",
- " if left_col < 0:\n",
- " gx = previous_gx\n",
- " right_col = int(video_width)+(int(video_width)-gx)\n",
+ " top_edge_row = int(video_height) -(int(video_height)-gy)\n",
" left_col = (int(video_width)-gx)\n",
- " \n",
- " if right_col > int(video_width)*2:\n",
- " gx = previous_gx\n",
" right_col = int(video_width)+(int(video_width)-gx)\n",
- " left_col = (int(video_width)-gx)\n",
"\n",
- " previous_gx = gx \n",
- " previous_gy = gy\n",
+ " cols = np.arange(top_edge_row,bottom_edge_row)\n",
+ "\n",
+ " #if things are going off screen, use whatever gaze data worked most recently\n",
+ " if top_edge_row < 0:\n",
+ " gy = previous_gy\n",
+ " top_edge_row = int(video_height) -(int(video_height)-gy)\n",
+ " bottom_edge_row = int(video_height)*2-(int(video_height)-gy)\n",
+ "\n",
+ " if bottom_edge_row > int(video_height)*2:\n",
+ " gy = previous_gy\n",
+ " top_edge_row = int(video_height) -(int(video_height)-gy)\n",
+ " bottom_edge_row = int(video_height)*2-(int(video_height)-gy)\n",
+ " \n",
+ " if left_col < 0:\n",
+ " gx = previous_gx\n",
+ " right_col = int(video_width)+(int(video_width)-gx)\n",
+ " left_col = (int(video_width)-gx)\n",
+ " \n",
+ " if right_col > int(video_width)*2:\n",
+ " gx = previous_gx\n",
+ " right_col = int(video_width)+(int(video_width)-gx)\n",
+ " left_col = (int(video_width)-gx)\n",
+ "\n",
+ " previous_gx = gx \n",
+ " previous_gy = gy\n",
+ " \n",
+ " this_retinal_aligned_image[top_edge_row:bottom_edge_row, left_col:right_col,:] = image\n",
+ "\n",
+ " this_retinal_aligned_image[circular_mask==0] = 0\n",
+ "\n",
+ "\n",
+ " this_retinal_aligned_image = this_retinal_aligned_image[:, video_width-video_height:(video_width-video_height)+2*video_height,:]\n",
+ "\n",
+ " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
+ " (int(video_height), 0), \n",
+ " (int(video_height), int(video_height)*2), \n",
+ " (0,0,0,255), \n",
+ " 5)\n",
+ " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
+ " (0, int(video_height)), \n",
+ " (int(video_width)*2, \n",
+ " int(video_height)), \n",
+ " (0,0,0,255), \n",
+ " 5)\n",
+ " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
+ " (int(video_height), 0), \n",
+ " (int(video_height), int(video_height)*2), \n",
+ " (255,255,255,255), \n",
+ " 1,)\n",
+ " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
+ " (0, int(video_height)), \n",
+ " (int(video_width)*2, \n",
+ " int(video_height)), \n",
+ " (255,255,255,255), \n",
+ " 1)\n",
+ " this_retinal_aligned_image = cv2.circle(this_retinal_aligned_image, \n",
+ " (int(video_height), int(video_height)),\n",
+ " 20,\n",
+ " (0,0,0,255), \n",
+ " 5)\n",
+ " this_retinal_aligned_image = cv2.circle(this_retinal_aligned_image, \n",
+ " (int(video_height), int(video_height)),\n",
+ " 20,\n",
+ " (255,255,255,255), \n",
+ " 1)\n",
+ "\n",
+ " # plt.cla()\n",
+ " # plt.imshow(this_retinal_aligned_image[:,:,:3]) \n",
+ " # plt.show()\n",
+ " # plt.pause(0.1)\n",
+ "\n",
+ " retinal_video_writer.write(this_retinal_aligned_image) \n",
+ "\n",
+ " if frame_number%100 == 0:\n",
+ " print(f'frame_number: {frame_number}')\n",
+ "\n",
+ " retinal_video_writer.release()\n",
+ " print('done!')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "make Pupil Exports + Retinal + Gaze Trace Vid"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "frame_number: 1\n"
+ ]
+ }
+ ],
+ "source": [
+ "plt.close('all')\n",
+ "retinal_video_save_path = pupil_data_exports_path / 'retinal_aligned_video.mp4'\n",
+ "\n",
+ "retinal_vid_cap = cv2.VideoCapture(str(retinal_video_save_path))\n",
+ "pupil_export_vid_cap = cv2.VideoCapture(str(pupil_export_video_path))\n",
+ "\n",
+ "combo_video_save_path = pupil_data_exports_path / 'combo_retinal_world_video.mp4'\n",
+ "\n",
+ "\n",
+ "combo_video_writer = cv2.VideoWriter(str(combo_video_save_path),\n",
+ " cv2.VideoWriter_fourcc(*\"MP4V\"),\n",
+ " video_framerate, \n",
+ " (video_height,2000))\n",
+ "\n",
+ "pup_success = True\n",
+ "ret_success = True\n",
+ "frame_number = 0\n",
+ "while pup_success and ret_success:\n",
+ " frame_number += 1\n",
+ " print(f'frame_number: {frame_number}')\n",
+ " ret_success, ret_image = retinal_vid_cap.read()\n",
+ " if not ret_success:\n",
+ " print('ret - failed to read frame')\n",
+ " break\n",
+ "\n",
+ " pup_success, pup_image = pupil_export_vid_cap.read()\n",
+ " if not pup_success:\n",
+ " print('pup - failed to read frame')\n",
+ " break\n",
" \n",
- " this_retinal_aligned_image[top_edge_row:bottom_edge_row, left_col:right_col,:] = image\n",
- "\n",
- " this_retinal_aligned_image[circular_mask==0] = 0\n",
- "\n",
- "\n",
- " this_retinal_aligned_image = this_retinal_aligned_image[:, video_width-video_height:(video_width-video_height)+2*video_height,:]\n",
- "\n",
- " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
- " (int(video_height), 0), \n",
- " (int(video_height), int(video_height)*2), \n",
- " (0,0,0,255), \n",
- " 5)\n",
- " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
- " (0, int(video_height)), \n",
- " (int(video_width)*2, \n",
- " int(video_height)), \n",
- " (0,0,0,255), \n",
- " 5)\n",
- " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
- " (int(video_height), 0), \n",
- " (int(video_height), int(video_height)*2), \n",
- " (255,255,255,255), \n",
- " 1,)\n",
- " this_retinal_aligned_image = cv2.line(this_retinal_aligned_image, \n",
- " (0, int(video_height)), \n",
- " (int(video_width)*2, \n",
- " int(video_height)), \n",
- " (255,255,255,255), \n",
- " 1)\n",
- " this_retinal_aligned_image = cv2.circle(this_retinal_aligned_image, \n",
- " (int(video_height), int(video_height)),\n",
- " 20,\n",
- " (0,0,0,255), \n",
- " 5)\n",
- " this_retinal_aligned_image = cv2.circle(this_retinal_aligned_image, \n",
- " (int(video_height), int(video_height)),\n",
- " 20,\n",
- " (255,255,255,255), \n",
- " 1)\n",
- "\n",
- " # plt.cla()\n",
- " # plt.imshow(this_retinal_aligned_image[:,:,:3]) \n",
- " # plt.show()\n",
- " # plt.pause(0.1)\n",
- "\n",
- " retinal_video_writer.write(this_retinal_aligned_image) \n",
- "\n",
- " if frame_number%100 == 0:\n",
- " print(f'frame_number: {frame_number}')\n",
- "\n",
- "retinal_video_writer.release()"
+ " ret_image = cv2.cvtColor(ret_image, cv2.COLOR_BGR2RGB)\n",
+ " pup_image = cv2.cvtColor(pup_image, cv2.COLOR_BGR2RGB)\n",
+ "\n",
+ " shrink_ret_image = cv2.resize(ret_image, (0,0), fx=0.5, fy=0.5)\n",
+ " combo_image = np.hstack((shrink_ret_image, pup_image))\n",
+ "\n",
+ " combo_video_writer.write(combo_image) \n"
]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": []
}
],
"metadata": {
diff --git a/jon_scratch/sleap/sleap_freemocap_processing.ipynb b/jon_scratch/sleap/sleap_freemocap_processing.ipynb
index 53a0c9b3..07072623 100644
--- a/jon_scratch/sleap/sleap_freemocap_processing.ipynb
+++ b/jon_scratch/sleap/sleap_freemocap_processing.ipynb
@@ -22,30 +22,24 @@
},
{
"cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": false,
- "pycharm": {
- "name": "#%%\n"
- }
- },
+ "execution_count": null,
"outputs": [],
"source": [
"import numpy as np\n",
"import h5py\n",
"from pathlib import Path\n",
"from aniposelib.cameras import CameraGroup\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
+ ],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
- },
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
"outputs": [],
"source": [
"session_id = 'sesh_2022-05-07_17_15_05_pupil_wobble_juggle_0'\n",
@@ -61,144 +55,32 @@
"sleap_h5_files_path = sleap_data_path / 'output_h5_files'\n",
"\n",
"sleap_predictions_file = sleap_data_path / 'labels.v000.slp'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
+ ],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
- },
- "outputs": [],
- "source": [
- "anipose_camera_calibration_object = CameraGroup.load(camera_calibration_file_path)"
- ]
+ }
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
+ "outputs": [],
+ "source": [
+ "anipose_camera_calibration_object = CameraGroup.load(camera_calibration_file_path)"
+ ],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "===filename===\n",
- "C:\\Users\\jonma\\Dropbox\\FreeMoCapProject\\FreeMocap_Data\\sesh_2022-05-07_17_15_05_pupil_wobble_juggle_0\\sleap_data\\output_h5_files\\labels_v000_analysis_video_0.h5\n",
- "\n",
- "===HDF5 datasets===\n",
- "['edge_inds', 'edge_names', 'instance_scores', 'node_names', 'point_scores', 'track_names', 'track_occupancy', 'tracking_scores', 'tracks']\n",
- "\n",
- "===locations data shape===\n",
- "(5090, 10, 2, 1)\n",
- "\n",
- "===nodes===\n",
- "0: red_ball\n",
- "1: green_ball\n",
- "2: orange_ball\n",
- "3: wobble_0\n",
- "4: wobble_1\n",
- "5: wobble_2\n",
- "6: wobble_3\n",
- "7: wobble_4\n",
- "8: wheel_center\n",
- "9: wheel_edge\n",
- "\n",
- "===filename===\n",
- "C:\\Users\\jonma\\Dropbox\\FreeMoCapProject\\FreeMocap_Data\\sesh_2022-05-07_17_15_05_pupil_wobble_juggle_0\\sleap_data\\output_h5_files\\labels_v000_analysis_video_1.h5\n",
- "\n",
- "===HDF5 datasets===\n",
- "['edge_inds', 'edge_names', 'instance_scores', 'node_names', 'point_scores', 'track_names', 'track_occupancy', 'tracking_scores', 'tracks']\n",
- "\n",
- "===locations data shape===\n",
- "(5090, 10, 2, 1)\n",
- "\n",
- "===nodes===\n",
- "0: red_ball\n",
- "1: green_ball\n",
- "2: orange_ball\n",
- "3: wobble_0\n",
- "4: wobble_1\n",
- "5: wobble_2\n",
- "6: wobble_3\n",
- "7: wobble_4\n",
- "8: wheel_center\n",
- "9: wheel_edge\n",
- "\n",
- "===filename===\n",
- "C:\\Users\\jonma\\Dropbox\\FreeMoCapProject\\FreeMocap_Data\\sesh_2022-05-07_17_15_05_pupil_wobble_juggle_0\\sleap_data\\output_h5_files\\labels_v000_analysis_video_2.h5\n",
- "\n",
- "===HDF5 datasets===\n",
- "['edge_inds', 'edge_names', 'instance_scores', 'node_names', 'point_scores', 'track_names', 'track_occupancy', 'tracking_scores', 'tracks']\n",
- "\n",
- "===locations data shape===\n",
- "(5090, 10, 2, 1)\n",
- "\n",
- "===nodes===\n",
- "0: red_ball\n",
- "1: green_ball\n",
- "2: orange_ball\n",
- "3: wobble_0\n",
- "4: wobble_1\n",
- "5: wobble_2\n",
- "6: wobble_3\n",
- "7: wobble_4\n",
- "8: wheel_center\n",
- "9: wheel_edge\n",
- "\n",
- "===filename===\n",
- "C:\\Users\\jonma\\Dropbox\\FreeMoCapProject\\FreeMocap_Data\\sesh_2022-05-07_17_15_05_pupil_wobble_juggle_0\\sleap_data\\output_h5_files\\labels_v000_analysis_video_3.h5\n",
- "\n",
- "===HDF5 datasets===\n",
- "['edge_inds', 'edge_names', 'instance_scores', 'node_names', 'point_scores', 'track_names', 'track_occupancy', 'tracking_scores', 'tracks']\n",
- "\n",
- "===locations data shape===\n",
- "(5090, 10, 2, 1)\n",
- "\n",
- "===nodes===\n",
- "0: red_ball\n",
- "1: green_ball\n",
- "2: orange_ball\n",
- "3: wobble_0\n",
- "4: wobble_1\n",
- "5: wobble_2\n",
- "6: wobble_3\n",
- "7: wobble_4\n",
- "8: wheel_center\n",
- "9: wheel_edge\n",
- "\n",
- "===filename===\n",
- "C:\\Users\\jonma\\Dropbox\\FreeMoCapProject\\FreeMocap_Data\\sesh_2022-05-07_17_15_05_pupil_wobble_juggle_0\\sleap_data\\output_h5_files\\labels_v000_analysis_video_4.h5\n",
- "\n",
- "===HDF5 datasets===\n",
- "['edge_inds', 'edge_names', 'instance_scores', 'node_names', 'point_scores', 'track_names', 'track_occupancy', 'tracking_scores', 'tracks']\n",
- "\n",
- "===locations data shape===\n",
- "(5090, 10, 2, 1)\n",
- "\n",
- "===nodes===\n",
- "0: red_ball\n",
- "1: green_ball\n",
- "2: orange_ball\n",
- "3: wobble_0\n",
- "4: wobble_1\n",
- "5: wobble_2\n",
- "6: wobble_3\n",
- "7: wobble_4\n",
- "8: wheel_center\n",
- "9: wheel_edge\n",
- "\n"
- ]
- }
- ],
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "outputs": [],
"source": [
"\n",
"\n",
@@ -230,112 +112,230 @@
" print()\n",
"\n",
"\n"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
+ "outputs": [],
+ "source": [
+ "number_of_videos = len(per_video_labels_fr_point_xy)\n",
+ "number_of_frames = len(per_video_labels_fr_point_xy[0])\n",
+ "number_of_markers = len(per_video_labels_fr_point_xy[0][0])\n",
+ "sleap2d_nCams_nFrames_nImgPts_XY = np.empty((number_of_videos, number_of_frames, number_of_markers, 2))"
+ ],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
- },
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "put data into freemocap 2d_npy format"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
"outputs": [],
"source": [
- "# number_of_videos = len(per_video_labels_fr_point_xy)\n",
- "# number_of_frames = len(per_video_labels_fr_point_xy[0])\n",
- "# number_of_markers = len(per_video_labels_fr_point_xy[0][0])\n",
- "# sleap2d_nCams_nFrames_nImgPts_XY = np.empty((number_of_videos, number_of_frames, number_of_markers, 2))"
- ]
+ "for this_video_number in range(len(per_video_labels_fr_point_xy)):\n",
+ " sleap2d_nCams_nFrames_nImgPts_XY[this_video_number,:,:,:] = np.squeeze(per_video_labels_fr_point_xy[this_video_number])\n",
+ "\n",
+ "sleap2d_nCams_nFrames_nImgPts_XY.shape"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
"cell_type": "markdown",
- "metadata": {},
"source": [
- "put data into freemocap 2d_npy format"
- ]
+ "load anipose calibration cgroup whosit"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
+ "outputs": [],
+ "source": [
+ "\n",
+ "sleap_flattened_nCams_nTotalPoints_XY = sleap2d_nCams_nFrames_nImgPts_XY.reshape(number_of_videos, -1, 2) # reshape data to collapse across 'frames' so it becomes [numCams, numFrames*numPoints, XY]\n",
+ "\n",
+ "print('Reconstructing 3d points...')\n",
+ "sleap_data3d_flat = anipose_camera_calibration_object.triangulate(sleap_flattened_nCams_nTotalPoints_XY, progress=True)\n",
+ "\n",
+ "sleap_data_reprojerr_flat = anipose_camera_calibration_object.reprojection_error( sleap_data3d_flat, sleap_flattened_nCams_nTotalPoints_XY, mean=True)\n",
+ "\n",
+ "##return:\n",
+ "sleap_fr_mar_xyz = sleap_data3d_flat.reshape(number_of_frames, number_of_markers, 3)\n",
+ "sleap_fr_mar_reprojectionError = sleap_data_reprojerr_flat.reshape(number_of_frames, number_of_markers)\n"
+ ],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(5, 5090, 10, 2)"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "outputs": [],
+ "source": [
+ "\n",
+ "print(f'sleap_fr_mar_xyz.shape: {sleap_fr_mar_xyz.shape}')\n",
+ "print(f'sleap_fr_mar_reprojectionError.shape: {sleap_fr_mar_reprojectionError.shape}')"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
}
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "outputs": [],
+ "source": [
+ "import matplotlib.pyplot as plt\n",
+ "%matplotlib \n"
],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "outputs": [],
"source": [
- "# for this_video_number in range(len(per_video_labels_fr_point_xy)):\n",
- "# sleap2d_nCams_nFrames_nImgPts_XY[this_video_number,:,:,:] = np.squeeze(per_video_labels_fr_point_xy[this_video_number])\n",
+ "plt.close('all')\n",
+ "fig = plt.figure()\n",
"\n",
- "# sleap2d_nCams_nFrames_nImgPts_XY.shape"
- ]
+ "for this_marker_number in range(sleap_fr_mar_xyz.shape[1]):\n",
+ " ax = fig.add_subplot(5,2,this_marker_number+1)\n",
+ " ax.plot(sleap_fr_mar_xyz[:,this_marker_number,:])"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "save sleap data to `DataArrays` folder "
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
},
{
"cell_type": "code",
- "execution_count": 10,
- "metadata": {},
+ "execution_count": null,
"outputs": [],
"source": [
"session_data_arrays_path = session_folder_path / 'DataArrays'\n",
"\n",
- "sleap_2d_dataa_path = session_data_arrays_path / 'sleap_2d_cameraNum_frameNum_trackedPts_xyz.npy'\n",
+ "sleap_3d_save_path = session_data_arrays_path / 'sleap_3d_points.npy'\n",
+ "sleap_reproj_err_save_path = session_data_arrays_path / 'sleap_reprojection_error.npy'\n",
+ "label_name_csv_path = session_data_arrays_path / 'sleap_label_names.csv'\n",
"\n",
- "sleap2d_nCams_nFrames_nImgPts_XY = np.load(sleap_2d_dataa_path)"
- ]
+ "np.save(sleap_3d_save_path, sleap_fr_mar_xyz)\n",
+ "np.save(sleap_reproj_err_save_path, sleap_fr_mar_reprojectionError)\n",
+ "\n",
+ "import csv\n",
+ "with open(label_name_csv_path,'w') as label_name_file:\n",
+ " wr = csv.writer(label_name_file)\n",
+ " wr.writerow(node_names)"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Using matplotlib backend: TkAgg\n"
- ]
+ "cell_type": "markdown",
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
+ },
"source": [
- "import matplotlib.pyplot as plt\n",
- "%matplotlib \n"
+ "put data into freemocap 2d_npy format"
]
},
{
"cell_type": "code",
"execution_count": 12,
- "metadata": {},
- "outputs": [],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(5, 5090, 10, 2)"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "plt.close('all')\n",
+ "for this_video_number in range(len(per_video_labels_fr_point_xy)):\n",
+ " sleap2d_nCams_nFrames_nImgPts_XY[this_video_number,:,:,:] = np.squeeze(per_video_labels_fr_point_xy[this_video_number])\n",
"\n",
- "for this_video_number in range(number_of_videos):\n",
- " fig = plt.figure(this_video_number)\n",
- "\n",
- " for this_marker_number in range(sleap2d_nCams_nFrames_nImgPts_XY.shape[2]):\n",
- " ax = fig.add_subplot(5,2,this_marker_number+1)\n",
- " ax.plot(sleap2d_nCams_nFrames_nImgPts_XY[this_video_number,:,this_marker_number,:])\n",
- " plt.show()\n",
- " plt.pause(0.2)"
+ "sleap2d_nCams_nFrames_nImgPts_XY.shape"
]
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ },
"source": [
"load anipose calibration cgroup whosit"
]
@@ -361,7 +361,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
- "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 50900/50900 [00:14<00:00, 3613.45it/s]\n"
+ "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 50900/50900 [00:07<00:00, 6795.51it/s]\n"
]
}
],
@@ -382,7 +382,11 @@
{
"cell_type": "code",
"execution_count": 14,
- "metadata": {},
+ "metadata": {
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
"outputs": [
{
"name": "stdout",
@@ -402,7 +406,11 @@
{
"cell_type": "code",
"execution_count": 15,
- "metadata": {},
+ "metadata": {
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
"outputs": [
{
"name": "stdout",
@@ -419,8 +427,12 @@
},
{
"cell_type": "code",
- "execution_count": 16,
- "metadata": {},
+ "execution_count": 22,
+ "metadata": {
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
"outputs": [],
"source": [
"plt.close('all')\n",
@@ -433,15 +445,23 @@
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ },
"source": [
"save sleap data to `DataArrays` folder "
]
},
{
"cell_type": "code",
- "execution_count": 17,
- "metadata": {},
+ "execution_count": null,
+ "metadata": {
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
"outputs": [],
"source": [
"session_data_arrays_path = session_folder_path / 'DataArrays'\n",
@@ -461,28 +481,23 @@
},
{
"cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(5090,)"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
+ "execution_count": null,
+ "metadata": {
+ "pycharm": {
+ "name": "#%%\n"
}
- ],
- "source": [
- "sleap_fr_mar_xyz[:,5,0].shape"
- ]
+ },
+ "outputs": [],
+ "source": []
},
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
"outputs": [],
"source": []
}
@@ -511,4 +526,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
-}
+}
\ No newline at end of file