使用opencv在android中获取肤色轮廓区域

使用opencv在android中获取肤色轮廓区域,android,opencv4android,hsv,opencv-contour,opencv-drawcontour,Android,Opencv4android,Hsv,Opencv Contour,Opencv Drawcontour,下面是我运行以查找面区域的代码 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, mH

下面是我运行以查找面区域的代码

 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_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    Imgproc.drawContours(mRgbMat, contours,counter, colorGreen, iLineThickness);
    Log.d(TAG + " contours " , contours.get(counter).toString());

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

    // find the imageview and draw it!
    imageView.setImageBitmap(bm);
}
然而,我得到了太多我不想要的区域。 这是我手动查找的所需区域(绿色区域)。我在单击按钮时添加值,并在按下按钮时绘制不同的区域

这是logcat中显示的消息

02-16 00:11:46.413 14234-14234/fyp.hkust.facet D/ColorizeFaceActivity等高线:Mat[932*1*cv32sc2,isCont=true,isSubmat=false,nativeObj=0xffffffff96aa78f8,dataAddr=0xffffffff96a57010]

我也试着把它们都画出来,但是有太多额外的区域我不想要

    for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
        if (contours.size() > 100)  // Minimum size allowed for consideration
        {
            Imgproc.drawContours(mRgbMat, contours, contourIdx, colorGreen, iLineThickness);
            Log.d(TAG + " contours " , contours.get(contourIdx).toString());
        }
    }
for(int-contourIdx=0;contourIdx100)//允许考虑的最小尺寸
{
Imgproc.drawContours(mRgbMat、contours、contourIdx、彩绿、iLineThickness);
Log.d(标记+“轮廓”,轮廓.get(轮廓idx.toString());
}
}
这就是全部结果

如何对它们进行分类以获得面部区域,同时我还需要提取该区域的hsv值。我该怎么做?请给我一些帮助。多谢各位