2011-11-16 61 views
23

我是R的新手,喜歡它,但是我對完全缺乏用於分析運動捕捉數據的固體軟件包感到驚訝。R軟件包用於運動捕捉數據分析和可視化

最簡單的動作捕捉文件只是一張巨大的表格,其中每個連接到記錄主體的點的「XYZ」座標以及捕獲的每個幀都是如此。我知道我可以在R中找到單獨的方法和函數來執行復雜的操作(如主分量分析),也可以繪製所有點的時間序列。但是當我在尋找可以統計地分析人類運動的例子,並提供用於數據視覺表示的漂亮工具箱時,R原來是一片冷漠的沙漠。另一方面,MATLAB有Motion capture toolboxMoCap Toolbox,特別是後者有非常好的繪圖和分析捕獲的選項。但說實話 - MATLAB有相當難看可視化引擎比較R.

對於R動作捕捉包中的一些具體要求將包括:

  • 閱讀,編輯,可視化和轉換動作捕捉數據
  • 動能和運動分析
  • 時間序列和主成分分析
  • 動畫數據

我在這裏錯過了什麼(在我的谷歌搜索中)還是真的沒有mocap包裝R?有沒有人試圖在R中使用動作捕捉數據?你能給我一些指導嗎?

+2

您可能沒有缺少什麼。我的favo(u)禮儀解決方案,庫(sos); findFn(「{動作捕捉}」),沒有提出任何有用的東西。有文化方面的問題:用R做很酷的東西是可能的,但是如果所有從事運動捕捉的酷酷的孩子都使用MATLAB或者Python,那麼這就是事情將要完成的地方。我肯定會看一下,看看Python中已經做了什麼,以及將R與Python進行接口以用於任何尚未在R中實現的統計繁重工作... –

+1

您可以使用包「forecast」和「ftsa」主成分分析。 – power

回答

1

通過快速搜索RSeek來判斷,R沒有可用的動作捕捉包。它看起來像需要爲每個函數找到等價物。更一般的應該很容易找到(插值,子集,轉換/投影,時間序列分析,pca,矩陣分析等),編寫自己的自定義函數用於估計瞬時動能等特定事情的過程可能很可能學習的最佳方式!

您可能會發現plyr有助於將數據敲入形狀並使用animation包進行運動可視化。

1

我使用包rgl從動作手勢數據集創建動畫。雖然它不是專門用於手勢數據的包,但您可以使用它。

在下面的例子中,我們在上身有8個點的手勢數據:脊柱,肩中心,頭部,左肩,左手腕,右肩和右手腕。受試者的雙手向下,右臂向上移動。

我將數據集限制爲6個時間觀察值(如果您願意的話),因爲否則它會變大以在此處發佈。

原始數據集中的每一行對應於一次時間觀察,並且每個身體點的座標以4組(每四列爲一個身體點)定義。所以在每一條線上,我們都有「x」,「y」,「z」,「br」爲脊椎,然後是「x」,「y」,「z」,「br」爲肩中心,依此類推。 「br」始終爲1,以便分隔每個身體部位的三個座標(x,y,z)。

原來這裏是(限制)數據集:

DATA.time.obs<-rbind(c(-0.06431,0.101546,2.990067,1,-0.091378,0.165703,3.029513,1,-0.090019,0.518603,3.022399,1,-0.042211,0.687271,2.987086,1,-0.231384,0.419869,2.953286,1,-0.299824,0.173991,2.882627,1,0.063367,0.399478,3.136306,1,0.134907,0.176191,3.159998,1), 
       c(-0.067185,0.102249,2.990185,1,-0.095083,0.166589,3.028688,1,-0.093098,0.519146,3.019775,1,-0.043808,0.687041,2.987671,1,-0.234622,0.417481,2.94581,1,-0.300324,0.169313,2.869782,1,0.056816,0.398384,3.135578,1,0.134536,0.180875,3.162843,1), 
       c(-0.069282,0.102964,2.989943,1,-0.098594,0.167465,3.027638,1,-0.097184,0.52169,3.019556,1,-0.046626,0.695406,2.989244,1,-0.23478,0.417057,2.943475,1,-0.300101,0.168628,2.860515,1,0.053793,0.395444,3.143226,1,0.134175,0.182816,3.172053,1), 
       c(-0.070924,0.102948,2.989369,1,-0.101156,0.167554,3.026474,1,-0.100244,0.522901,3.018919,1,-0.049834,0.696996,2.987933,1,-0.235301,0.416329,2.939331,1,-0.301339,0.170203,2.85497,1,0.04762,0.390872,3.142792,1,0.14041,0.186844,3.182172,1), 
       c(-0.071973,0.103372,2.988788,1,-0.103215,0.16776,3.025409,1,-0.102334,0.52281,3.019341,1,-0.051298,0.697003,2.991192,1,-0.235497,0.414859,2.935161,1,-0.297678,0.15788,2.833734,1,0.045973,0.386249,3.147609,1,0.14408,0.1916,3.204443,1), 
       c(-0.073223,0.104598,2.988132,1,-0.106597,0.168971,3.022554,1,-0.106778,0.522688,3.015138,1,-0.051867,0.697781,2.990767,1,-0.236137,0.414773,2.931317,1,-0.297552,0.153462,2.827027,1,0.039316,0.39146,3.166831,1,0.175061,0.214336,3.207459,1)) 

對於每個時間點,我們可以創建一個矩陣,其中的每一行都將是一個體穴,列將座標:

# Single time point for analysis 
time.point<-1 
# Number of coordinates 
coordinates<-4 
# Number of body points 
body.points<-dim(DATA.time.obs)[2]/coordinates 

# Total time of gesture 
total.time<-dim(DATA.time.obs)[1] 

# Transform data for a single time. observation into a matrix 
DATA.matrix<-matrix(DATA.time.obs[1,],c(body.points,coordinates),byrow = TRUE) 
colnames(DATA.matrix)<-c("x","y","z","br") 
rownames(DATA.matrix)<-c("hip_center","spine","shoulder_center","head", 
         "left_shoulder","left_wrist","right_shoulder", 
         "right_wrist") 

所以,我們必須在每個時間點,像這樣的矩陣:

     x  y  z br 
hip_center  -0.064310 0.101546 2.990067 1 
spine   -0.091378 0.165703 3.029513 1 
shoulder_center -0.090019 0.518603 3.022399 1 
head   -0.042211 0.687271 2.987086 1 
left_shoulder -0.231384 0.419869 2.953286 1 
left_wrist  -0.299824 0.173991 2.882627 1 
right_shoulder 0.063367 0.399478 3.136306 1 
right_wrist  0.134907 0.176191 3.159998 1 

而現在擺在我們Ërgl從這個矩陣圖中的數據:

#install.packages("rgl") 
library(rgl) 

# INITIAL PLOT 

x<-unlist(DATA.matrix[,1]) 
y<-unlist(DATA.matrix[,2]) 
z<-unlist(DATA.matrix[,3]) 

# OPEN A BLANK 3D PLOT AND SET INITIAL NEUTRAL VIEWPOINT 
open3d() 
rgl.viewpoint(userMatrix=rotationMatrix(0,0,0,0)) 

# SET FIGURE POSITION 
# This is variable. It will depend on your dataset 
# I've found that for this specific dataset a rotation 
# of -0.7*pi on the Y axis works 

# You can also plot and select the best view with 
# your mouse. This selected view will be passed on 
# to the animation. 
U <- par3d("userMatrix") 
par3d(userMatrix = rotate3d(U, -0.7*pi, 0,1,0)) 

# PLOT POINTS 
points3d(x=x,y=y,z=z,size=6,col="blue") 
text3d(x=x,y=y,z=z,texts=1:8,adj=c(-0.1,1.5),cex=0.8) 

# You can also plot each body point name. 
# This might be helpful when you don't know the 
# initial orientation of your plot 

# text3d(x=x,y=y,z=z,texts=rownames(DATA.matrix), 
#  cex=0.6,adj=c(-0.1,1.5)) 

# Based on the plotted figure, connect the line segments 
CONNECTOR<-c(1,2,2,3,3,4,3,5,3,7,5,6,7,8) 
segments3d(x=x[CONNECTOR],y=y[CONNECTOR],z=z[CONNECTOR],col="red") 

然後,我們有這樣的:

創建一個動畫,我們可以把這一切變成一個函數,並使用lapply

movement.points<-function(DATA,time.point,CONNECTOR,body.points,coordinates){ 

    DATA.time<-DATA[time.point,] 

    DATA.time<-matrix(DATA.time,c(body.points,coordinates),byrow = TRUE) 

    x<-unlist(DATA.time[,1]) 
    y<-unlist(DATA.time[,2]) 
    z<-unlist(DATA.time[,3]) 

    # I used next3d instead of open3d because now I want R to plot 
    # several plots on top of our original, creating the animation 

    next3d(reuse=FALSE) 
    points3d(x=x,y=y,z=z,size=6,col="blue") 
    segments3d(x=c(x,x[CONNECTOR]),y=c(y,y[CONNECTOR]),z=c(z,z[CONNECTOR]),col="red") 
# You can control the "velocity" of the animation by changing the 
# parameter below. Smaller = faster 
    Sys.sleep(0.5) 
} 

我知道這個解決方案並不優雅,但它的工作原理。

enter image description here