Ask Your Question

Opencv_lover's profile - activity

2017-05-10 03:53:52 -0500 received badge  Popular Question (source)
2016-04-08 06:43:01 -0500 received badge  Notable Question (source)
2014-11-17 16:16:31 -0500 received badge  Popular Question (source)
2014-10-19 14:47:26 -0500 received badge  Student (source)
2014-04-29 04:15:10 -0500 commented question change grabcut background to white

It is very kind of you to help me ,But ,the code is C\C++,it can not run on the android phone ,can you give me the android code to solve this problem,Thank you~

2014-04-29 02:27:47 -0500 asked a question How to change Grabcut black backgroung to other color

Hello,every one,I use grabcut as opencv step by step ,but the result image is not the right image as I need,here is the code,It is should be output an white background bitmap ,but it is still black.

 //GrabCut part
         Mat img = new Mat();
         Utils.bitmapToMat(bitmap, img);
         Log.d(TAG, "img: " + img);

         int r = img.rows();
         int c = img.cols();

         Point p1 = new Point(rect.left,rect.top );
         Point p2 = new Point(rect.right, rect.bottom);
         org.opencv.core.Rect rect1=new  org.opencv.core.Rect(p1,p2) ;
         //Rect rect = new Rect(50,30, 100,200);
         Log.d(TAG, "rect: " + rect);
         Mat mask = new Mat();
         mask.setTo(new Scalar(125));
         Mat fgdModel = new Mat();
         fgdModel.setTo(new Scalar(255, 255, 255));
         Mat bgdModel = new Mat();
         bgdModel.setTo(new Scalar(255, 255, 255));
         Mat imgC3 = new Mat();  
         Imgproc.cvtColor(img, imgC3, Imgproc.COLOR_RGBA2RGB);
         Log.d(TAG, "imgC3: " + imgC3);
         Log.d(TAG, "Grabcut begins");
         Imgproc.grabCut(imgC3, mask, rect1, bgdModel, fgdModel,5, Imgproc.GC_INIT_WITH_RECT);
         Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
         Core.compare(mask, source, mask, Core.CMP_EQ);
         Mat foreground = new Mat(img.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));//background should be white
          img.copyTo(foreground,mask);//finish
        //  foreground.setTo(new Scalar(255, 255, 255));
            Utils.matToBitmap(foreground, bitmap);
2014-04-29 00:45:14 -0500 commented question change grabcut background to white

I am new to the image process area ,can you give me the right code to me ,I would be very appearcaite it

2014-04-28 22:18:23 -0500 commented answer How to remove black background from grabcut output image in OpenCV android ?

Can you give me your java code to remove the block background.Very Thanks

2014-04-28 06:55:07 -0500 asked a question change grabcut background to white

Here is my code to use grabcut on the android phone,But when finish the grabcut ,the background is black ,how to let it white,Thanks a lot!

org.opencv.core.Rect rect1=new  
org.opencv.core.Rect(p1,p2) ;
//Rect rect = new Rect(50,30, 100,200);
Log.d(TAG, "rect: " + rect);
Mat mask = new Mat();
mask.setTo(new Scalar(125));
Mat fgdModel = new Mat();
fgdModel.setTo(new Scalar(255, 255, 255));
Mat bgdModel = new Mat();
bgdModel.setTo(new Scalar(255, 255, 255));
Mat imgC3 = new Mat();  
Imgproc.cvtColor(img, imgC3, Imgproc.COLOR_RGBA2RGB);
Log.d(TAG, "imgC3: " + imgC3);
Log.d(TAG, "Grabcut begins");
Imgproc.grabCut(imgC3, mask, rect1, bgdModel, fgdModel,5, Imgproc.GC_INIT_WITH_RECT);
Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
Core.compare(mask, source, mask, Core.CMP_EQ);
//  Core.compare(mask,cv::GC_PR_FGD,mask,Core.CMP_EQ);
Mat foreground = new Mat(img.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
img.copyTo(foreground, mask);//提取完成
//convert to Bitmap
Log.d(TAG, "Convert to Bitmap");
Utils.matToBitmap(foreground, bitmap);
img.release();
imgC3.release();
mask.release();
fgdModel.release();
bgdModel.release();
return bitmap;
2013-07-05 03:23:10 -0500 asked a question Android Opencv 2.4.0 Sift Feature

Hello,Everyone ,I use opencv to extact sift feature,the result image show the result ,but How can I see how many features detect and most important,what is the feature message such as 128-d vector. Thanks for help!

2013-07-03 00:20:08 -0500 asked a question How To use OpenCv(2.4.5) GrabCut

Hello Everyone,

Here is my code using the OpenCv method GrabCut, but there is a problem. The input image is a color image, but through Grabcut, the result image is a grey level image.

The code as follows:

    Long startTime = System.currentTimeMillis();

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.p4);
    Log.d(TAG, "bitmap: " + bitmap.getWidth() + "x" + bitmap.getHeight());


    bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Log.d(TAG, "bitmap 8888: " + bitmap.getWidth() + "x" + bitmap.getHeight());


    //GrabCut part
    Mat img = new Mat();
    Utils.bitmapToMat(bitmap, img);
    Log.d(TAG, "img: " + img);

    int r = img.rows();
    int c = img.cols();

    Point p1 = new Point(c/10, r/10);
    Point p2 = new Point(c-c/10, r-r/10);
    Rect rect = new Rect(p1,p2);
    //Rect rect = new Rect(50,30, 100,200);
    Log.d(TAG, "rect: " + rect);

    Mat mask = new Mat();
    Mat fgdModel = new Mat();
    Mat bgdModel = new Mat();


    Mat imgC3 = new Mat();  
    Imgproc.cvtColor(img, imgC3, Imgproc.COLOR_RGBA2RGB);
    Log.d(TAG, "imgC3: " + imgC3);

    Log.d(TAG, "Grabcut begins");
    Imgproc.grabCut(imgC3, mask, rect, bgdModel, fgdModel, 2, Imgproc.GC_INIT_WITH_RECT);

    Core.convertScaleAbs(mask, mask, 100, 0);
    Imgproc.cvtColor(mask, mask, Imgproc.COLOR_GRAY2RGBA,4);
    Log.d(TAG, "maskC4: " + mask);

    //convert to Bitmap
    Log.d(TAG, "Convert to Bitmap");

    Utils.matToBitmap(mask, bitmap);


    iv.setImageBitmap(bitmap);
    Long endTime = System.currentTimeMillis();
    Long time=endTime-startTime;
    System.out.println("Time Is:"+time);
    //release MAT part
    img.release();
    imgC3.release();
    mask.release();
    fgdModel.release();
    bgdModel.release();