Overview

This document gives an overview of the physically-based estimated generated by open-body-fit. We will use the data from the demo directory to describe the setup.

The points of the body (in demo/036CR1-3d.csv) are hard-coded to have the following ids in our data tables. We use these ids to refer to specific joints, for example, when we draw lines or compute distances.

root = 1
neck = 2
head = 3
thorax = 4
rshoulder = 5
relbow = 6
rwrist = 7
rhand = 8
lshoulder = 9
lelbow = 10
lwrist = 11
lhand = 12

Let’s define the paths to our data source here.

# TODO: Set your data directory paths here
data_dir = "../demo/"
img_dir = "../demo/images"
participant = "036CR1"

Data

We will visualize the following files:

The units are based on meters, joules, and radians.

Positions

positions <- read.table(sprintf("%s%s-3d_positions.txt", 
                        data_dir, participant), sep = ",", header = TRUE)

We can view the 3D estimate overlaid onto the original video for a single frame. Below we render frame 130.

positions_cm = 100 * positions; # projection on to image assumes cm, not meters

frame = 130
image_file = sprintf("%s/%s-%05d.png", img_dir, participant, frame)
raw_img = readImage(image_file); 

Cmat = readMat(sprintf("%s%s-CMatrix.mat", data_dir, participant));
C = as.matrix(Cmat$C);

plot_skeleton_2d(raw_img, C, frame, positions_cm, participant)

We can also view an animation of the data in 3D

startFrame = 290
endFrame = 420 # last frame = nrow(positions)
slider_skeleton_3d(positions, participant, startFrame, endFrame) 

Angular velocities, accelerations, and torques

The following code reads in the raw data.

angular_velocities <- read.table(sprintf("%s%s-3d_avels.txt", data_dir, participant), sep = ",", header = TRUE)
angular_accelerations <- read.table(sprintf("%s%s-3d_aaccs.txt", data_dir, participant), sep = ",", header = TRUE)
linear_velocities <- read.table(sprintf("%s%s-3d_vels.txt", data_dir, participant), sep = ",", header = TRUE)
linear_accelerations <- read.table(sprintf("%s%s-3d_accs.txt", data_dir, participant), sep = ",", header = TRUE)
torques <- read.table(sprintf("%s%s-3d_forces.txt", data_dir, participant), sep = ",", header = TRUE) 

raw_velocities <- read.table(sprintf("%s%s-3d_vels.txt", data_dir, participant), sep = ",", header = TRUE)

The magnitude function returns a table with the magnitudes (e.g. lengths) of the x,y,z quantities stored in the files.

mags <- magnitudes(angular_velocities) # compute angular speeds
head(mags)
##   root       neck head torso  lshoulder    lelbow lwrist lhand  rshoulder
## 1    0 0.00750104    0     0 0.02570021 0.0199633      0     0 0.02907158
## 2    0 0.02952056    0     0 0.02658489 0.0224619      0     0 0.07580719
## 3    0 0.18266784    0     0 0.12030270 0.2300320      0     0 0.40886418
## 4    0 0.47296255    0     0 0.32898125 0.7204230      0     0 1.03078492
## 5    0 0.86152764    0     0 0.65870884 1.3470700      0     0 1.81409201
## 6    0 1.12073215    0     0 1.04630557 1.7120300      0     0 2.37323274
##        relbow rwrist rhand
## 1 0.008388650      0     0
## 2 0.000814326      0     0
## 3 0.003415920      0     0
## 4 0.008916840      0     0
## 5 0.008744260      0     0
## 6 0.067822000      0     0

Visualization of the neck’s angular accelerations with a histogram.

plot_ly(x = mags$neck, type = "histogram") %>% 
  layout(title="Angular speeds (neck)", 
         xaxis=list(title="radians/s"),
         yaxis=list(title="counts"))

Visualization of the angular velocities for all joints.

clamp_val = 5
trim = pmin(as.vector(unlist(mags)), clamp_val);
img = matrix(trim, nrow=nrow(mags), ncol=ncol(mags)) 


fig <- plot_ly(z = img, type = "heatmap") %>%
  layout(title="Angular speeds (All joints) radians/s",
         yaxis=list(title="frame number"),
         xaxis=list(ticktext =colnames(mags), tickvals=0:ncol(mags)))
fig
plot_ly(x=1:nrow(mags), y=mags$lshoulder, mode="lines", type="scatter") %>%
        layout(title="Angular Speed (lshoulder)",
         yaxis=list(title="radians/s"),
         xaxis=list(title="frame"))
plot_ly(x=1:nrow(mags), y=mags$rshoulder, mode="lines", type="scatter") %>%
        layout(title="Angular Speed (rshoulder)",
         yaxis=list(title="radians/s"),
         xaxis=list(title="frame"))
num = length(mags$rshoulder)
plot_ly(x = mags$rshoulder, type = "histogram", histnorm='percent', xbins=list("start"=0,"end"=50, size=0.2)) %>% 
  layout(title="Angular speeds (Right shoulder)", 
         xaxis=list(title="radians/s", range=list(0,10)),
         yaxis=list(title="counts as percentage", range=list(0,25)))
plot_ly(x = mags$relbow, type = "histogram", histnorm='percent', xbins=list("start"=0,"end"=50, size=0.2)) %>% 
  layout(title="Angular speeds (Right elbow)", 
         xaxis=list(title="radians/s", range=list(0,10)),
         yaxis=list(title="counts as percentage", range=list(0,25)))
plot_ly(x = mags$lshoulder, type = "histogram", histnorm='percent', xbins=list("start"=0,"end"=50, size=0.2)) %>% 
  layout(title="Angular speeds (Left shoulder)", 
         xaxis=list(title="radians/s", range=list(0,10)),
         yaxis=list(title="counts as percentage", range=list(0,25)))
plot_ly(x = mags$lelbow, type = "histogram", histnorm='percent', xbins=list("start"=0,"end"=50, size=0.2)) %>% 
  layout(title="Angular speeds (Left elbow)", 
         xaxis=list(title="radians/s", range=list(0,10)),
         yaxis=list(title="counts as percentage", range=list(0,25)))

Visualization of the left (cyan) and right (red) hands with a point cloud.

sf = 1
ef = nrow(positions)
point_cloud_3d(positions, participant, sf, ef)