我试图从文件加载图像作为CvMat(如mat1)并尝试创建另一个矩阵(mat2)与正在读取的文件大小相同并尝试减去原始矩阵(mat1)的平均值并尝试将该值插入到新矩阵(mat2)中,但不幸的是我得到一个错误。有人可以告诉我为什么吗?我在OpenCV中使用C API。以下是代码将图像矩阵大小复制到OpenCV中的另一个矩阵
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
是你的mat1.type CV_32FC1? – William
@威廉我不知道。我只是试图从图像文件加载它。你知道我怎么检查它的类型? mat1的值是0和-2 – user227666
你可以尝试'mat1-> type()'而不是'CV_32FC1'吗? – JonesV