Getting error -213: Unsupported combination of source format (=0), and destination format (=4) in function getLinearFilter
I am trying to apply the inbuilt laplacian operator on an image but I am getting error "error: (-213) Unsupported combination of source format (=0), and destination format (=4) in function getLinearFilter" Please tell how to resolve. Complete code:
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
using namespace cv;
const char ImageFilePath[] = "/home/user/Downloads/skeleton.tif";
/**
* @function main
*/
int main(int argc, char** argv) {
Mat src, dst;
Mat gray;
//
/// Load image
src = imread(ImageFilePath, 1);
//gray = Mat(src.rows, src.cols, CV_32SC1);
if (!src.data) {
return -1;
}
//cout << src.channels() << endl;
cvtColor(src, gray, CV_BGR2GRAY);
gray.convertTo(gray, CV_32SC1);
Mat res, abs_dst;
//res = gray.clone();
namedWindow("src image", CV_WINDOW_AUTOSIZE);
imshow("src image", gray);
Laplacian(gray, res, CV_32SC1, 3, 1, 0, BORDER_DEFAULT);
//namedWindow("Laplacian", CV_WINDOW_AUTOSIZE );
//imshow("Laplacian", res );
res += gray;
//convertScaleAbs( res, abs_dst );
//namedWindow("Addition", CV_WINDOW_AUTOSIZE );
// imshow("Addition", abs_dst );
waitKey(0);
return 0;
}
please, try not to pre-allocate the result Mat's it's usually not nessecary, and in your case, it even goes wrong here:
Mat(gray.rows, gray.cols, CV_32SC1)
// if at all, it should have been src.cols, src.rows, CV_8UC1 ! (gray is still empty, so gray.cols==gray.row==0)also you do not need
res = gray.clone();
again, this is c++, not c
@berak sorry for messing this up. I just corrected the program. Still it's buggy
^^ missed the 'other' error in there, read again !
@berak I was actually trying to execute the statement "res += gray" and as guided by error ended up in pre allocating the Mat object. Please suggest how can I successfully add two matrices.
@berak Even if i completely remove pre-allocation, I still get the same error.
to successfully add them, they have to be of the same type.
@berak I am allocating "gray" with exactly the same depth type using mat constructor. Then why should this matter?
it broke the
Laplacian()
, remember ?Still getting the same error
I have included your suggestions in the code still it is broken. And the error is same