Tag Archives: time slicing

Timeslice Code Available

Set up a google code svn repo for the time slicing code for anyone interested:
https://code.google.com/p/videotimeslice/

Advertisements

More Timeslicing + Some Old Stuff

Got a new Cannon Powershot sx200is (was promptly CHDK’d) which can do some surprisingly good 720p video. So I thought I’d have a bash at running some footage through the timeslicing code I’ve written. Unfortunately the re-encoding with ffmpeg wasn’t so good so the quality is a bit out of whack, but here is is anyway with the wonderful BlackCloud1711 modelling for the footage:

Also here’s a couple of pictures of an old GCSE (I think) project. It’s a parallel port controlled pen drum plotter. Most of the mechanical hardware was built by my dad with a couple of design suggestions thrown in from me, all the electronics and software was done by me (before the days of fancy-pancy arduinos). It’s controlled through the parallel port with all the code written in QBasic on a IBM100 (100Mhz raaaawwww power, also the first computer that was mine, it was only about 10 years out of date).

One of these days I’ll get round to adding an arduino with a G-Code interpreter to it so I can get some delicious plotting action on the go.

Time Slicing Update

Been spending the past few evenings playing around with and rewriting the time slicing code I wrote a while back. It now pushes and pops the camera frames into a fixed size buffer and allows you to set the rotation of the “slice” through the buffer. The effect this achieves is quite difficult to describe so here is a video to demonstrate it.

Here’s a brief description of each of the sections.

  • Normal video recorded @ 640×480 with a cheap webcam in my front yard. Splitting the frames out using ffmpeg for processing greatly reduced the quality of the subsequent sections (probably need to play around with some switches).
  • Time slice set at 45 degrees, effectively making columns of pixels to the right of the image be further back in time the columns on the left. The video appears to “grow” from the centre at the start of the section as the frame buffer fills up.
  • The time slice slowly rotates about the centre axis, changing the view from one instance in time at 0 degrees to the “history” of  the centre column of pixels at 180 degrees.
  • Same as previous section but with the slice rotating faster. Note how objects at the edge appear to be sped up while objects towards the centre slow down, this is due to the rotation of the slice effectively speeding up the play back of columns of pixels at the edge of the frames.

Why am I wandering aimlessly through an overgrown yard? Well the idea was the movement of the plants would look cool, but the web-cam I used to capture the video was too shitty to pick up much detail. One of these day’s I’ll save up for a decent video camera.

Currently the slice is only rotatable in one axis, will hopefully change this in later versions to allow full 3D positioning, and will probably get round to releasing the code at some point aswell.

Time Slicing part 2

So here is a new time-sliced video and the opencv code used to create it. The video is under a Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK license and the code is GPL’ed.

In order to get the code to work you will need the opencv image processing libraries as well as the libboost libraries. The code was built and tested on Ubuntu 9.10 using Opencv 2.0 (not available in repos, will have to build yourself. Earlier versions of opencv probably should work.)

In order to use the program you will have to split out the individual frames of the video using this command:

ffmpeg -i filename.ogv -r 30 -f image2 %03d.jpg

Then run TimeSlice in the directory thusly:

./timeslice *.jpg

This will produce the individual time sliced frames (Overwriting some of the original frames). Now delete the remainder of the original frames (if there are any) and run the following command to create a .avi:

ffmpeg -sameq -r 30 -b 7200 -i %03d.jpg test.avi

/*
* File:   main.cpp
* Author: matt
*
* Created on 03 March 2010, 15:51
*/

/*This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.*/


#include <stdlib.h>
#include <cv.h>
#include <cvaux.h>
#include <highgui.h>
#include <iostream>
#include <iomanip>
#include <boost/intrusive/list.hpp>
using namespace std;

/*
*
*/
int main(int argc, char** argv) {

std::vector<IplImage*> image_vector;

//Load images
cerr << "Loading Images" << endl;
for (int loop = 1; loop < argc; loop++) {
IplImage *image;
cerr << "    Loading: " << argv[loop] << endl;
image = cvLoadImage(argv[loop]);

image_vector.push_back(image);

}
//return 0;
cerr << "Finished Loading" << endl;


//Process Frames
int depth = 0;

cerr << "Rotating images about y" << endl;
for (int depth = 0; depth < image_vector[0]->width; depth++) {
IplImage *result = cvCreateImage(cvSize(image_vector.size(),
                          image_vector.back()->height), IPL_DEPTH_32F, 3);

for (int x = 0; x < image_vector.size(); x++) {
for (int y = 0; y < image_vector[x]->height; y++) {
CvScalar pix = cvGet2D(image_vector[x], y, depth);
cvSet2D(result, y, x, pix);
}
}
std::string s;
std::stringstream out;
out<< setw(3) << setfill('0') <<depth;
s = out.str();
s.append(".jpg");
cvSaveImage(s.c_str(), result);
//result_vector.push_back(result);
}
cerr << "Done rotating images about y" << endl;

return (EXIT_SUCCESS);
}

Time Slicing

Not in the cool Terry Pratchet “Theif of Time” way. More in the “messing-around-with-video-to-get-funny-effects” way.

So imagine video as a set of still images. Then imagine stacking these pictures one in-front of the other. In order to play the video you would have to start at the front of the stack and move backwards making each of the images totally transparent.

Now take that same stack of images, rotate it 90 degrees about the y axis so your looking at them side on (The x axis and time axis have now swapped round). Then take slices through this. You have now time sliced!

Illustration of rotating the "image stack"

Hold onto your hats because heres a video of this in action:

What can this be used for you may be asking? Well if you run a horizontal sobel filter over the individual time sliced frames you have a “rate-of-change-with-time”  for each pixel.

Now take a feed from a camera. Stick the incoming frames onto a queue of a set size. time slice these frames. Do a sobel filter on them and then spin em back to normal and compress all the frames into a single frame (do the average or just take one of them or something). Then use this single frame as an alpha channel mask. This will give you a sort-of-temporally-adjusting-background-subtraction-type-thing.