2017-08-31 35 views
0

使用Google Vision API時出現問題。 我正在循環這個過程,分析幾張圖片,但是當我打印結果時,所有進程在5分鐘後都進入一個塊,但我想知道是否可以啓動程序並使其打印結果每個圖片分析後?如何逐一處理Google Vision API而不是在一個區塊中處理?

這裏是我的算法代碼:

bool space = false; 
     // var image = Google.Cloud.Vision.V1.Image.FromFile("C:\\temp\\sequence\\n" + i + ".jpg"); 
      var image = Google.Cloud.Vision.V1.Image.FromFile(path); 
      var client = ImageAnnotatorClient.Create(); 
      var response = client.DetectLabels(image); 
      CropHintsAnnotation confidence = client.DetectCropHints(image); 

     bool car = false; 
     bool vehicle = false; 
     bool land = false; 
     int score = 0; 
     //System.IO.Directory 

     foreach (var annotation in response) 
     { 
      textBox1.Text += annotation.Description + "\r\n"; 
      textBox1.Text += "Score : " + annotation.Score + "\r\n"; 
      vehicle = !annotation.Description.Equals("vehicle"); 
      car = !annotation.Description.Equals("car"); 
      land = !annotation.Description.Equals("land vehicle"); 

      if (car == false) 
      { 
       score += 1; 
       //textBox1.Text += "\r\nEmpty ?  " + car + "\r\n\r\n"; 
      } 
      else if (vehicle == false) 
      { 
       score += 1; 
       //textBox1.Text += "\r\nEmpty ?  " + vehicle + "\r\n\r\n"; 
      } 
      else if (land == false) 
      { 
       score += 1; 
       //textBox1.Text += "\r\nEmpty ?  " + land + "\r\n\r\n"; 
      } 
      else if (annotation.Description.Equals("asphalt")) 
      { 
       score += -20; 
       //textBox1.Text += "\r\nEmpty ? True \r\n\r\n"; 
      } 
      else 
      { 
       score += 0; 
      } 
     } 
     if (score > 0) 
     { 
      //textBox1.Text += "The parking space is taken \r\n\r\n"; 
      space = true; 
     } 
     else 
     { 
      //textBox1.Text += "The parking space is empty \r\n\r\n"; 
      space = false; 
     } 
     return space; 

我有一個foreach(目錄中的圖像文件)循環這一點。

任何想法幫助我?

非常感謝!

+1

'進程5分鐘後全部進入塊'哪一行代碼需要5分鐘? – mjwills

+0

如果我取消註釋寫作行,它是TextBox1.text + = annotation.Description; 和打印分數的行,都在過程結束時打印 –

+0

看起來好多了! 它接近我想要的,但它已經足夠了,非常感謝你! –

回答

1

即使您更新textBox1.Text,UI將不會update,因爲UI線程忙於計算。

因此,您需要在更新textBox1.Text後致電textBox1.Refresh()Application.DoEvents()

+0

非常感謝您的解釋!這工作。 –

相關問題