Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何一个接一个地处理Google Vision API,而不是在一个块中?_C#_Loops_Google Vision - Fatal编程技术网

C# 如何一个接一个地处理Google Vision API,而不是在一个块中?

C# 如何一个接一个地处理Google Vision API,而不是在一个块中?,c#,loops,google-vision,C#,Loops,Google Vision,我在使用Google Vision API时遇到了一个问题。 我正在循环这个过程,分析几张图片,但是当我打印结果时,经过5分钟的处理后,所有的结果都在一个块中出现,但是我想知道是否有可能启动程序,让它在每次图片分析后打印结果 以下是我的算法代码: bool space = false; // var image = Google.Cloud.Vision.V1.Image.FromFile("C:\\temp\\sequence\\n" + i + ".jpg");

我在使用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也不会更新,因为UI线程正忙于进行计算


同样地,在更新
textBox1.Text
后,您需要调用
textBox1.Refresh()
Application.DoEvents()
。Text经过5分钟的处理后,所有的代码都会进入一个块中哪一行代码需要5分钟?如果我取消对写入行的注释,则是textBox1.Text+=注释。Description;打印分数的那一行,都是在流程的最后打印出来的,看起来好多了!这接近我想要的,但足够了,非常感谢!非常感谢您的解释!成功了。