0

I got a problem when using the Google Vision API. I'm looping the process, to analyze several pictures, but when I print the results, all is coming in a block after 5 minutes of process, but I wanted to know if it's possible to start the program and make it print the results after each picture analyzis ?

Here's my code for the algorithm :

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;

I'm looping this with a foreach(Image file in Directory).

Any ideas to help me ?

Thanks a lot !

Kapuchon
  • 124
  • 2
  • 13
  • 1
    `all is coming in a block after 5 minutes of process` Which line of code is taking 5 minutes? – mjwills Aug 31 '17 at 12:33
  • If I uncomment the writing lines, it's the TextBox1.text += annotation.Description; and the line that prints the score, both are printed at the end of the process – Kapuchon Aug 31 '17 at 12:39
  • It looks much better ! It's close to what I want, but it's enough, thank you so much ! – Kapuchon Aug 31 '17 at 12:58

1 Answers1

1

Even though you update textBox1.Text, the UI will not update since the UI thread is busy doing the calculation.

As such, you need to call textBox1.Refresh() or Application.DoEvents() after updating textBox1.Text.

mjwills
  • 23,389
  • 6
  • 40
  • 63