save every histogram of an image in text file format by pressing space

May 13, 2013 at 6:13am
Hi guys,

I want to save a histogram text file every time when i space space.
i have say 5 images. i am showing the result of histogram after pressing the space.
but i want to save the histogram in text file with its image number name as index.

Currently,i am doing like this .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  if(imgWait == -1)
	{
		std::ostringstream  histDataToBuffer;
		
		histDataToBuffer << "Histo_info " << imgIndex << ".txt" << endl;
		
		std::string histo_info_update = histDataToBuffer.str();
		
		const char* histo_info2char = histo_info_update.c_str();
		
		for(int i  = 0; i<= n-1; i++)
		{
			histDataToBuffer << "["<< i << "]"<< histogram[i] << endl;
		}
	}


but it don't save the histogram in text file format. i can't see any file withe name "Histo_info1.txt" . Can any one guide me how can fix it, thanks
May 13, 2013 at 6:42am
If you want to write to a file, use file streams. Here's some basic examples: http://stackoverflow.com/questions/478075/creating-files-in-c
May 13, 2013 at 7:12am
but i want to create many text files with the same name and different file number every time when i press space.
That's my problem right now. i can create file and wrote data in it. no problem in creating and writing the data.
May 13, 2013 at 10:04am
yes, the histDataToBuffer is okay, but you can't use it to store the data.
The better name for histDataToBuffer would be histDataFilename (or so)

To store histogram[i] you need a new variable that is a fstream:

http://cplusplus.com/reference/fstream/fstream/?kw=fstream
May 29, 2013 at 8:01am
turning to file formats , so you will be able to save image in file formats. i believe you already have some data in mind. but that's a lot of work to do. take a look at: http://www.rasteredge.com/how-to/csharp-imaging/document-image-formats/
Topic archived. No new replies allowed.