Ask Your Question

life Evader's profile - activity

2015-12-10 04:28:51 -0600 received badge  Enthusiast
2015-12-09 05:15:36 -0600 commented question Converting C++ code to java

wow so you cannot just explain the whole thing for me? we ask questions because we tried and it did not go so well, there are very very few android tutorials/java based on OpenCV most of them are C++ , C# and python, I have been struggling with this for the past 3 weeks, I have just showed you all what I have done based on the C++ code I earlier posted for help, all help I needed was the meaning of this vector<point> contours; vector<point> convexHull_pts; Why Canny in java has 4 parameter and what I should do to the extra parameter in my case, I expected better response from here than starckoverflow so much for being the official opencv forum if all you tell people in need is to go read a bunch of books even when they have clearly showed you they tried.

2015-12-09 04:49:44 -0600 commented question Converting C++ code to java

I have looked at the documentation that is why I pointed out that in java Canny only has 4 parameters and besides and a new user I cannot just learn everything by reading 2 documentations at a go, am learning slowly, that is not the complete code, I have done most of the work its only this that is really puzzling me

2015-12-09 01:46:21 -0600 asked a question Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );
vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

I tried Converting it based on my knowledge and here is what I got:

     Mat src= new Mat();
    Utils.bitmapToMat(bitmap, src);
    Mat original = src.clone();
    Mat gray = new Mat();
    Mat mask = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.blur(gray, gray, new Size(3, 3));

    Imgproc.Canny(gray, mask, 100, 300, 3);

    MatOfPoint contours = new MatOfPoint(); // i am not sure how to initialize MatOfPoint ( blind suggestion )
    MatOfPoint convexHull_pts = new MatOfPoint();

    Core.findNonZero(mask, contours);
    Imgproc.convexHull(contours, convexHull_pts);
    Imgproc.fillConvexPoly(mask, convexHull_pts, Imgproc.Scalar(255));
2015-12-07 19:34:13 -0600 received badge  Student (source)
2015-12-07 12:52:10 -0600 received badge  Editor (source)
2015-12-07 12:49:04 -0600 asked a question Edge refinement OpenCV android

ok so I am a newbie to opencv, I have manage to perform a grabcut which seems "ok" to me except the edges are pretty out of shape, I want to get realistic edges, maybe blur the edges out to get a perfectly done image, another thing I have noticed is the colors tend to be too bright after the entire process I wanted to reduce the vibrancy to somewhat acceptable below is my code

private Bitmap backGrndErase()
{

    color = new Scalar(255, 0, 0, 255);
    dst = new Mat();
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.myshirt);
    Log.d(TAG, "bitmap: " + bitmap.getWidth() + "x" + bitmap.getHeight());


    bitmap = ResizeImage.getResizedBitmap(bitmap, calculatePercentage(40, bitmap.getWidth()), calculatePercentage(40, bitmap.getHeight()));



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



    Mat img = new Mat();
    Utils.bitmapToMat(bitmap, img);


    Point p1 = new Point((img.cols()/10), (img.rows()/10));
    Point p2 = new Point((img.cols()-img.cols()/10), (img.rows()-img.rows()/10));
    Rect rect = new Rect(p1,p2);

    int border = 20;
    int border2 = border + border;
    Rect rect2 = new Rect( border, border, img.cols() - border2, img.rows()-border2);




    Mat mask = new Mat();
    debugger(""+mask.type());
    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, rect2, bgdModel, fgdModel, 2, Imgproc.GC_INIT_WITH_RECT);
    Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
    //Do Sth
    Core.compare(mask, source, mask, Core.CMP_EQ);
    //Do Sth
    Mat foreground = new Mat(img.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
    img.copyTo(foreground, mask);
    Imgproc.rectangle(img, p1, p2, color);

    Mat background = new Mat();
    try {
        background = Utils.loadResource(getApplicationContext(),
                R.drawable.blackcolor );
    } catch (IOException e) {

        e.printStackTrace();
    }
    Mat tmp = new Mat();
    Imgproc.resize(background, tmp, img.size());

    background = tmp;

    Mat tempMask = new Mat(foreground.size(), CvType.CV_8UC1, new Scalar(255, 255, 255));
    Imgproc.cvtColor(foreground, tempMask, 6/* COLOR_BGR2GRAY */);


    Mat vals = new Mat(1, 1, CvType.CV_8UC3, new Scalar(0.0));
    dst = new Mat();
    background.setTo(vals, tempMask);
    Imgproc.resize(foreground, tmp, mask.size());
    foreground = tmp;
    Core.add(background, foreground, dst, tempMask);
    Log.d(TAG, "Convert to Bitmap");


    //removing blackbaground started

     Mat tmp2 = new Mat();
     Mat alpha = new Mat();
     Imgproc.cvtColor(dst, tmp2, Imgproc.COLOR_BGR2GRAY);
     Imgproc.threshold(tmp2, alpha, 100, 255, Imgproc.THRESH_BINARY);


     List<Mat> rgb = new ArrayList<Mat>(3);
     Core.split(dst, rgb);


     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);
     Bitmap output = Bitmap.createBitmap(dst.width(), dst.height(), Bitmap.Config.ARGB_8888);
     Utils.matToBitmap(dst, output);

    //removing back ended


    Utils.matToBitmap(dst, bitmap);



    //release MAT part
    img.release();
    imgC3.release();
    mask.release();
    fgdModel.release();
    bgdModel.release();
    alreadyRun = true;
    return  bitmap;

}

and the intput looks like this:

image description

and the ... (more)

2015-12-06 18:31:01 -0600 answered a question It can be used for commercial purposes grabcut? surf and sift algorithm is being used to grabcut?

it is being used by companies in creating vision oriented systems

2015-12-05 03:42:26 -0600 asked a question Removing background from Image

Ok so I am newbie in openCv, I am working on an Android App that requires a user to remove Image background using OpenCV, I could have used other libraries if there were many good ones out there but the community has advised me to stick to OpenCV for great performance, I have been reading the opencv documentation and to be honest I do not see myself accomplishing my task, there are very few Android tutorials out there on OpenCV Android so it is really hard for me to pick up the idea, if anyone has attempted Image background removal using OpenCV please help or better share your code and a little explanation on how it works, thank you in advance.