ファイルから画像を CvMat として (mat1 として) 読み込もうとしており、読み取られているファイルと同じサイズの別の行列 (mat2) を作成しようとしており、元の行列 (mat1) の平均値を減算しようとしています。新しいマトリックス(mat2)に値を挿入しますが、残念ながらエラーが発生しています。理由を教えてもらえますか?OpenCVでC APIを使用しています。以下はコードです
CvMat* mat1 = cvLoadImageM(argv[2], CV_LOAD_IMAGE_UNCHANGED); // load an image from a file as a CvMat
CvMat* mat2 = cvCreateMat(mat1->width, mat1->height, CV_32FC1); // trying to create a matrix as same width and height as the image file being loaded.
CvScalar avg = cvAvg(mat1); // calculating the avg of all elements of matrix
cvSubS(mat1, avg, mat2); // subtracting the average value from the original matrix and inserting the new values to matrix mat2
エラーは
OpenCV Error: Assertion failed (src1.size == dst.size && src1.channels() == dst.channels()) in cvAddS, file /home/Documents/opencv-2.4.5/modules/core/src/arithm.cpp, line 2783 terminate called after throwing an instance of 'cv::Exception' what(): /homeDocuments/opencv-2.4.5/modules/core/src/arithm.cpp:2783: error: (-215) src1.size == dst.size && src1.channels() == dst.channels() in function cvAddS