【问题标题】:How to write Parallel ForEach in Viola-Jones如何在 Viola-Jones 中编写 Parallel ForEach
【发布时间】:2017-04-04 06:25:47
【问题描述】:

我想通过并行提取检测到的人脸来加速 Viola-Jones,我使用了这段代码,但是 For Each 语句中的人脸参数有一个错误,你能告诉我如何解决这个错误吗? 错误是

(错误 2 无法从用法中推断出方法 System.Threading.Tasks.Parallel.ForEach<TSource>(System.Collections.Concurrent.OrderablePartitioner<TSource>, System.Action<TSource,System.Threading.Tasks.ParallelLoopState,long>) 的类型参数。尝试显式指定类型参数。
D:\Hadeel\00 论文\人脸识别\C#\Backup\Viola and Jones Results
2 - 复制\Viola 和 Jones 结果 2\Form1.cs 356 25
Viola and Jones 结果 2)

else if (chcParallel.Checked == true)
{//Rectangle face=new Rectangle();
    Parallel.ForEach(  face, faceObjects =>
    {
        graphicRect.DrawRectangle(p, face);
        face.Inflate(-10, -10);// resize face for crop face without background

        Crop crop = new Crop(face);

        Bitmap newimage = crop.Apply(image);

        // ResizeBicubic resixe = new ResizeBicubic(460, 480);
        //newimage = resixe.Apply(newimage);
        //pictureBox2.Image = (newimage); 
        if (chcSkin.Checked == false)
        {
            facearray[i] = newimage;
            pictureBox2.Image = facearray[i];
            i = i + 1;
        }
        else if (chcSkin.Checked == true)
        {
            f1 = 0; f2 = 0; f3 = 0;
            Bitmap imagess = new Bitmap(newimage);
            for (int x = 0; x < imagess.Width - 1; x++)
            {
                for (int y = 0; y < imagess.Height - 1; y++)
                {
                    Color pixelColor = imagess.GetPixel(x, y);
                    int r = pixelColor.R;
                    int g = pixelColor.G;
                    int b = pixelColor.B;
                    //        int f1 = 0;
                    //        int f2 = 0;
                    //        int f3 = 0;
                    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)
                    {
                        f1 = f1 + 1;// image.SetPixel(x, y, Color.White);
                    }
                    else if (r > 220 & g > 210 & b > 170)
                    {
                        f2 = f2 + 1;// imagess.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        f3 = f3 + 1;// imagess.SetPixel(x, y, Color.White);
                    }
                }
            }
            if ((f1 > f2) && (f1 > f3))
            {
                facearray[i] = newimage;
                pictureBox2.Image = facearray[i];
                i = i + 1;
            }
        }
        //else
        //{ }
    });

    graphicRect.Dispose();
    pictureBox1.Image = image;
}//end if Parallel True 

【问题讨论】:

  • facefaceObjects 是什么类型?

标签: c# multithreading parallel-processing parallel.foreach viola-jones


【解决方案1】:

很难确定,但您是否尝试将 face 对象标记为 lambda 参数?然后需要切换参数:

// for each of faceObject do
Parallel.ForEach(faceObjects, face =>
{
    // your code here
});

【讨论】:

  • 非常感谢,是的,我做到了,但无论如何它是行不通的,我认为并行是不可能的。
  • 我的意思是,我无法在 viola jones 代码中进行并行处理,我只是想让它更快地进行实时人脸检测,但做不到
猜你喜欢
  • 2017-06-13
  • 2016-01-20
  • 2013-11-27
  • 2014-06-03
  • 2012-04-27
  • 2013-12-12
  • 1970-01-01
  • 2016-12-23
  • 2013-12-01
相关资源
最近更新 更多