前提・実現したいこと
画像を連番で読み込み、階調を反転させて出力したい。
発生している問題・エラーメッセージ
処理結果の保存の箇所で「アクセス違反が発生しました」となってしまうのですが、そのエラーを解決できません。ご教授のほどよろしくお願いいたします。
該当のソースコード
C++
1#define _CRT_SECURE_NO_WARNINGS 2#define _USE_MATH_DEFINES 3#include<iostream> 4#include<cmath> 5#include<opencv2/opencv.hpp> 6using namespace std; 7using namespace cv; 8string win_src = "src"; 9string win_dst = "dst"; 10 11int main() 12{ 13 for (int i = -40; i <= 40; i += 10) { 14 string file_src = "aout" + to_string(i) + ".pgm"; // 入力画像のファイル名 15 string file_dst = "test" + to_string(i) + ".pgm"; // 出力画像のファイル名 16 Mat img_src = imread(file_src, 0); // 入力画像(グレースケール)の読み込み 17 18 Mat img_dst; 19 if (!img_src.data) { 20 cout << "error" << endl; 21 return -1; 22 } 23 24 int x, y; 25 26 for (y = 0; y < img_src.cols; y++) { 27 for (x = 0; x < img_src.rows; x++) { 28 img_src.at<unsigned char>(y, x) = 255 - img_src.at<unsigned char>(y, x); 29 } 30 } 31 32 imwrite(file_dst, img_src); // 処理結果の保存 33 34 waitKey(0); // キー入力待ち 35 } 36 37 return 0; 38}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/26 02:09