【问题标题】:How to do fast skin segmentation如何进行快速的皮肤分割
【发布时间】:2014-01-16 13:42:21
【问题描述】:

这是我为用手检测图像的肤色而实现的代码,但检查每张照片大约需要 5 分钟...有谁知道如何以更快的方式实现它?谢谢!

using (Bitmap SampleImage = (Bitmap)Image.FromFile (path)) { 
    for (int x = 0; x < SampleImage.Width; x++) {
        for (int y = 0; y < SampleImage.Height; y++) {
            Color pixelColor = SampleImage.GetPixel (x, y);
            int r = pixelColor.R;
            int g = pixelColor.G;
            int b = pixelColor.B;
            int differenceMinMax =
                Math.Max (r, Math.Max (g, b)) - Math.Min (r, Math.Min (g, b));

            if (r > 95 & g > 40 & b > 20 & differenceMinMax > 15 & r > g & r > b) {
                SampleImage.SetPixel (x, y, Color.White);
            } else if (r > 220 & g > 210 & b > 170) {
                SampleImage.SetPixel (x, y, Color.White);
            } else {
                SampleImage.SetPixel (x, y, Color.Black);
            }

            SampleImage.Save (path, System.Drawing.Imaging.ImageFormat.Jpeg); 
        }
    }
}

【问题讨论】:

标签: c# detection skin


【解决方案1】:
  1. 将 SampleImage.Save 移到循环之外。
  2. 内循环应按 X 坐标进行迭代。它减少了 CPU 缓存未命中的次数。
  3. 按照上面 cmets 中的建议,摆脱缓慢的 GetPixel 和 SetPixel 方法。
  4. 并行化内循环http://msdn.microsoft.com/en-us/library/dd783584(v=vs.110).aspx#fbid=IJmDXumNJjA

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 2019-04-27
    相关资源
    最近更新 更多