Skip to content

Commit

Permalink
Adding processed data
Browse files Browse the repository at this point in the history
  • Loading branch information
InfantLab committed Mar 16, 2022
1 parent c088efd commit 86bb80a
Show file tree
Hide file tree
Showing 20 changed files with 4,539 additions and 568 deletions.
33 changes: 1 addition & 32 deletions Drum.Tutorial.settings.json
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
{
"batchName": "VASC Drumming Data tutorial",
"lastUpdate": null,
"flags":{
"anon": false,
"includeHands": true,
"cleaned": false
},
"paths":{
"openpose":"C:\\Users\\cas\\openpose-1.5.0-binaries-win64-gpu-python-flir-3d_recommended\\",
"project": ".\\DrumTutorial",
"videos_in": ".\\DrumTutorial\\videos",
"videos_out": ".\\DrumTutorial\\",
"videos_out_openpose": ".\\DrumTutorial\\openpose",
"videos_out_timeseries": ".\\DrumTutorial\\timeseries",
"videos_out_analyses" : ".\\DrumTutorial\\analyses"
},
"filenames":{
"videos_json": "videos.json",
"clean_json": "clean.json",
"alldatanpz": "allframedata.npz",
"lefthandnpz": "lefthandframedata.npz",
"righthandnpz": "righthandframedata.npz",
"lefthandnpz": "lefthandframedata.npz",
"cleannpz": "cleandata.npz",
"cleanrightnpz": "cleanrightdata.npz",
"cleanleftnpz": "cleanleftdata.npz",
"cleandataparquet": "cleandata.parquet",
"righthandparquet": "righthand.parquet",
"lefthandparquet": "lefthand.parquet"
}
}
{"batchName": "VASC Drumming Data tutorial", "lastUpdate": "2022-03-14T09:23:08.849601", "flags": {"anon": false, "includeHands": true, "cleaned": true}, "paths": {"openpose": "C:\\Users\\cas\\openpose-1.5.0-binaries-win64-gpu-python-flir-3d_recommended\\", "project": ".\\DrumTutorial", "videos_in": ".\\DrumTutorial\\videos", "videos_out": ".\\DrumTutorial\\", "videos_out_openpose": ".\\DrumTutorial\\openpose", "videos_out_timeseries": ".\\DrumTutorial\\timeseries", "videos_out_analyses": ".\\DrumTutorial\\analyses"}, "filenames": {"videos_json": "videos.json", "clean_json": "clean.json", "alldatanpz": "allframedata.npz", "lefthandnpz": "lefthandframedata.npz", "righthandnpz": "righthandframedata.npz", "cleannpz": "cleandata.npz", "cleanrightnpz": "cleanrightdata.npz", "cleanleftnpz": "cleanleftdata.npz", "cleandataparquet": "cleandata.parquet", "righthandparquet": "righthand.parquet", "lefthandparquet": "lefthand.parquet"}}
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions DrumTutorial/clean.json

Large diffs are not rendered by default.

Binary file added DrumTutorial/timeseries/cleandata.npz
Binary file not shown.
Binary file added DrumTutorial/timeseries/cleandata.parquet
Binary file not shown.
Binary file added DrumTutorial/timeseries/cleanleftdata.npz
Binary file not shown.
Binary file added DrumTutorial/timeseries/cleanrightdata.npz
Binary file not shown.
Binary file added DrumTutorial/timeseries/lefthand.parquet
Binary file not shown.
Binary file added DrumTutorial/timeseries/righthand.parquet
Binary file not shown.
Binary file added DrumTutorial/timeseries/trimdata.npz
Binary file not shown.
75 changes: 40 additions & 35 deletions Step1.ProcessVideo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"source": [
"### 1.1 Settings?\n",
"\n",
"Load a json file that tells us where to find our videos and where to save the data. You should create a different settings file for each project. Then you don't need to change any other values in the script for Step 1 or Step 2. \n",
"Load a json file that tells us where to find our videos and where to save the data. You should create a different settings file for each project. Then you don't need to change any other values in the script for Step 1 or Step 2.\n",
"\n",
"\n",
"`TODO - write a helper to create a settings file`"
]
Expand Down Expand Up @@ -177,7 +178,7 @@
"source": [
"### 1.3 Where are your videos?\n",
"\n",
"In the next cell you need to specify the folder with your set of video files. So that we process them. These scripts use the following directory structure. It expects your videos to be in a subfolder of your project \n",
"In the next cell you need to specify the folder with your set of video files. So that we process them. These scripts use the following directory structure. It expects your videos to be in a subfolder of your project\n",
"\n",
"```\n",
"path\\to\\project\\myvideos\n",
Expand Down Expand Up @@ -214,7 +215,7 @@
"source": [
"# where's the project data folder? (with trailing slash)\n",
"projectpath = settings[\"paths\"][\"project\"]\n",
"#where are your video files? \n",
"#where are your video files?\n",
"videos_in = settings[\"paths\"][\"videos_in\"]\n",
"\n",
"# locations of videos and output\n",
Expand Down Expand Up @@ -250,7 +251,9 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"metadata": {
"lines_to_end_of_cell_marker": 2
},
"outputs": [
{
"name": "stdout",
Expand All @@ -271,19 +274,17 @@
" videos = {}\n",
" with open(videosjson, 'w') as outfile:\n",
" json.dump(videos, outfile)\n",
" print(\"Creating new videos.json\") \n",
" \n",
" "
" print(\"Creating new videos.json\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Either \n",
"### 1.4.3.A Scanning all videos in particular folder \n",
"### Either\n",
"### 1.4.3.A Scanning all videos in particular folder\n",
"\n",
"In which case we look at all videos in `videos_in` let the names of the files also provide the base names for each participant we create. \n",
"In which case we look at all videos in `videos_in` let the names of the files also provide the base names for each participant we create.\n",
"\n",
"We will reference these files by the video names so myvid1.avi is found in `videos[\"myvid1\"]`.\n",
"\n",
Expand Down Expand Up @@ -370,7 +371,7 @@
"print(\"We found %d mp4s\" % len(mp4s))\n",
"print(\"We found %d 3gps\" % len(threegps))\n",
"\n",
"#For the moment we will manually specify what videos to process. \n",
"#For the moment we will manually specify what videos to process.\n",
"#TODO generate a list of force or skip videos to automate things slightly\n",
"allvideos = []\n",
"allvideos.extend(avis)\n",
Expand All @@ -385,22 +386,22 @@
" #we will reference these files by the video names so myvid1.avi is found in videos[\"myvid1\"]0\n",
" fullname = os.path.basename(thisvid)\n",
" fullpath = str(os.path.abspath(thisvid))\n",
" vid, fmt = os.path.splitext(fullname) \n",
" vid, fmt = os.path.splitext(fullname)\n",
" #generate an structure to hold some info about this video\n",
" if vid in videos: \n",
" if vid in videos:\n",
" print(vid + \" already in videos.json\")\n",
" else:\n",
" print(\"Adding \" + vid + \" to videos.json\")\n",
" videos[vid] = {} \n",
" videos[vid] = {}\n",
" cam = \"camera1\"\n",
" videos[vid][cam] = {} \n",
" videos[vid][cam] = {}\n",
" videos[vid][cam][\"shortname\"] = vid + \".\" + cam\n",
" videos[vid][cam][\"stemname\"] = vid\n",
" videos[vid][cam][\"fullname\"] = fullname\n",
" videos[vid][cam][\"fullpath\"] = fullpath\n",
" videos[vid][cam][\"index\"] = None #the numerical index this data will have in np.array.\n",
" videos[vid][cam][\"format\"] = fmt\n",
" videos[vid][cam][\"openpose\"] = {\"exitcode\" : None, \"when\" : None} "
" videos[vid][cam][\"openpose\"] = {\"exitcode\" : None, \"when\" : None}"
]
},
{
Expand All @@ -416,7 +417,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### OR \n",
"### OR\n",
"### 1.4.2.B Read an Excel file of videos\n",
"\n",
"We expect the first column of the spreadsheet to tell us the base name for each participant and columns 2 to 4 contains the full name and location of the videos.\n",
Expand Down Expand Up @@ -473,7 +474,7 @@
" if cam in videolist.columns:\n",
" #if so what is path of video it has\n",
" fullpath = os.path.abspath(videolist[cam][ind])\n",
" #maybe we processed this already \n",
" #maybe we processed this already\n",
" if cam in videos[vid] and videos[vid][cam][\"fullpath\"] == fullpath:\n",
" print(cam, videos[vid][cam][\"stemname\"], \"already processed\")\n",
" print(\"Exit code:\", videos[vid][cam][\"openpose\"][\"exitcode\"])\n",
Expand All @@ -491,7 +492,7 @@
" videos[vid][cam][\"openpose\"] = {\"exitcode\" : None, \"when\" : None}\n",
"\n",
"\n",
" \n"
"\n"
]
},
{
Expand All @@ -508,7 +509,7 @@
"outputs": [],
"source": [
"pprint(videos)\n",
"#beware that pretty print sometimes messes up the display formating of fullpath,. \n",
"#beware that pretty print sometimes messes up the display formating of fullpath,.\n",
"#(this should not affect actual code that uses fullpath)"
]
},
Expand All @@ -531,7 +532,7 @@
"\n",
"Other useful params\n",
" ```\n",
"--hand #include a model and points for the hands. \n",
"--hand #include a model and points for the hands.\n",
"--frame_first 100 #start from frame 100\n",
"--display 0 #don't show the images as they are processed\n",
" ```\n"
Expand All @@ -547,16 +548,6 @@
"includeHands = settings[\"flags\"][\"includeHands\"]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"#should we generate and process points for hand data?\n",
"includeHands = settings[\"flags\"][\"includeHands\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1044,7 +1035,7 @@
"\n",
"keypoints_array = np.zeros([nvideos,maxcameras, maxframes,maxpeople,ncoords]) #big array to hold all the numbers\n",
"\n",
"#also create arrays for hand data \n",
"#also create arrays for hand data\n",
"righthand_array = np.zeros([nvideos,maxcameras, maxframes,maxpeople,hcoords]) #big array to hold all the numbers\n",
"lefthand_array = np.zeros([nvideos,maxcameras, maxframes,maxpeople,hcoords]) #big array to hold all the numbers\n",
"\n",
Expand Down Expand Up @@ -1147,8 +1138,8 @@
" for p in data[\"people\"]:\n",
" keypoints_array[v,c,i,j,:]= p[\"pose_keypoints_2d\"]\n",
" if includeHands:\n",
" righthand_array[v,c,i,j,:]= p[\"hand_right_keypoints_2d\"] \n",
" lefthand_array[v,c,i,j,:] = p[\"hand_left_keypoints_2d\"] \n",
" righthand_array[v,c,i,j,:]= p[\"hand_right_keypoints_2d\"]\n",
" lefthand_array[v,c,i,j,:] = p[\"hand_left_keypoints_2d\"]\n",
" j += 1\n",
" npeople[i] = j\n",
" i += 1\n",
Expand All @@ -1169,7 +1160,7 @@
"\n",
"if includeHands:\n",
" righthand_array = np.delete(righthand_array,np.s_[int(globalmaxpeople):],3)\n",
" lefthand_array = np.delete(lefthand_array, np.s_[int(globalmaxpeople):],3) \n",
" lefthand_array = np.delete(lefthand_array, np.s_[int(globalmaxpeople):],3)\n",
"\n",
"print(\"keypoints_array has size\", keypoints_array.shape)"
]
Expand Down Expand Up @@ -1208,6 +1199,20 @@
" np.savez_compressed(videos_out_timeseries + '\\\\' + settings[\"filenames\"][\"lefthandnpz\"], keypoints_array=lefthand_array)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4ee4b6a",
"metadata": {},
"outputs": [],
"source": [
"#after each new id we save the json data\n",
"settings[\"lastUpdate\"] = datetime.now().isoformat()\n",
"with open(settingsjson, 'w') as outfile:\n",
" json.dump(settings, outfile)\n",
" print('settings.json updated')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
5 changes: 1 addition & 4 deletions Step1.ProcessVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#
# Load a json file that tells us where to find our videos and where to save the data. You should create a different settings file for each project. Then you don't need to change any other values in the script for Step 1 or Step 2.
#
#
# `TODO - write a helper to create a settings file`

# +
Expand Down Expand Up @@ -137,7 +138,6 @@
#
# If you want to start afresh just delete this single file and everything gets reprocessed from scratch.

# +
#retrieve the list of base names of processed videos.
videosjson = os.path.abspath(settings["paths"]["videos_out"] + '\\' + settings["filenames"]["videos_json"])
try:
Expand All @@ -150,9 +150,6 @@
json.dump(videos, outfile)
print("Creating new videos.json")


# -

# ### Either
# ### 1.4.3.A Scanning all videos in particular folder
#
Expand Down
Loading

0 comments on commit 86bb80a

Please sign in to comment.