如何处理 Google Vision API 一个一个而不是一个块?
How to process Google Vision API one by one and not in a block?
我在使用 Google Vision API 时遇到问题。
我正在循环这个过程,分析几张图片,但是当我打印结果时,经过 5 分钟的过程,所有的都在一个块中,但我想知道是否可以启动程序并让它在之后打印结果每张图片分析?
这是我的算法代码:
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(目录中的图像文件)进行循环。
有什么想法可以帮助我吗?
非常感谢!
即使您更新 textBox1.Text
,UI 也不会 update,因为 UI 线程正忙于计算。
因此,您需要在更新 textBox1.Text
后调用 textBox1.Refresh()
或 Application.DoEvents()
。
我在使用 Google Vision API 时遇到问题。 我正在循环这个过程,分析几张图片,但是当我打印结果时,经过 5 分钟的过程,所有的都在一个块中,但我想知道是否可以启动程序并让它在之后打印结果每张图片分析?
这是我的算法代码:
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(目录中的图像文件)进行循环。
有什么想法可以帮助我吗?
非常感谢!
即使您更新 textBox1.Text
,UI 也不会 update,因为 UI 线程正忙于计算。
因此,您需要在更新 textBox1.Text
后调用 textBox1.Refresh()
或 Application.DoEvents()
。