Bilateral filter error, Assertion failed ((src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.data != dst.data)

asked 2016-06-11 11:50:45 -0600

BaKa gravatar image

updated 2016-06-11 16:48:52 -0600

berak gravatar image

My code is shown in the following:

Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
int width = b.getWidth();
int height =  b.getHeight();
Mat tmp = new Mat (width, height, CvType.CV_8UC3);
Mat tmp2 = tmp.clone();
Utils.bitmapToMat(b, tmp);
Imgproc.bilateralFilter(tmp,tmp2,10,50,10);

and give the following error,

OpenCV Error: Assertion failed ((src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.data != dst.data) in void cv::bilateralFilter_8u(const cv::Mat&, cv::Mat&, int, double, double, int), file /Volumes/Linux/builds/master_pack-android/opencv/modules/imgproc/src/smooth.cpp, line 3145

May i ask what's wrong with my code, Thanks a lot!!

edit retag flag offensive close merge delete

Comments

1

It's possible the Bitmap has a different number of channels. 4 is the most likely. Check for that.

Tetragramm gravatar imageTetragramm ( 2016-06-11 18:05:12 -0600 )edit

i have checked the channel of the src, it has 4 channels, but now i am confused about how to change the number of channels of the src btw thanks for your comment

BaKa gravatar imageBaKa ( 2016-06-12 00:33:18 -0600 )edit
1

Use the cvtColor function with COLOR_BGRA2BGR as the color code. See the documentation for more details.

Tetragramm gravatar imageTetragramm ( 2016-06-12 00:35:32 -0600 )edit

Thanks for you help, i can use it now!

BaKa gravatar imageBaKa ( 2016-06-12 00:49:43 -0600 )edit