Ask Your Question

Revision history [back]

Using adaptative thresshold on android.

I am trying to use an adaptative thresshold to binarize one image using the open cv library. The code is the following:

public Bitmap filter(Bitmap image){

    Log.d(TAG, " Filtering ... ");

    Mat inputMat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8U/*.CV_8UC1*/);
    Utils.bitmapToMat(image, inputMat);

    Mat inputMat2 = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8U);     
    Mat outputMat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8U);

    Log.d(TAG, " Pre Filtering ... ");

    Imgproc.adaptiveThreshold(inputMat, outputMat, 50, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 25);

    // Photo.fastNlMeansDenoisingColored(inputMat, outputMat);
    Log.d(TAG, " Filtering Done... ");

    Bitmap output = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.RGB_565);
    Utils.matToBitmap(outputMat, output);

    return output;  
}

I had tried several types as CV_8UC1 or CV_8SC1, but all always cause the same error at executing the function:

05-16 00:50:33.125: E/AndroidRuntime(1892): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=102, result=-1, data=Intent { dat=content://media/external/images/media/15312 (has extras) }} to activity {com.medicasafe.images/com.medicasafe.images.ImageDecodingActivity}: CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/thresh.cpp:796: error: (-215) src.type() == CV_8UC1 in function void cv::adaptiveThreshold(cv::InputArray, cv::OutputArray, double, int, int, int, double)

The method is executed in onActivityResult() after the user select one image from gallery.

click to hide/show revision 2
retagged

updated 2014-05-16 00:45:54 -0600

berak gravatar image

Using adaptative thresshold on android.

I am trying to use an adaptative thresshold to binarize one image using the open cv library. The code is the following:

public Bitmap filter(Bitmap image){

    Log.d(TAG, " Filtering ... ");

    Mat inputMat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8U/*.CV_8UC1*/);
    Utils.bitmapToMat(image, inputMat);

    Mat inputMat2 = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8U);     
    Mat outputMat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8U);

    Log.d(TAG, " Pre Filtering ... ");

    Imgproc.adaptiveThreshold(inputMat, outputMat, 50, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 25);

    // Photo.fastNlMeansDenoisingColored(inputMat, outputMat);
    Log.d(TAG, " Filtering Done... ");

    Bitmap output = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.RGB_565);
    Utils.matToBitmap(outputMat, output);

    return output;  
}

I had tried several types as CV_8UC1 or CV_8SC1, but all always cause the same error at executing the function:

05-16 00:50:33.125: E/AndroidRuntime(1892): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=102, result=-1, data=Intent { dat=content://media/external/images/media/15312 (has extras) }} to activity {com.medicasafe.images/com.medicasafe.images.ImageDecodingActivity}: CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/thresh.cpp:796: error: (-215) src.type() == CV_8UC1 in function void cv::adaptiveThreshold(cv::InputArray, cv::OutputArray, double, int, int, int, double)

The method is executed in onActivityResult() after the user select one image from gallery.