Hello everybody. I am seeking help on how to save 3 output images into a specific path after filter by 3 different mask size e.g. 3x3, 5x5 and 7x7 mask. My program is in C:\Cpp\Project\, I wish to save those output images inside "filter" folder with path in C:\Cpp\Project\filter. Thus, the "filter" folder will have output images with name - "outputBOHE 3 x 3.pgm", "outputBOHE 5 x 5.pgm", and "outputBOHE 7 x 7.pgm". However, when I run my program, those output images are save at C:\Cpp\Project. Although I had created the "filter" folder, the output images cannot be save in C:\Cpp\Project\filter. Please advise me on how to solve this problem. Thanks in advance.
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
string NumberToString(int t)
{
ostringstream os;
os << t;
return os.str();
}
int main()
{
int cr_w, cr_h;
int ind=0;
image= cv::imread("BOHE.pgm", 0); //openCV format for reading an image
nl = image.rows; //openCV format to obtain image rows
nc = image.cols; //openCV format to obtain image columns
for (int i = 0; i < 3; i++)
{
cr_w = 3 + 2*(i%3); //mask width
cr_h = 3 + 2*(i%3); //mask height
//create 3 output images with name of "outputBOHE 3 x 3.pgm", "outputBOHE 5 x 5.pgm", and "outputBOHE 7 x 7.pgm" after filtering with 3x3, 5x5, and 7x7 mask
std::string name = "outputBOHE " + NumberToString(cr_w) +" x "+ NumberToString(cr_h)+".pgm";
//save the 3 output images into the following path
ofstream fout ("C:\Cpp\Project\filter");
fout.open (name.c_str());
fout <<"P2\n"<<nc<<'\t'<<nl<<endl<<cr_w<<'\t'<<cr_h<<endl<<255<<endl; //P2 is for image with pgm extension
for (int y=0; y<nl; y++)
{
for (int x=0; x<nc; x++)
{
fout << int(image.at<uchar>(y,x))<<' ';
}
}
fout.close();
}
return 0;
}