Skip to content

Instantly share code, notes, and snippets.

@bhive01
Last active July 6, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhive01/a018430eb88829fb04fe3c7afb6757c5 to your computer and use it in GitHub Desktop.
Save bhive01/a018430eb88829fb04fe3c7afb6757c5 to your computer and use it in GitHub Desktop.
rVision Optical Flow Demo
library(Rvision)
library(tidyverse)
vid_loc <- paste0(find.package("Rvision"), "/sample_vid/SampleVideo_1080x720_5mb.mp4")
vid1 <- video(vid_loc)
res <- data.frame(frame_pos = seq(2,nframes(vid1), 5), total_movement = NA)
old <- readFrame(vid1, 1)
pb <- txtProgressBar(min = 0, max = nrow(res), style = 3)
for(i in 1:nrow(res)) {
new <- readFrame(vid1, res$frame_pos[i])
of <- farneback(old, new, winsize = 61)
d <- sqrt(of[, , 1]^2 + of[, , 2]^2)
res$total_movement[i] <- sum(d)
old <- cloneImage(new)
setTxtProgressBar(pb, i)
}
close(pb)
ggplot(res, aes(x=frame_pos, y = total_movement, group=1)) + geom_path()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment