Halcon实战记录之一《划分图像区域为中心,四边,四角》

在做图像处理的时候,我们有时候对图像的不同区域的处理方式不一样,我这里写下我最近使用的方法,将一副图像分成三个区域–中心,四边,四角,如下图:

Halcon实战记录之一《划分图像区域为中心,四边,四角》_第1张图片

边的最小宽度和高度占图像的比例为Ratio,例如Rato等于0.1,即中心占图像的0.8的比例。

1、获取中心区域:

void GetImageRegion_Center (HObject *ho_Region, HTuple hv_imWidth, HTuple hv_imHeight, HTuple hv_Ratio)
{
    GenRectangle1(&(*ho_Region), hv_imHeight*hv_Ratio, hv_imWidth*hv_Ratio, (hv_imHeight*(1-hv_Ratio))-1, (hv_imWidth*(1-hv_Ratio))-1);
}

2、获取四边区域:

void GetImageRegion_Side (HObject *ho_Region, HTuple hv_imWidth, HTuple hv_imHeight, HTuple hv_Ratio)
{
    // Local iconic variables
    HObject  ho_Rectangle_top, ho_Rectangle_bot, ho_Rectangle_lft;
    HObject  ho_Rectangle_rgt, ho_ObjectsConcat;
    //top
    GenRectangle1(&ho_Rectangle_top, 0, hv_imWidth*hv_Ratio, (hv_imHeight*hv_Ratio)-1, (hv_imWidth*(1-hv_Ratio))-1);
    //bottom
    GenRectangle1(&ho_Rectangle_bot, hv_imHeight*(1-hv_Ratio),hv_imWidth*hv_Ratio, hv_imHeight-1, (hv_imWidth*(1-hv_Ratio))-1);
    //left
    GenRectangle1(&ho_Rectangle_lft, hv_imHeight*hv_Ratio, 0, (hv_imHeight*(1-hv_Ratio))-1, (hv_imWidth*hv_Ratio)-1);
    //right
    GenRectangle1(&ho_Rectangle_rgt, hv_imHeight*hv_Ratio, hv_imWidth*(1-hv_Ratio), (hv_imHeight*(1-hv_Ratio))-1, hv_imWidth-1);
    ConcatObj(ho_Rectangle_top, ho_Rectangle_bot, &ho_ObjectsConcat);
    ConcatObj(ho_ObjectsConcat, ho_Rectangle_lft, &ho_ObjectsConcat);
    ConcatObj(ho_ObjectsConcat, ho_Rectangle_rgt, &ho_ObjectsConcat);
    Union1(ho_ObjectsConcat, &(*ho_Region));
}

3、获取四角区域:

void GetImageRegion_Corner (HObject *ho_Region, HTuple hv_imWidth, HTuple hv_imHeight, HTuple hv_Ratio)
{
    // Local iconic variables
    HObject  ho_Rectangle_lt, ho_Rectangle_lb, ho_Rectangle_rt;
    HObject  ho_Rectangle_rb, ho_ObjectsConcat;
    //left top
    GenRectangle1(&ho_Rectangle_lt, 0, 0, (hv_imHeight*hv_Ratio)-1, (hv_imWidth*hv_Ratio)-1);
    //left bottom
    GenRectangle1(&ho_Rectangle_lb, hv_imHeight*(1-hv_Ratio), 0, hv_imHeight-1, (hv_imWidth*hv_Ratio)-1);
    //right top
    GenRectangle1(&ho_Rectangle_rt, 0, hv_imWidth*(1-hv_Ratio), (hv_imHeight*hv_Ratio)-1, hv_imWidth-1);
    //right bottom
    GenRectangle1(&ho_Rectangle_rb, hv_imHeight*(1-hv_Ratio), hv_imWidth*(1-hv_Ratio), hv_imHeight-1, hv_imWidth-1);

    ConcatObj(ho_Rectangle_lt, ho_Rectangle_lb, &ho_ObjectsConcat);
    ConcatObj(ho_ObjectsConcat, ho_Rectangle_rt, &ho_ObjectsConcat);
    ConcatObj(ho_ObjectsConcat, ho_Rectangle_rb, &ho_ObjectsConcat);
    Union1(ho_ObjectsConcat, &(*ho_Region));
}

注意:四边和四角的区域各有四个,返回的是联合区域。

你可能感兴趣的:(Halcon实战,图像处理)