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
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]);


//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();
cvSaveImage(s.c_str(), result);
cerr << "Done rotating images about y" << endl;

return (EXIT_SUCCESS);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s