Ask Your Question

ichaka's profile - activity

2015-07-03 11:44:46 -0600 asked a question What should I do to do convexity defect OpenCV in Android ?

Hello. I'm beginner in android development and newbie in OpenCV too. I have project about hand gesture recognition in Android. I want to do convexity defect on it. Before I do convexity defect, I should have done finding contour and convex hull. I have done them already. Now, I'm doing convexity defect to get defect of the hand and fingers. But there is something wrong. When I build my code with convexity defect in my Android, It's unfortunately stopped. I don't know whether my convexity defect function is wrong, or the way I get value of defect (MatOfInt4) to Point is wrong. Somebody, please help me. Thank you. This is my code :

   List<MatOfInt> hull = new ArrayList<MatOfInt>();
   List<MatOfInt4> defect = new ArrayList<MatOfInt4>();
   for(int i = 0; i < newContours.size(); i++)
        {
            hull.add(new MatOfInt());
            Imgproc.convexHull(newContours.get(i), hull.get(i));
            Imgproc.convexityDefects(newContours.get(i), hull.get(i), defect.get(i));
        }

        Point defectSP= new Point();
        Point defectEP= new Point();
        Point defectFP= new Point();
        for(int i = 0; i < defect.size(); i++)
        {
            Point[] startP = new Point[newContours.get(i).rows()];
            Point[] endP = new Point[newContours.get(i).rows()];
            Point[] farP = new Point[newContours.get(i).rows()];
            Point[] depthP = new Point[newContours.get(i).rows()];

            for(int j = 0; j < defect.get(i).rows(); j++)
            {
                int distP = (int) defect.get(i).get(j, 3)[3];
                if (distP > 20*256)
                {
                    startId = (int) defect.get(i).get(j, 0)[0];
                    endId = (int) defect.get(i).get(j, 1)[1];
                    farId = (int) defect.get(i).get(j, 2)[2];

                    defectSP.x = startId;
                    defectSP.y = startId;
                    defectEP.x = endId;
                    defectEP.y = endId;
                    defectFP.x = farId;
                    defectFP.y = farId;
                }
             }
         }
2015-06-15 01:07:04 -0600 asked a question How do I draw Convexity Defect using OpenCV Android ???

I'm doing my final project about hand gesture recognition using OpenCV in Android. So far I did until Convex Hull. Now, I want to draw convexity defect on it and get the defect value from it. But I am stack. I found some references codes, but most of it written in C++ code. I have no idea how to convert them into Java android code. Anyone, Would you mind to help me by convert this code? this is the C++ code :

/// Draw convexityDefects
for( int i = 0; i< contours.size(); i++ )
{
size_t count = contours[i].size();
if( count <300 )
continue;

vector<Vec4i>::iterator d=convdefect[i].begin();
while( d!=convdefect[i].end() ) {
Vec4i& v=(*d);
int startidx=v[0]; Point ptStart( contours[i][startidx] );
int endidx=v[1]; Point ptEnd( contours[i][endidx] );
int faridx=v[2]; Point ptFar( contours[i][faridx] );
float depth = v[3] / 256;

line( drawing, ptStart, ptEnd, Scalar(0,255,0), 1 );
line( drawing, ptStart, ptFar, Scalar(0,255,0), 1 );
line( drawing, ptEnd, ptFar, Scalar(0,255,0), 1 );
circle( drawing, ptFar,   4, Scalar(0,255,0), 2 );
d++;
}
}

I would be glad if you can solve this for me, because it's for my final project. Thanks a lot.

2015-06-10 01:57:28 -0600 received badge  Enthusiast
2015-06-04 01:25:47 -0600 asked a question How to get the right Cr and Cb (YCrCb) values from RGB real time image from android camera using OpenCV?

I am doing my final project about image processing in android. In my project I want to pick YCrCb color through the android camera (rgb image) using OpenCV, and get the value of Cr low, Cr high, Cb low also Cb high. It can happen when i pressed a button, so i do my code inside it. Firstly, I convert rgb image to YCrCb color, then find Cr and Cb value by array. It works out. But, there is a wrong output. When i used "Imgproc.COLOR_RGB2YCrCb" Cr high value always be 254 (maximum), even if i did in another color sample to be picked. Then, when i used "Imgproc.COLOR_BGR2YCrCb", Cb high value always 254. But actually, it should give another value. So, what should i do to fix this problem? I just want it could pick color and give the right value as same as the sample color that is picked. Thanks, and this is my code.

public boolean getSkin(View view) {
getSkin = true;
Imgproc.cvtColor(rect_ROI, rect_ROI, Imgproc.COLOR_BGR2YCrCb);

Cr_low = 255;
Cr_high = 0;
Cb_low = 255;
Cb_high = 0;

for (int x = 0; x < rect_ROI.rows(); x++) 
{
    for (int y = 0; y < rect_ROI.cols(); y++)
    {
        double[] array_value = rect_ROI.get(x, y);

        if (Cr_low > array_value[1]) Cr_low = (int) array_value[1] ;
        if (Cr_high < array_value[1]) Cr_high = (int) array_value[1];
        if (Cb_low > array_value[2]) Cb_low = (int) array_value[2];
        if (Cb_high < array_value[2]) Cb_high = (int) array_value[2];
    }       
}

if (Cr_high > Cr_low + 10) Cr_high = Cr_high - 1;
if (Cb_high > Cb_low + 10) Cb_high = Cb_high - 1;
Cr_low += 1;
Cb_low += 1; 

TextView Crl = (TextView) findViewById(R.id.cr_low);
TextView Crh = (TextView) findViewById(R.id.cr_high);
TextView Cbl = (TextView) findViewById(R.id.cb_low);
TextView Cbh = (TextView) findViewById(R.id.cb_high);

Crl.setText(""+Cr_low);
Crh.setText(""+Cr_high);
Cbl.setText(""+Cb_low);
Cbh.setText(""+Cb_high);

return getSkin;
 }
2015-05-07 00:17:14 -0600 received badge  Editor (source)
2015-05-07 00:15:56 -0600 asked a question Why I can't do threshold opencv for skin segmentation provementin my android project ?

I am doing final project about hand gesture recognition real time using android and opencv. I'm doing skin segmentation on it, by convert picture from camera frame (RGB) to YCrCb color and get the Cr and Cb value (range) from rectangle that is directed to skin color (seems like color picker). Now, i want to prove it (skin segmentation) by using thresholding function through option menu button on my android phone. But, it's not work, no effect. What should I do ? This is my threshold code :

   case MainActivity.VIEW_MODE_THRES:
        mask = rgba.clone();
        rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);

        Imgproc.cvtColor(rgbaInnerWindow, rgbaInnerWindow, Imgproc.COLOR_BGR2YCrCb);
        Imgproc.cvtColor(mask, mask, Imgproc.COLOR_BGR2GRAY);

        Core.inRange(rgbaInnerWindow, new Scalar(0, Cr_low, Cb_low), new Scalar (255, Cr_high, Cb_high), mask);

        image = mask.clone(); //save the image segmentation output
        Imgproc.blur(mask, mask, new Size(5,5));

        Imgproc.threshold(mask, mask, 13, 255, Imgproc.THRESH_OTSU);
        Core.inRange(mask, new Scalar(30), new Scalar(255), mask); rgbaInnerWindow.release();
        mask.release();
        break;