فهرست منبع

Added algoritm to straingten out camera perspective

Deben Oldert 10 سال پیش
والد
کامیت
4d4c6ca8fe
3فایلهای تغییر یافته به همراه37 افزوده شده و 18 حذف شده
  1. 15 15
      code/head.R
  2. 2 0
      code/main.R
  3. 20 3
      code/state.R

+ 15 - 15
code/head.R

@@ -8,7 +8,6 @@ plot(DATA$Head.y,
 )
 
 for(i in 1:nrow(DATA)){
-  print(i)
   points(i, DATA[i,]$Head.y, col = color[DATA[i,]$state])
 }
 
@@ -16,23 +15,24 @@ for(i in 1:nrow(DATA)){
 #Check if patient is walking straight enough
 differ_ <- 0.4
 
-WALKING <- strtoi(rownames(DATA[DATA$state==1,]))
-
 start <- min(WALKING)
 stop <- max(WALKING)
 
 
-segments(start, mean(c(DATA[start,]$Head.y, DATA[stop,]$Head.y)), stop, col = "black")
-
-base <- mean(c(DATA[start,]$Head.y, DATA[stop,]$Head.y))
-size_ <- 7
-for(i in seq(start, stop, size_)){
+segments(start, WALKBASE, stop, col = "black")
 
-  step <- mean(DATA[i:(i+size_),]$Head.y) - base
+#base <- mean(c(DATA[start,]$Head.y, DATA[stop,]$Head.y))
+#size_ <- 5
+# for(i in seq(start, stop, size_)){
+#
+#   step <- mean(DATA[i:(i+size_),]$Head.y) - base
+#
+#   for(j in 0:(size_ -1)){
+#     if(DATA[i+j,]$state != 1) next
+#     points(i+j, DATA[i+j,]$Head.y - step, p = "*")
+#   }
+#
+# }
 
-  for(j in 0:(size_ -1)){
-    if(DATA[i+j,]$state != 1) next
-    points(i+j, DATA[i+j,]$Head.y - step, p = "*")
-  }
-
-}
+# http://stats.stackexchange.com/questions/30975/how-to-add-non-linear-trend-line-to-a-scatter-plot-in-r
+# http://www.mathsisfun.com/geometry/parabola.html

+ 2 - 0
code/main.R

@@ -42,6 +42,8 @@ remove(y)
 remove(z)
 remove(cnv_)
 
+print("DATA PREPERATION DONE")
+
 source("code/state.R")
 
 source("code/head.R")

+ 20 - 3
code/state.R

@@ -1,6 +1,6 @@
 # CALCULATE PATIENT STATE ALGORITHM
 STATE = c("WALK", "UP", "DOWN", "SIT")
-size_ <- 7
+size_ <- 5
 differ_ <- 0.1
 
 POINTS <- data.frame(
@@ -59,9 +59,26 @@ for(i in size_:(nrow(DATA)-size_)){
     POINTS[i-size_,]$probability <- ((1 / size_) * tmp_[1,]$n)
   }
   DATA[i,]$state = state_
-  print(i)
 }
-print("STATE DONE")
+print("STATE CALCULATION DONE")
 remove(tmp_)
 DATA <- DATA[complete.cases(DATA),]
 rownames(DATA) <- 1:nrow(DATA)
+DATA$index = as.integer(rownames(DATA))
+
+WALKING <- strtoi(rownames(DATA[DATA$state==1,]))
+
+# DRAW PARABOLA (FOR CALCULATING STRAIGHT PATH)
+
+yPrediction <-lm(Head.y ~ I(index^2)+index, data=DATA[min(WALKING):max(WALKING),])
+#lines(WALKING, predict(lm2, data.frame(index=WALKING)), type = "l", col = "orange")
+
+yPredicted <- as.vector(predict(yPrediction, data.frame(index=WALKING)))
+
+WALKBASE <- mean(c(yPredicted[1], tail(yPredicted, n=1)))
+
+for(i in WALKING[1]:(length(WALKING) + WALKING[1] - 1)){
+  DATA[i,]$Head.y <- DATA[i,]$Head.y - (yPredicted[i-WALKING[1]+1] - WALKBASE)
+}
+
+plot(POINTS$probability, type = "l")