By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

Read images from two different folder, apply optical flow method and store results as

P: 1
I have 1800 frames(for instance, tsukuba_daylight_L_00001,tsukuba_daylight_L_00002. ...tsukuba_daylight_L_01799 ), I need to read images from two different folder. Apply optical flow method and store the result as text files (for example: frame1.txt,frame2.text....) for all te frames. Here, I attached the code which I have tried. I'm not getting output. Could anyone please, tell me where exactly I'm going wrong.

#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdlib.h>
#include <math.h>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <sstream>
#include <video/video.hpp>
#include <iostream>
#include <fstream>

using namespace std;
using namespace cv;

string intToStr(int i,string path){
string bla = "00001";
stringstream ss;
ss<<i;
string ret ="";
ss>>ret;
string name = bla.substr(0,bla.size()-ret.size());
name = path+name+ret+".png";
return name;
}


int main(int argc, char** argv)
{
// ifstream File;
// File.open("E:/Thesis/LEFTRIGHT/left/*.png");

// if(!File.is_open())
// {
// cout<<"unable to open file";
// exit(1);
// }

// File.close();


int width, height;

Size(640,480);
//Mat x_vector= Size(0,639)+ 0.5;


int i=3;
for(int i = 3 ; i< 10 ; i++)
{
string Leftfile = intToStr(i,"E:/Thesis/LEFTRIGHT/left/tsukuba_daylight_L_");
string Rightfile = intToStr(i,"E:/Thesis/LEFTRIGHT/right/tsukuba_daylight_R_");
string leftfilenextframe = intToStr(i+1,"E:/Thesis/LEFTRIGHT/left/tsukuba_daylight_L_");
string rightfilenextframe = intToStr(i+1, "E:/Thesis/LEFTRIGHT/right/tsukuba_daylight_R_" ) ;

Mat left_image_f1= imread(Leftfile,1);
Mat right_frame_f1= imread(Rightfile,1);
Mat left_next_frame_f2= imread(leftfilenextframe,1);
Mat right_next_frame_f2= imread(rightfilenextframe,1);


imshow("left image", left_image_f1);

Ptr<DenseOpticalFlow> TVL1= createOptFlow_DualTVL1();
Mat results;
TVL1->calc(left_image_f1,right_frame_f1,results);
cout<<"Size of the image"<< results.size<<endl;
//printf("Channels", results.channels);


// export all text files into folder

//string name= "frame";
//ostringstream out;

char filename[32];
FILE *fp;
sprintf(filename, "frame%d.txt", i );
fp= fopen(filename,"wb");
fprintf(fp,"%f \t %f\n", results);
fclose(fp);

waitKey(0);

}
}
May 9 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.