次のコードを見てください
#include <iostream>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
using namespace std;
using namespace cv;
Mat PeperAndSalt(Mat *,int);
int main()
{
Mat image,image2;
try
{
image = imread("C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg");
if(!image.data)
{
throw 1;
}
}
catch(int a)
{
cout << "Error. Image does not exist" << endl;
exit(0);
}
//Display Normal Image
namedWindow("Normal Image");
imshow("Normal Image",image);
//Edited Image
image2 = PeperAndSalt(&image,3000);
namedWindow("Edited Image");
imshow("Edited Image",image2);
waitKey(0);
return 0;
}
Mat PeperAndSalt(Mat *imagePtr, int numberOfPixels)
{
srand(numberOfPixels);
Mat newMat;
imagePtr->copyTo(newMat);
for(int a=0;a<numberOfPixels;a++)
{
int column = rand()%newMat.cols;
int row = rand()%newMat.rows;
if(newMat.channels()==1)
{
//Grey Image
newMat.at<uchar>(column,row)= 255;
}
else if(newMat.channels()==3)
{
//Colour Image
newMat.at<Vec3b>(column,row)[0]=255;
newMat.at<Vec3b>(column,row)[1]=255;
newMat.at<Vec3b>(column,row)[2]=255;
}
}
return newMat;
}
このコードは次のエラーを生成します
Unhandled exception at 0x756a9617 in OpenCV1.exe: Microsoft C++ exception: cv::Exception at memory location 0x003bf2a0..
どうしてこれなの?助けてください!
編集
これは、OpenCV の組み込みクラスである Mat.hpp で発生するエラーです。デバッグ中にこれを取得しました
編集
エラーはこの行にあります
image2 = PeperAndSalt(&image,3000);