我正在使用OpenCV库和visual studio 2013。我只想将结果图像保存在一个完整的路径中。对于相同的路径可以,但c:\...
不起作用。我尝试使用前向和后向
/
,结果看起来是一样的。这是代码:
#include<iostream>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat src, dst;
float sum;
/// Load an image
src = imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE);
if (!src.data)
{
return -1;
}
// define the kernel
float Kernel[3][3] = {
{ 1 / 9.0, 1 / 9.0, 1 / 9.0 },
{ 1 / 9.0, 1 / 9.0, 1 / 9.0 },
{ 1 / 9.0, 1 / 9.0, 1 / 9.0 }
};
dst = src.clone();
for (int y = 0; y < src.rows; y++)
for (int x = 0; x < src.cols; x++)
dst.at<uchar>(y, x) = 0.0;
//convolution operation
for (int y = 1; y < src.rows - 1; y++){
for (int x = 1; x < src.cols - 1; x++){
sum = 0.0;
for (int k = -1; k <= 1; k++){
for (int j = -1; j <= 1; j++){
sum = sum + Kernel[j + 1][k + 1] * src.at<uchar>(y - j, x - k);
}
}
dst.at<uchar>(y, x) = sum;
}
}
namedWindow("final");
imshow("final", dst);
namedWindow("initial");
imshow("initial", src);
vector<int> compression_params; //vector that stores the compression parameters of the image
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); //specify the compression technique
compression_params.push_back(100); //specify the compression quality
bool bSuccess = imwrite("filtre.jpg", dst, compression_params);//ok
bool bSucccess = imwrite("D:/trunk/jpwl/Release/nouveau_dossier/filtre.jpg", dst, compression_params);// not ok
bool bSuccces = imwrite("D:trunkjpwlReleasenouveau_dossierfiltre.jpg", dst, compression_params);// not ok
waitKey();
return 0;
}
使用:"D:\trunk\jpwl\Release \nouveau_dossier\filtre.jpg"(带有双反斜杠,Stackoverflow还显示一个反斜杠)
或
@"D:/trunk/jpwl/Release/nouveau_dossier/filtre.jpg"相反单个\是一个ESC字符。
Dick