2

我想通過提取檢測到的並行面來加速Viola-Jones,我使用此代碼,但For Each語句中的face argument有錯誤,您能否告訴我如何解決這個錯誤請? 誤差如何在Viola-Jones中編寫Parallel ForEach

(錯誤2方法System.Threading.Tasks.Parallel.ForEach<TSource>(System.Collections.Concurrent.OrderablePartitioner<TSource>, System.Action<TSource,System.Threading.Tasks.ParallelLoopState,long>)類型參數不能從使用推斷嘗試顯式指定類型參數
d:\ Hadeel \ 00論文\人臉識別\ C#\備份\ Viola和Jones結果
2 - 複製\ Viola和Jones結果2個\ Form1.cs的356 25
Viola和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 
+0

什麼類型是'face'和'faceObjects'? – meJustAndrew

回答

0

這是很難說的當然,但你是否試圖將face對象標記爲lambda參數?那麼你需要切換參數:

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

非常感謝,是的,我做到了,但任何方式都不行,平行是不可能的,因爲我在想。 –

+0

@HiraqiHmaster「不工作」是什麼意思? – VMAtm

+0

我的意思是,我不能在中提琴瓊斯代碼中進行並行處理,我只是想讓它更快地進行實時人臉檢測,但不能做到這一點 –

相關問題