我正在尝试将文件中的图像加载为 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