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(目录中的图像文件)循环这一点。
任何想法帮助我?
非常感谢!
'进程5分钟后全部进入块'哪一行代码需要5分钟? – mjwills
如果我取消注释写作行,它是TextBox1.text + = annotation.Description; 和打印分数的行,都在过程结束时打印 –
看起来好多了! 它接近我想要的,但它已经足够了,非常感谢你! –