【问题标题】:How to process Google Vision API one by one and not in a block? [duplicate]如何逐个处理Google Vision API而不是一个块? [复制]
【发布时间】:2018-02-09 09:50:08
【问题描述】:

我在使用 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(目录中的图像文件)循环这个。

有什么想法可以帮助我吗?

非常感谢!

【问题讨论】:

  • all is coming in a block after 5 minutes of process 哪一行代码需要 5 分钟?
  • 如果我取消注释书写行,它是 TextBox1.text += annotation.Description;和打印分数的行,都在进程结束时打印
  • 看起来好多了!已经接近我想要的了,但已经足够了,非常感谢!

标签: c# loops google-vision


【解决方案1】:

即使您更新textBox1.Text,UI 也不会update,因为 UI 线程正忙于进行计算。

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

【讨论】:

  • 非常感谢您的解释!那行得通。
猜你喜欢
  • 2017-10-01
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 2020-03-28
  • 1970-01-01
  • 2016-09-17
  • 2018-05-14
  • 1970-01-01
相关资源
最近更新 更多