Skip to content

Commit

Permalink
Merge pull request #1 from InfantLab/Sangath
Browse files Browse the repository at this point in the history
recursive search for videos
  • Loading branch information
InfantLab authored Feb 15, 2021
2 parents d8085ee + f322df1 commit 38617e3
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 303 deletions.
71 changes: 49 additions & 22 deletions Step1.ProcessVideo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@
"outputs": [],
"source": [
"# where's the project folder? (with trailing slash)\n",
"projectpath = os.getcwd() + \"\\\\..\\\\lookit\\\\\"\n",
"# projectpath = \"U:\\\\Caspar\\\\\"\n",
"videos_in = projectpath \n",
"#projectpath = os.getcwd() + \"\\\\..\\\\Sangath\"\n",
"projectpath = \"C:\\\\Users\\\\cas\\\\OneDrive - Goldsmiths College\\\\Projects\\\\Measuring Responsive Caregiving\\\\Sangath\"\n",
"videos_in = \"\\\\\\\\192.168.0.50\\\\Videos\\\\Obs Feeding videos _1.3.17\\\\\" \n",
"\n",
"# locations of videos and output\n",
"# videos_out = \"E:\\\\SpeakNSign\\\\\" + \"out\"\n",
Expand Down Expand Up @@ -152,6 +152,15 @@
" print(\"Creating new videos.json\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"videos_out"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -248,24 +257,37 @@
"We set a flag `namesfromfiles = True`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"threegps = glob.glob(videos_in + \"./*/*.3gp\", recursive = True)\n",
"print(threegps)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#first get list of videos in the inbox\n",
"avis = glob.glob(videos_in + \"*.avi\")\n",
"mp4s = glob.glob(videos_in + \"*.mp4\")\n",
"avis = glob.glob(videos_in + \"./*/*.avi\", recursive = True)\n",
"mp4s = glob.glob(videos_in + \"./*/*.mp4\", recursive = True)\n",
"threegps = glob.glob(videos_in + \"./*/*.3gp\", recursive = True)\n",
"\n",
"print(\"We found %d avis\" % len(avis))\n",
"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",
"#TODO generate a list of force or skip videos to automate things slightly\n",
"allvideos = []\n",
"allvideos.extend(avis)\n",
"allvideos.extend(mp4s)\n",
"allvideos.extend(threegps)\n",
"\n",
"namesfromfiles = True\n",
"\n",
Expand All @@ -276,16 +298,20 @@
" fullname = os.path.basename(thisvid)\n",
" vid, fmt = os.path.splitext(fullname) \n",
" #generate an structure to hold some info about this video\n",
" videos[vid] = {} \n",
" cam = \"camera1\"\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\"] = thisvid\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} "
" if vid in videos: \n",
" print(vid + \" already in videos.json\")\n",
" else:\n",
" print(\"Adding \" + vid \" to videos.json\"))\n",
" videos[vid] = {} \n",
" cam = \"camera1\"\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\"] = thisvid\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} "
]
},
{
Expand Down Expand Up @@ -332,9 +358,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The main openpose loop\n",
"### The main openpose loop\n",
"\n",
"Call the openpose app for each of the videos at a time. For each one print the full command that we use so that you can use it manually to investigate any errors. \n",
"Call the `openposedemo` app for each of the videos at a time. For each one print the full command that we use so that you can use it manually to investigate any errors. \n",
"\n",
"Finally, we write a list of the processed videos to a file called `videos.json`. \n",
"Note that we will add other information to this file as we go through other steps. \n",
Expand Down Expand Up @@ -510,7 +536,7 @@
"nvideos = len(videos)\n",
"maxcameras = 3\n",
"maxframes = 0\n",
"maxpeople = 10 #maximum people we might expect (large upper bound)\n",
"maxpeople = 15 #maximum people we might expect (large upper bound)\n",
"ncoords = 75 #the length of the array coming back from openpose x,y coords of each point plus pafs\n",
"\n",
"for vid in videos: \n",
Expand Down Expand Up @@ -597,7 +623,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"lines_to_end_of_cell_marker": 2
},
"outputs": [],
"source": [
"#update the json file in the video out directory\n",
Expand All @@ -606,8 +634,7 @@
"\n",
"# in the time series folder we save the data file. \n",
"#in a compressed format as it has a lot of empty values\n",
"np.savez_compressed(videos_out_timeseries + '\\\\allframedata.npz', keypoints_array=keypoints_array)\n",
"\n"
"np.savez_compressed(videos_out_timeseries + '\\\\allframedata.npz', keypoints_array=keypoints_array)"
]
},
{
Expand Down Expand Up @@ -639,7 +666,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
48 changes: 30 additions & 18 deletions Step1.ProcessVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@

# +
# where's the project folder? (with trailing slash)
projectpath = os.getcwd() + "\\..\\lookit\\"
# projectpath = "U:\\Caspar\\"
videos_in = projectpath
#projectpath = os.getcwd() + "\\..\\Sangath"
projectpath = "C:\\Users\\cas\\OneDrive - Goldsmiths College\\Projects\\Measuring Responsive Caregiving\\Sangath"
videos_in = "\\\\192.168.0.50\\Videos\\Obs Feeding videos _1.3.17\\"

# locations of videos and output
# videos_out = "E:\\SpeakNSign\\" + "out"
Expand Down Expand Up @@ -118,6 +118,8 @@
videos = {}
print("Creating new videos.json")

videos_out

# ### EITHER 1.4.2 Read an Excel file of videos
#
# 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.
Expand Down Expand Up @@ -199,19 +201,25 @@
#
# We set a flag `namesfromfiles = True`.

threegps = glob.glob(videos_in + "./*/*.3gp", recursive = True)
print(threegps)

# +
#first get list of videos in the inbox
avis = glob.glob(videos_in + "*.avi")
mp4s = glob.glob(videos_in + "*.mp4")
avis = glob.glob(videos_in + "./*/*.avi", recursive = True)
mp4s = glob.glob(videos_in + "./*/*.mp4", recursive = True)
threegps = glob.glob(videos_in + "./*/*.3gp", recursive = True)

print("We found %d avis" % len(avis))
print("We found %d mp4s" % len(mp4s))
print("We found %d 3gps" % len(threegps))

#For the moment we will manually specify what videos to process.
#TODO generate a list of force or skip videos to automate things slightly
allvideos = []
allvideos.extend(avis)
allvideos.extend(mp4s)
allvideos.extend(threegps)

namesfromfiles = True

Expand All @@ -222,16 +230,20 @@
fullname = os.path.basename(thisvid)
vid, fmt = os.path.splitext(fullname)
#generate an structure to hold some info about this video
videos[vid] = {}
cam = "camera1"
videos[vid][cam] = {}
videos[vid][cam]["shortname"] = vid + "." + cam
videos[vid][cam]["stemname"] = vid
videos[vid][cam]["fullname"] = fullname
videos[vid][cam]["fullpath"] = thisvid
videos[vid][cam]["index"] = None #the numerical index this data will have in np.array.
videos[vid][cam]["format"] = fmt
videos[vid][cam]["openpose"] = {"exitcode" : None, "when" : None}
if vid in videos:
print(vid + " already in videos.json")
else:
print("Adding " + vid " to videos.json"))
videos[vid] = {}
cam = "camera1"
videos[vid][cam] = {}
videos[vid][cam]["shortname"] = vid + "." + cam
videos[vid][cam]["stemname"] = vid
videos[vid][cam]["fullname"] = fullname
videos[vid][cam]["fullpath"] = thisvid
videos[vid][cam]["index"] = None #the numerical index this data will have in np.array.
videos[vid][cam]["format"] = fmt
videos[vid][cam]["openpose"] = {"exitcode" : None, "when" : None}
# -

# ### 1.5 Calling the OpenPose app
Expand Down Expand Up @@ -265,9 +277,9 @@
createoutputvideo = True #do we get openpose to create a video output?
# -

# #### The main openpose loop
# ### The main openpose loop
#
# Call the openpose app for each of the videos at a time. For each one print the full command that we use so that you can use it manually to investigate any errors.
# Call the `openposedemo` app for each of the videos at a time. For each one print the full command that we use so that you can use it manually to investigate any errors.
#
# Finally, we write a list of the processed videos to a file called `videos.json`.
# Note that we will add other information to this file as we go through other steps.
Expand Down Expand Up @@ -399,7 +411,7 @@
nvideos = len(videos)
maxcameras = 3
maxframes = 0
maxpeople = 10 #maximum people we might expect (large upper bound)
maxpeople = 15 #maximum people we might expect (large upper bound)
ncoords = 75 #the length of the array coming back from openpose x,y coords of each point plus pafs

for vid in videos:
Expand Down
Loading

0 comments on commit 38617e3

Please sign in to comment.