gpt4 book ai didi

c++ - OpenCV3.1 中的 imwrite 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:34 27 4
gpt4 key购买 nike

当我尝试使用 imwrite 保存图像时出现以下错误:

Files that help describe the problem:
C:\Users\jalal\AppData\Local\Temp\WER64CE.tmp.WERInternalMetadata.xml
C:\Users\jalal\AppData\Local\Temp\WER7092.tmp.appcompat.txt
C:\Users\jalal\AppData\Local\Temp\WER70C2.tmp.mdmp

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt

这是我的全部代码(代码有效——imshow 显示模糊图像):

#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <iostream>
#include <string>

using namespace cv;
using namespace std;

//void tintImageBlue(Mat& image);

int main()
{
Mat image;
Mat channels[3];

image = imread("mona1.jpg", IMREAD_GRAYSCALE);
split(image, channels);
//image = 0.2*channels[0] + 0.4*channels[1] + 0.4*channels[2]; //gives us a black and white image (grey)
image = 0.2126*channels[0] + 0.7152*channels[1] + 0.0722*channels[2]; //wikipedia formula
//Colorimetric (luminance-preserving) conversion to grayscale



if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return 0;
}

float neighbors[8];
float neighbors_mean = 0;
float neighbors_sum;

for (int iter = 0; iter < 3; iter++){
for (int i = 0; i < image.rows; i++) {
for (int j = 0; j < image.cols; j++) {


neighbors[0] = (((i - 1) >= 0 && (j - 1) >= 0) ? image.at<uchar>(i - 1, j - 1) : 0.0f);
neighbors[1] = (((i - 1) >= 0) ? image.at<uchar>(i - 1, j) : 0.0f);
neighbors[2] = (((i - 1) >= 0 && (j + 1) < image.cols) ? image.at<uchar>(i - 1, j + 1) : 0.0f);
neighbors[3] = (((j + 1) < image.cols) ? image.at<uchar>(i, j + 1) : 0.0f);
neighbors[4] = (((i + 1) < image.rows && (j + 1) < image.cols) ? image.at<uchar>(i + 1, j + 1) : 0.0f);
neighbors[5] = (((i + 1) < image.rows && (j - 1) >= 0) ? image.at<uchar>(i + 1, j) : 0.0f);
neighbors[6] = (((i + 1) < image.rows && (j - 1) >= 0) ? image.at<uchar>(i + 1, j - 1) : 0.0f);
neighbors[7] = (((j - 1) >= 0) ? image.at<uchar>(i, j - 1) : 0.0f);

neighbors_sum = neighbors[0] + neighbors[1] + neighbors[2] + neighbors[3] +
neighbors[4] + neighbors[5] + neighbors[6] + neighbors[7];

neighbors_mean = neighbors_sum / 8.0f;
image.at<uchar>(i, j) = neighbors_mean;


neighbors_sum = 0;
neighbors_mean = 0;

}
}
}












//tintImageBlue(image);

//namedWindow("Grey Mona", WINDOW_AUTOSIZE); // Create a window for display.
//imshow("Grey Mona", image); // Show our image inside it.

//resizeWindow("Grey Mona",800, 1000);

//waitKey(0); // Wait for a keystroke in the window
imwrite("10_iteration_blurring.jpg", image);
return 0;
}

但是使用 imwrite 它变得没有响应。我应该如何解决这个问题?

enter image description here

最佳答案

这对我有用:

 imwrite("10_iteration_blurring.bmp", image);

关于c++ - OpenCV3.1 中的 imwrite 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46207926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com