【halcon】Tips, Union1 can save time

background:

        When using halcon, modify the following steps and find that the time-consuming surges by 2 seconds.

The definition to the key code is as follows:

//再和之前的选择区域取交集
HOperatorSet.Intersection(SelectedRegions0, SelectedRegions, out ho_CutLineRegion);

DebugShow(ho_CutLineRegion, "red", false, false);

It is found that the DebugShow function is time-consuming, but it was not found to be time-consuming before. It's just a display.

public void DebugShow(HObject targetRegions, string color = "red", bool bmargin = false, bool bStop = true)
{
    if (bmargin)
    {
        HOperatorSet.SetDraw(hSmart.HalconWindow, "margin");
    }
    else
    {
        HOperatorSet.SetDraw(hSmart.HalconWindow, "fill");
    }
    HOperatorSet.SetColor(hSmart?.HalconWindow, color);
    hSmart?.HalconWindow.DispObj(targetRegions);

    if (bStop)
    { 
        MessageBox.Show("");
    }
}

Finally, it was found that it was time-consuming to display because the variable ho_CutLineRegion contained hundreds of objects.

So I modified the code as follows (join ho_CutLineRegion and then display):

//再和之前的选择区域取交集
HOperatorSet.Intersection(SelectedRegions0, SelectedRegions, out ho_CutLineRegion);

//Unionl之后,不管是显示,而是其他操作,会更加节省时间!
HOperatorSet.Union1(ho_CutLineRegion, out ho_CutLineRegion);

DebugShow(ho_CutLineRegion, "red", false, false);

The surge of 2 seconds is gone!

Later, I found that not only the display, but also other operations, such as area subtraction, choosing Union1 will also save time!

Guess you like

Origin blog.csdn.net/songhuangong123/article/details/130292928