有关将循环输出保存到.csv文件的问题

时间:2016-11-09 10:01:35

标签: c++ csv

我是编程的新手。我有一个问题,关于将循环的输出保存到.csv文件。

#include <iostream>
#include <string>

#include <cstdlib>
#include <fstream>
#include <ios>
#include <iomanip>
#include <sstream>


#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/videoio/videoio.hpp"

#include "opencv2/core/cvdef.h"
#include <cstddef>
#include <cstring>
#include <cctype>

#include <algorithm>
#include <utility>
#include <cstdlib>
#include <cmath>
#include "opencv2/core/ptr.inl.hpp"

#include "dirent.h"
#include "windows.h"

#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"

#include "opencv2/flann/miniflann.hpp"
#include "opencv2/highgui.hpp"

#include <opencv2/calib3d/calib3d.hpp>

#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"



using namespace cv;
using namespace std;





#define SHOW_RESULTS 
typedef long SLONG;
typedef LARGE_INTEGER TIMER;
static SLONG
flag_timer_setup = 0;
static LARGE_INTEGER
lpTimerFrequency;

//-------------------------------------------------------
void SYS_reset_timer ( TIMER *tick )
//-------------------------------------------------------
{
if( flag_timer_setup == 0)
{
QueryPerformanceFrequency(&lpTimerFrequency);
flag_timer_setup = 1;
}

QueryPerformanceCounter( tick );

}

//-------------------------------------------------------
SLONG SYS_get_timer_us           ( TIMER *tick)
//-------------------------------------------------------
{
TIMER
lpPerformanceCountEnd;
QueryPerformanceCounter( &lpPerformanceCountEnd );

return ((SLONG)(0xFFFFFFFF & ((lpPerformanceCountEnd.QuadPart - tick->QuadPart) * 1000000L / lpTimerFrequency.QuadPart)) );
}

int testBlur(Mat sourceImage, Mat & destinationImage, float & time)
{

TIMER tic;

/// test parameters
int filterSize = 11;
int N = 1000;
int time1;
if( sourceImage.empty()) // Check for invalid input
{
cout <<  "Invelid input image" << std::endl ;
return -1;
}


for (filterSize =1; filterSize <11; filterSize+=1)
{
    SYS_reset_timer(&tic);  

for(int i =0; i<N; i++)
{
    // filter the image
    blur(sourceImage, destinationImage, cvSize(filterSize, filterSize));

}

SLONG elapsed_time = SYS_get_timer_us(&tic);
float elapsed_time_seconds = elapsed_time/1000.0f;
float el = (elapsed_time_seconds)/N;

cout<< "blur"<< el<<endl;
time = el;
}


return 0;

}

int main(int argc, const char* argv[])

{
Mat sourceImage, destImage, temp, desttImage, detect;
Mat grad,src,distanceTransform;
int scale = 1;
int delta = 0;
float time;
int ddepth = -1;    


////////
ofstream myfile;
myfile.open ("Elapsed Time For Image Filtering.csv");

//load image
sourceImage = imread("../images/man.tiff",IMREAD_GRAYSCALE); // load and convert to grayscale
if( sourceImage.empty() )                      // Check for invalid input                                           
{
cout <<  "Could not open or find the image" << std::endl ;
return -1;
}








// call test function for blur
testBlur(sourceImage, destImage,time);
myfile << "Blur;"<<time<<time<<endl;
imwrite("blur.bmp", destImage);

//show results
#ifdef  SHOW_RESULTS
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Display window", destImage );                // Show our image inside it.
//waitKey(0); // Wait for a keystroke in the window
#endif

我转换了图像并使用了一些过滤功能并添加了计时器来测试tick和toc,我通过挂起过滤器的值来添加for循环,并且我无法将testblur的十个输出保存到.csv文件。请告诉我如何将测试模糊的for循环输出打印到.csv文件。

提前致谢

0 个答案:

没有答案