我正在使用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:\trunk\jpwl\Release\nouveau_dossier\filtre.jpg", dst, compression_params);// not ok
waitKey();
return 0;
}
答案 0 :(得分:1)
使用: &#34; d:\树干\ jpwl \推出\ nouveau_dossier \ filtre.jpg&#34; (使用双反斜杠,Stackoverflow也显示单个反斜杠)
或
@&#34; d:/trunk/jpwl/Release/nouveau_dossier/filtre.jpg" 代替。单个\是ESC字符。
迪克