Ask Your Question

crazymichel1's profile - activity

2015-12-28 07:32:31 -0500 received badge  Nice Answer (source)
2014-10-21 23:19:57 -0500 received badge  Teacher (source)
2014-10-01 22:45:44 -0500 received badge  Necromancer (source)
2014-10-01 18:26:30 -0500 answered a question How to remove black background from grabcut output image in OpenCV android ?

Here is my working java code for Haris answer:

`

 /**

 * Make the black background of a PNG-Bitmap-Image transparent.
 * code based on example at http://j.mp/1uCxOV5
 * @Param image png bitmap image
 * @return output image
 */

private static Bitmap makeBlackTransparent(Bitmap image) {
    // convert image to matrix
    Mat src = new Mat(image.getWidth(), image.getHeight(), CvType.CV_8UC4);
    Utils.bitmapToMat(image, src);

    // init new matrices
    Mat dst = new Mat(image.getWidth(), image.getHeight(), CvType.CV_8UC4);
    Mat tmp = new Mat(image.getWidth(), image.getHeight(), CvType.CV_8UC4);
    Mat alpha = new Mat(image.getWidth(), image.getHeight(), CvType.CV_8UC4);

    // convert image to grayscale
    Imgproc.cvtColor(src, tmp, Imgproc.COLOR_BGR2GRAY);

    // threshold the image to create alpha channel with complete transparency in black background region and zero transparency in foreground object region.
    Imgproc.threshold(tmp, alpha, 100, 255, Imgproc.THRESH_BINARY);

    // split the original image into three single channel.
    List<Mat> rgb = new ArrayList<Mat>(3);
    Core.split(src, rgb);

    // Create the final result by merging three single channel and alpha(BGRA order)
    List<Mat> rgba = new ArrayList<Mat>(4);
    rgba.add(rgb.get(0));
    rgba.add(rgb.get(1));
    rgba.add(rgb.get(2));
    rgba.add(alpha);
    Core.merge(rgba, dst);

    // convert matrix to output bitmap
    Bitmap output = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(dst, output);
    return output;
}`
2014-09-05 10:21:32 -0500 answered a question Errors on importing OpenCV Samples : BasedLoaderCallback cannot be resolved to a type
2014-09-05 10:17:45 -0500 answered a question the import org.opencv.android cannot be resolved

and in addition to autodev101s solution (which worked for me) make sure that you do not copy the samples into your workspace but just reference them, otherwise you get a couple of further errors

2014-08-30 13:09:46 -0500 received badge  Supporter (source)
2014-08-30 13:09:44 -0500 received badge  Scholar (source)
2014-08-29 18:03:51 -0500 asked a question Is it possible to use OpenCV in Android- and IPhone-App without rooting/jailbreaking the device?

Sorry if the answer is too obvious. I ask because a friend of mine said it would not be possible. I do not need to read up on the subject and start coding if the answer is no..