Ask Your Question
0

GaborFilter Android

asked 2017-07-19 13:38:31 -0600

I have a problem with GaborFilter in Android. I try to implement this filter because CannyFilter is too weak for my purposes. I want to use it to get edges with great accuracy from the image provided by the user but when I call this method I get problems with src.type. Does my image is in wrong format?

GaborFilter implementation:

private Bitmap gaborFilter(Bitmap bitmap){
    Mat tmp = new Mat();
    Utils.bitmapToMat(bitmap, tmp);

    Mat edges = new Mat(tmp.size(), CvType.CV_32F);
    //tmp.convertTo(tmp, CvType.CV_8U);
    //Imgproc.cvtColor(tmp, edges, Imgproc.COLOR_RGB2GRAY, 4);

    double sigma = 15, theta = 4.71, lambda = 50, gamma = 0.6;
    Mat kernel = Imgproc.getGaborKernel(new Size(3,3),sigma,theta,lambda,gamma);

    Imgproc.filter2D(tmp, edges, CvType.CV_32F, kernel);

    Bitmap resultBitmap = Bitmap.createBitmap(tmp.cols(), tmp.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(dst, resultBitmap);

    return resultBitmap;
}

Error that I received:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=11, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:42 flg=0x1 }} to activity {com.example.janekxyz.teest/com.example.janekxyz.teest.MainActivity}: CvException [org.opencv.core.CvException: /build/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:98: error: (-215) src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4 in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)]

Any thoughts how can I make this code run?

P.S. I'm new to OpenCV.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-20 00:49:02 -0600

berak gravatar image

you should apply filter2D to a single channel float image, and the result will be in the same format, so you'll have to convert it back to CV_8U (maybe using scale & offset values) before putting it back into a bitmap, also Bitmap.Config.ARGB_8888 might be the wrong flag there (single channel).

also, i'm afraid, this won't give you a "better Canny" edge detection, but it will select only very specific edges by angle and size given in the getGaborFilter() params.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-19 13:38:31 -0600

Seen: 339 times

Last updated: Jul 20 '17