Setting Area, finding Edges and adding Label

Hello Chris,
I am a little bit lost with upgrading to Cvb.net
Here is part of the code I wrote to find edges, set areas and add labels with my old AX Tools

BolLocated = (Cvb.Minos.Search.SearchOptimum(CLFRIGHTrightClassifier, axCVimage2.Image, 0, 1000, scanArea, out quality, out xPos, out yPos, out dX, out dY, out className));
            if (BolLocated)
            {
                if (ChkShowAllLabels.Checked == true)
                {
                    if (ChkLabelContents.Checked == true)
                    {
                        axCVdisplay2.AddLabel("RIGHTright", true, 255, 0, (int)xPos, (int)yPos);
                    }
                    else
                    {
                        axCVdisplay2.AddLabel("", true, 255, 0, (int)xPos, (int)yPos);
                    }
                }
                axCVimage2.OriginX = (int)xPos - 100;
                axCVimage2.OriginX = (int)yPos - 100;
                for (int i = 22; i < 27; i++)
                {
                    x0 = EdgesArray.arrayEdgeTool[i, 0];
                    x1 = EdgesArray.arrayEdgeTool[i, 2];
                    x2 = EdgesArray.arrayEdgeTool[i, 4];
                    y0 = EdgesArray.arrayEdgeTool[i, 1];
                    y1 = EdgesArray.arrayEdgeTool[i, 3];
                    y2 = EdgesArray.arrayEdgeTool[i, 5];
                    Cvb.Image.SetArea(x0, y0, x1, y1, x2, y2, out scanArea);

                    if (EdgesArray.arrayEdgeTool[i, 8] == 1)
                    {
                        BolLocated = Cvb.Edge.CSFindFirstEdge(axCVimage2.Image, 0, 1000, scanArea, EdgesArray.arrayEdgeTool[i, 6], Convert.ToBoolean(EdgesArray.arrayEdgeTool[i, 7]), out result);
                    }
                    else
                    {
                        BolLocated = Cvb.Edge.TSFindFirstEdge(axCVimage2.Image, 0, 1000, scanArea, EdgesArray.arrayEdgeTool[i, 6], Convert.ToBoolean(EdgesArray.arrayEdgeTool[i, 7]), out result);
                    }

                    if (BolLocated) /// if the edge is found then show labels
                    {
                        if (ChkShowAllLabels.Checked == true)
                        {
                            if (ChkLabelContents.Checked == true)
                            {
                                axCVdisplay2.AddLabel(Convert.ToString(i), true, 255, 0, (int)result.x, (int)result.y);
                            }
                            else
                            {
                                axCVdisplay2.AddLabel("", true, 255, 0, (int)result.x, (int)result.y);
                            }
                        }
                    }

I really can not find any tutorial about how to find edges, set areas or adding labels to my new Display.
Where can I learn it? is there any tutorial?
for example

 Cvb.Edge.CSFindFirstEdge(axCVimage.Image, 0, 1000, scanArea, EdgesArray.arrayEdgeTool[i, 6], Convert.ToBoolean(EdgesArray.arrayEdgeTool[i, 7]), out result);

What’s the equivalent for “axCVimage.Image” because if I change it for “Device” I have this error:
“Cannot convert from ‘Stemmer.Cvb.Device’ to 'Cvb.Image.IMG”

As you can see I am really really lost with this.
Our program, basically, needs:
1.- Set an area
2.- Find the edge
3.- Add a Label

Sorry to bother you Chris, if I can download the Cvb.Net tutorials for those 3 points I will study them. I need help
Thank you very very much again

Hi George,

there are a lot of examples here in the forum that show you how to add overlays to a Display, for example:

https://forum.commonvisionblox.com/t/how-to-add-overlay-objects-to-display-from-a-worker-thread-in-c/484/2

If you are not shure on how to use the Edge tool, try checking the documentation first:
https://help.commonvisionblox.com/NextGen/14.0/md_scripts_main__a_p_i__overview.html

This should be pretty straight forward.

Now, what you want to do is add another Display to show the resulting image, am I right?
If so, you have to have another displayControl or change the following line:

display.Image = value?.DeviceImage;

to not show the DeviceImage but the image you get from whatever processing you have done.

Your Edge Method call should look something like this:
FindFirst(ImagePlane, EdgeSearchMode, EdgeType, Double)

To explain you where the ImagePlane overload of the method comes from you have to take a look at the getting started once again, especially the part with the async processing:

https://forum.commonvisionblox.com/t/getting-started-with-cvb-net/246/10

Here is the interesting part:

private async void grabCheckBox_CheckedChanged(object sender, EventArgs e)
{
  if (grabCheckBox.Checked)
  {
    Device.Stream.Start();
    openButton.Enabled = false;
    try
    {
      while (grabCheckBox.Checked)
      {
        using (StreamImage image = await Device.Stream.WaitAsync())
        {
          // processing
        }
      }
    }
    catch (OperationCanceledException)
    {
      // acquisition was aborted
    }
    finally
    {
      openButton.Enabled = true;
    }
  }
  else
  {
    if (Device.Stream.IsRunning)
      Device.Stream.Abort();
  }
}

After you called the WaitAsync(), you have an image that you can use as argument for your edge tool, well not exactly the whole image but image.Planes[0] (for mono cameras) for RGB cameras just pass the index of the plane you want to use for processing.

I will also update my Example here
https://forum.commonvisionblox.com/t/getting-started-displaying-multiple-cameras/1508
To have another display that shows some image that is a result of some filter call or something like that.

For now I see, that you are making progress with the Forms approach so just stick with it but if you have time… just give my example a try.

Cheers
Chris

Thank you Chris, I will try it the whole day!
Thank you very much

1 Like

My dear Chris, I am completely stuck.
CVB had coding tutorials for all the AX Tools but unfortunately no tutorials for these new tools.
Please, may you write, if you have time, a code example? I am sure it will be useful to more people in the future. I even don’t know if I have to use a streamhandler for each display or not!

Imagine we have 2 monochrome cameras pointing to a cup of tea. One camera is pointing to the left side of the cup and the other is pointing to the handle. We have on our program 2 displays, one for each camera. I need on each display:

1.- Show a pre defined area of the image (area pre defined for me by (x0, x0, x1, y1, x2, y2)
2.- Find the edge on the selected area
3.- Put a label on that found edge

So finally we have 1 display showing the left image of the cup with my area and the found edge with a label on it and the other display showing the cup’s handle with the other pre defined area, the found edge and its label.

This code example, Chris, would be a great relief for me I am really worried about my decision of changing from AX tools to Cvb.net

Could you help me please? I mean PLEASE :pray:

Thank you very much again, and sorry if I am bothering you.
George

Hi @George

I am sorry but we cant do this.
I suggest you to contact your sales manager and get an offer for the application you need to be programmed by Stemmer.

We understand, that you dont always have the ressources and time to write your applications on your own. We have some great application engineers here that can build you whatever you need with the latest frameworks.

The forum here is for smaller problems and tips and trick, we cant provide you whole applications here unfortunately.

Thank you for your understanding

Cheers!
Chris

Hello Chris,
It’s a pity hearing that. Especially because we are a very good customers since 1999.
We are only asking for .net tutorials as Stemmer did with the old Ax tools to help their customers.
Those tutorials are not available for Cvb.net
I am not asking for an application, not at all, I am just asking for a foundation edge tutorial.
I will contact Stemmer on Monday.
Thank you Chris, you have been always kind. I just do not understand why Stemmer guys did not upgrade their tutorials to understand those Cvb.Net / Foundations tools
Kind regards

Hello @George

thank you for your feedback.
We would actually love to upgrade all those tutorials and there is also work in progress on this topic. Please be aware, our step towards the OOP wrappers was big one. Therefore it was not possible to provide all features or upgrade everything at once.
We will continue to work on a smooth user experience and aim to fill the gap we currently have.
Sorry for that.

Cheers

Andreas