我正在使用OpenCV库做一个Android移动应用程序,该库处理通过智能手机通过应用程序捕获的图像,它将处理该图像以检测肤色值(具有较高阈值和较低阈值)并使用边缘检测以在该颜色范围内绘制白线。到目前为止,只能检测肤色,但是我不知道如何提取RGB / HSV数字(如(255,255,255)或浮动HSV值)中的肤色值。这些值将与粉底液阴影进行比较,以获得哪些阴影最接近图像中的皮肤。我知道照明变量等,但仍想获取颜色的值。关于如何解决这个问题的任何想法?我已经导入了图书馆,他们开始工作了。输出将显示链接的面部轮廓线:
我尝试使用getDominantSwatch的getRGB的Android.Palette。该值不正确。我希望任何专家都能对此发表意见,因为我只是OpenCV的新手,但我很想学习。 OpenCV代码示例如下,输出示例:
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.imgcodecs.*;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK) {
Bitmap myBitmap = BitmapFactory.decodeFile(currentImagePath);
imageView.setImageBitmap(myBitmap);
//until here works and tested
Utils.bitmapToMat(myBitmap, mRgbMat);
Imgproc.cvtColor(mRgbMat, mHsvMat, Imgproc.COLOR_RGB2HSV, channelCount);
Scalar lowerThreshold = new Scalar(0, 48, 80); // lower hsv values
Scalar upperThreshold = new Scalar(20, 255, 255); // higher hsv values
Core.inRange(mHsvMat, lowerThreshold, upperThreshold, mMaskMat);
Imgproc.dilate(mMaskMat, mDilatedMat, new Mat());
//Scalar used = new Scalar(Core.inRange(mHsvMat, lowerThreshold, upperThreshold, mMaskMat));
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() + " used colour: " + mHsvMat );
// 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!
imageView2.setImageBitmap(bm);
}