Getting error -213: Unsupported combination of source format (=0), and destination format (=4) in function getLinearFilter

asked 2015-03-30 09:34:15 -0600

bubble gravatar image

updated 2015-03-30 10:09:16 -0600

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;

}
edit retag flag offensive close merge delete

Comments

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 gravatar imageberak ( 2015-03-30 09:45:08 -0600 )edit

@berak sorry for messing this up. I just corrected the program. Still it's buggy

bubble gravatar imagebubble ( 2015-03-30 09:50:36 -0600 )edit

^^ missed the 'other' error in there, read again !

berak gravatar imageberak ( 2015-03-30 09:53:54 -0600 )edit

@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.

bubble gravatar imagebubble ( 2015-03-30 09:54:52 -0600 )edit
1

@berak Even if i completely remove pre-allocation, I still get the same error.

bubble gravatar imagebubble ( 2015-03-30 09:57:11 -0600 )edit

to successfully add them, they have to be of the same type.

gray.convertTo(gray, CV_32S);
res += gray;
berak gravatar imageberak ( 2015-03-30 09:58:16 -0600 )edit

@berak I am allocating "gray" with exactly the same depth type using mat constructor. Then why should this matter?

bubble gravatar imagebubble ( 2015-03-30 10:01:31 -0600 )edit

it broke the Laplacian() , remember ?

berak gravatar imageberak ( 2015-03-30 10:02:47 -0600 )edit

Still getting the same error

bubble gravatar imagebubble ( 2015-03-30 10:04:32 -0600 )edit

I have included your suggestions in the code still it is broken. And the error is same

bubble gravatar imagebubble ( 2015-03-30 10:09:52 -0600 )edit