Ask Your Question
0

OpenCV Error : Asserson Failed CV_Assert( src.type() == srcType && dst.type() == dstType );

asked 2014-10-22 01:58:17 -0500

Deepak Kumar gravatar image

hi, i am having error in finding the imfilter of image. i have this code but it gives error as OpenCV Error : Asserson Failed CV_Assert( src.type() == srcType && dst.type() == dstType );

below is the code :-

Mat inner = cv::imread("C:\\Users\\Intern-3\\Desktop\\processed\\1.jpg",0);
int row = inner.rows; int col = inner.cols;
cv::imshow("Original Image", inner); // show the image*/

Point anchor( -1 ,-1 );
double delta = 0;

float data[2][5] = {{11,11,11,11,11},{11,11,11,11,11}};
//float kernel[2][2] = {{2,2},{2,2}};

Mat input = cv::imread("C:\\Users\\Intern-3\\Desktop\\processed\\1.jpg",0);
int row = input.rows; int col = input.cols;
cout<<"--------------------"<<endl;
cout<<"Input Image"<<endl;
cout<<"--------------------"<<endl;
cout<<"Row = "<<row<<endl;
cout<<"Col = "<<col<<endl;
Mat src = Mat(input.size(), CV_32FC1, &input);
Mat ker = Mat::ones(5, 5, CV_8U);
Mat dst = Mat(src.size(), src.type());

Ptr<FilterEngine> fe =  createLinearFilter(input.type(), ker.type(), ker, anchor, 
      delta, BORDER_CONSTANT, BORDER_CONSTANT, Scalar(0));

fe->apply(src, dst);

imshow("filter",dst);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-10-22 02:19:58 -0500

berak gravatar image

updated 2014-10-22 03:36:06 -0500

// this kernel does not make sense, but anyway.
float data[2][5] = {{11,11,11,11,11},{11,11,11,11,11}}; 

int row = input.rows; int col = input.cols;
cout<<"--------------------"<<endl;
cout<<"Input Image"<<endl;
cout<<"--------------------"<<endl;
cout<<"Row = "<<row<<endl;
cout<<"Col = "<<col<<endl;
/// oh noes! the address of a Mat is *not* pixel data. 
/// also, you can't convert to float this way 
//Mat src = Mat(input.size(), CV_32FC1, &input);
Mat src = input;                   // just keep it as is.
Mat ker = Mat(2, 5, CV_32F, data); // float data == CV_32F Mat
Mat dst = Mat(src.size(), CV_32F); // here, too.

Point anchor( -1 ,-1 );
double delta = 0;

Ptr<FilterEngine> fe =  createLinearFilter(input.type(), ker.type(), ker, anchor, 
      delta, BORDER_CONSTANT, BORDER_CONSTANT, Scalar(0));

fe->apply(src, dst);
edit flag offensive delete link more

Comments

this is my modified code. but still the output is not coming.

Point anchor( -1 ,-1 );
double delta = 0;

float kernel[5][5] = {{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}};
Mat input = cv::imread("C:\\Users\\Intern-3\\Desktop\\processed\\1.jpg",0);

Mat src = input;                   // just keep it as is.

Mat ker = Mat(5, 5, CV_32F, &amp;kernel); // float data == CV_32F Mat
Mat dst = Mat(src.size(), CV_32F); // here, too.

Ptr&lt;FilterEngine&gt; fe =  createLinearFilter(input.type(), ker.type(), ker, anchor, delta, BORDER_CONSTANT, BORDER_CONSTANT, Scalar(0));

fe-&gt;apply(src, dst);
imshow("filter",dst);
Deepak Kumar gravatar imageDeepak Kumar ( 2014-10-22 03:11:42 -0500 )edit

"output is not coming." - means ?

try values smaller than 1 in the kernel

berak gravatar imageberak ( 2014-10-22 03:21:07 -0500 )edit

means when i run the program the program does not shows any image and curser continues to moves. a kind of hang is going on

Deepak Kumar gravatar imageDeepak Kumar ( 2014-10-22 03:42:22 -0500 )edit

you need a waitKey(); after imshow();

berak gravatar imageberak ( 2014-10-22 03:44:59 -0500 )edit

its working ..........thanks

Deepak Kumar gravatar imageDeepak Kumar ( 2014-10-22 04:38:33 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-10-22 01:58:17 -0500

Seen: 1,548 times

Last updated: Oct 22 '14