Ask Your Question

Clementf2b's profile - activity

2020-11-05 12:53:13 -0600 received badge  Popular Question (source)
2017-02-16 08:08:49 -0600 commented question detect HSV color for skin color and extract the color in that region

@StevenPuttemans Thank you for your reply. You mean that I should set the range closer? Yes. If people contain brown hair, it would affect my result. Do you know how to extract the HSV color from that region?

2017-02-16 00:56:59 -0600 asked a question detect HSV color for skin color and extract the color in that region

The following is the code that I run to find the face region

private Mat mRgbMat;
private Mat mHsvMat;
private Mat mMaskMat;
private int channelCount = 3;
private Mat mDilatedMat;
private List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

private Mat hierarchy;
private int iLineThickness = 5;
private Scalar colorGreen = new Scalar(0, 255, 0);
private static double mMinContourArea = 0.3;
private List<MatOfPoint> mMaxContours = new ArrayList<MatOfPoint>();

private void detectRegion() {

    //get the image from gallery and change it into bitmap
    Bitmap bmpTemp = originalImg.copy(Bitmap.Config.ARGB_8888, true);
    Utils.bitmapToMat(bmpTemp, mRgbMat);
    Imgproc.cvtColor(mRgbMat, mHsvMat, Imgproc.COLOR_RGB2HSV, channelCount);

    Scalar lowerThreshold = new Scalar(0, 0.23 * 255, 50); // Blue color – lower hsv values
    Scalar upperThreshold = new Scalar(50, 0.68 * 255, 255); // Blue color – higher hsv values
    Core.inRange(mHsvMat, lowerThreshold, upperThreshold, mMaskMat);
    Imgproc.dilate(mMaskMat, mDilatedMat, new Mat());

    Imgproc.findContours(mMaskMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    // Find max contour area
    double maxArea = 0;
    Iterator<MatOfPoint> each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint wrapper = each.next();
        double area = Imgproc.contourArea(wrapper);
        if (area > maxArea)
            maxArea = area;
    }

    // Filter contours by area and resize to fit the original image size
    mMaxContours.clear();
    each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint contour = each.next();
        if (Imgproc.contourArea(contour) > mMinContourArea*maxArea) {
            mMaxContours.add(contour);
        }
    }

    Imgproc.drawContours(mRgbMat, mMaxContours,0, colorGreen, iLineThickness);
    Log.d(TAG + " contours" ,  contours.size() + "" );

    // convert to bitmap:
    Bitmap bm = Bitmap.createBitmap(mRgbMat.cols(), mRgbMat.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mRgbMat, bm);

    // find the imageview and draw it!
    imageView.setImageBitmap(bm);
}

Result of the above code:

please add https:// because I cannot post link. Thank you s11.postimg.org/myaf9fb4z/photo_2017_02_16_14_43_34.jpg

Although I can get a good result using the above function, I may not get the result that I want if there are some extra elements that contains a close value of the color like the following image.

please add https:// because I cannot post link. Thank you s27.postimg.org/gy04nnwzn/photo_2017_02_16_14_49_57.jpg

How do I change my code to fit this situation? Also I need to change the HSV value in this region. How can I get the HSV value in that region? Please give me some helps. Thank you very much.

2017-01-25 20:11:50 -0600 commented question OpenCV in c++ to java

This is the part that I have done. I am still working it but I dun know the part of iterator, the size_t and the pt[2] = Point2f(t[4], t[5 ]);. How to work it in java? Thanks.

2017-01-25 20:09:55 -0600 received badge  Editor (source)
2017-01-23 08:06:33 -0600 commented question OpenCV in c++ to java

preshap I place my translation of code to let you guys to give me some suggestions?

2017-01-23 03:34:59 -0600 commented question OpenCV in c++ to java

I knew but I dun know how does it work so I translate it to java

2017-01-23 03:34:10 -0600 received badge  Enthusiast
2017-01-22 07:19:31 -0600 asked a question OpenCV in c++ to java
static void calculateDelaunayTriangles(Rect rect, vector<Point2f> &points, vector< vector<int> > &delaunayTri){

Subdiv2D subdiv(rect);

for( vector<Point2f>::iterator it = points.begin(); it != points.end(); it++)
    subdiv.insert(*it);         

vector<Vec6f> triangleList;
subdiv.getTriangleList(triangleList);
vector<Point2f> pt(3);
vector<int> ind(3);

for( size_t i = 0; i < triangleList.size(); i++ )
{
Vec6f t = triangleList[i];
pt[0] = Point2f(t[0], t[1]);
pt[1] = Point2f(t[2], t[3]);
pt[2] = Point2f(t[4], t[5 ]);

if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
    for(int j = 0; j < 3; j++)
        for(size_t k = 0; k < points.size(); k++)
            if(abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)                      
                ind[j] = k;                 

    delaunayTri.push_back(ind);
}
}

 }

I would like to use this function which builds from opencv but this function is C++ function. I want to convert it to java and use it in android. I am a beginner in c++ and I dun know how to convert them. Can anyone help me to convert it? Thank you very much.

This is the part that I have done. I am still working it.

 static void calculateDelaunayTriangles(org.opencv.core.Rect rect, Vector<org.opencv.core.Point> points,       Vector<Vector<Integer> > delaunayTri){

 // Create an instance of Subdiv2D
    Subdiv2D subdiv = new Subdiv2D(rect);

    // Insert points into subdiv
    for(int i = 0;i < points.size();i++)
    subdiv.insert(points.get(i));

    MatOfFloat6 triangleList = null;
    subdiv.getTriangleList(triangleList);
    Vector<MatOfPoint2f> pt = new Vector<>(3);
    MatOfInt ind = new MatOfInt(3);

   for( int i = 0; i < triangleList.size(); i++ )
   {
   MatOfFloat6 t = triangleList[i];
   pt[0] = new Vector<MatOfPoint2f>(t[0], t[1]);
   pt[1] = new Vector<MatOfPoint2f>(t[2], t[3]);
   pt[2] = new Vector<MatOfPoint2f>(t[4], t[5 ]);

   if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])){
       for(int j = 0; j < 3; j++)
           for(int k = 0; k < points.size(); k++)
               if(Math.abs(pt[j].x - points[k].x) < 1.0 && abs(pt[j].y - points[k].y) < 1)
                   ind[j] = k;

       delaunayTri.push_back(ind);
   }
  }

  }
2016-08-08 00:56:22 -0600 asked a question Using opencv c++ code in android studio

I want to use the following automatic white balance function

http://docs.opencv.org/3.0-last-rst/m...

But I am new to android and I don't know how to convert it to use in the android studio. Can anyone help me to solve this problem? Thank You.