Ask Your Question
0

OpenCV4Android - BilateralFilter Problems

asked 2016-04-21 08:59:59 -0500

Silberlicht gravatar image

updated 2016-04-21 13:52:53 -0500

So I'm attempting to use a bilateralFilter and it's crashing for reasons unknown to me.

I'm following these as a guide and I'm not seeing anything wrong:
http://opencvexamples.blogspot.com/20...
http://docs.opencv.org/2.4/doc/tutori...

private Mat sharpen(Mat passedImage)
{
    Mat bilateral = passedImage.clone();
    Imgproc.cvtColor(bilateral, bilateral, Imgproc.COLOR_BGRA2BGR);

    int iSize = 9;

    Imgproc.bilateralFilter(bilateral, bilateral, iSize, iSize*2, iSize/2);

    return bilateral;
}
edit retag flag offensive close merge delete

Comments

1

In the documentation of bilateralFilter:

src – Source 8-bit or floating-point, 1-channel or 3-channel image.
Eduardo gravatar imageEduardo ( 2016-04-21 09:20:59 -0500 )edit

Updated Code to be a 3-Channel but something else must be wrong.

Silberlicht gravatar imageSilberlicht ( 2016-04-21 10:17:18 -0500 )edit
1

What happens if you use different Mat for input src and output dst?

Eduardo gravatar imageEduardo ( 2016-04-21 11:04:03 -0500 )edit

That did it... Thanks. I didn't even think that might cause a problem.

Silberlicht gravatar imageSilberlicht ( 2016-04-21 13:48:22 -0500 )edit
1

@berak, I reopened the question for the following reason: if there is not an error report than an explicit internal clone should be made to make this work. I would thus like to know if there was an error in the first case? @Silberlicht, can you enlighten us?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-22 06:28:20 -0500 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2016-04-22 07:20:18 -0500

berak gravatar image

from the c++ docs :

This filter does not work inplace.

so, you have to use a new Mat for the result:

private Mat sharpen(Mat passedImage)
{
    Mat bgr = new Mat();
    Imgproc.cvtColor(passedImage, bgr, Imgproc.COLOR_BGRA2BGR);

    int iSize = 9;
    Mat bilateral = new Mat();
    Imgproc.bilateralFilter(bgr, bilateral, iSize, iSize*2, iSize/2);
    bgr.release(); // !!

    return bilateral;
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-04-21 08:59:59 -0500

Seen: 167 times

Last updated: Apr 22 '16