设为首页 加入收藏

TOP

halcon/c++接口基础 之 HALCON图像变量类(一)
2016-09-03 16:03:00 】 浏览:1350
Tags:halcon/c 接口 基础 HALCON 图像 变量

在HALCON/C++中,HObject是一个基类,可以表示图像变量。另外还有三种类继承自HObject.

Class HImage 处理图像 Class HRegion 处理区域 Class HXLD 处理多边形

Regions

一个region是图像平面坐标点的集合。这样一个区域不需要被连通,而且可能还有好多洞。a region可以比实际的图像大。区域在HALCON中可以用所谓的行程编码实现。类HRegion代表HALCON/C++中的一个区域。HRegion的成员函数如下(列举几个重要的):

HRegion(void)
默认构造器。创造一个空的region,即region的面积是0.并不是所有的算子都可以将空region作为输入参数,例如一些shape property 操作。 HRegion(const HRegion )
拷贝构造函数 HRegion &operator = (const HRegion )
赋值运算符 void Display(const HWindow &w) const
在一个窗口中输出region

区域的几何变换

HRegion operator * (double scale) const
放缩区域到任何一个尺度。放缩中心为(0,0) HRegion operator + (const HDPoint2D &point) const
HRegion &operator += (const HDPoint2D &point)
平移

区域的形态学处理:

HRegion operator >> (double radius) const
HRegion &operator >>= (double radius)
用一个圆腐蚀,同erosion_circle HRegion operator << (double radius) const
HRegion &operator <<= (double radius)
用一个圆膨胀,同 dilation_circle. HRegion &operator ++ (void)
用一个含有五个点的十字交叉去膨胀。 HRegion &operator -- (void)
用一个含有五个点的十字交叉去腐蚀。 HRegion operator + (const HRegion ) const
HRegion &operator += (const HRegion )
与另一个区域的Minkowsky 加和, 同 minkowski_add1. HRegion operator - (const HRegion ) const
HRegion &operator -= (const HRegion )
与另一个区域的Minkowsky 减法, 同 minkowski_sub1.

区域的属性:

double Phi(void) const
一个等价的椭圆的角度,同 elliptic_axis. double Ra(void) const
一个区域的等价的椭圆的长半轴,同 elliptic_axis. double Rb(void) const
一个区域的等价的椭圆的短半轴,同elliptic_axis. long Area(void) const
区域的面积,即所包含的像素数,见 area_center. double X(void) const
double Y(void) const
区域的中心点坐标,见area_center. HRectangle1 SmallestRectangle1(void) const
区域的最小包围盒,此包围盒平行于坐标轴,同 smallest_rectangle1. HBool In(const HDPoint2D &p) const
检验一个点是否在区域内部,同 test_region_point. HBool IsEmpty(void) const;
检验区域是否为空,也就是区域面积是否为0

例1

 #include "HalconCpp.h"
using namespace Halcon;
void main()
{ 
    HImage     image("E:\\halcon\\images\\mreut.png");              // Reading an aerial image
    HRegion    region = image >= 190;       // Calculating a threshold
    HWindow    w;                           // Display window
    w.SetColor("red");                      // Set color for regions
    region.Display(w);                      // Display the region
    HRegion    filled = region.FillUp();    // Fill holes in region
    filled.Display(w);                      // Display the region
    // Opening: erosion followed by a dilation with a circle mask
    HRegion    open = (filled >> 4.5) << 4.5;
    w.SetColor("green");                    // Set color for regions
    open.Display(w);                        // Display the region
    HDPoint2D  trans(-100, -150);            // Vector for translation
    HRegion    moved = open + trans;       // Translation
    HRegion    zoomed = moved * 2.0;        // Zooming the region
}

First, an aerial image (mreut.png) is read from a file. All pixels with a gray value ≥ 190 are selected. This results in one region (region). This region is transformed by the next steps: All holes in the region are filled (FillUp), small parts of the region are eliminated by two morphological operations, first an erosion, a kind of shrinking the region, followed by a dilation, a kind of enlarging the region. The last step is the zooming of the region. For that the region is first shifted by a translation vector ( 100, 150) to the upper left corner and then zoomed by the factor two. Figure 6.2 shows the input image and the result of the opening operation.

Region Arrays

HRegionArray是一个包含Region的容器。代表成员函数如下:

long Num(void)
数列的个数,最大序号是Num() 1. HRegion const &operator [] (long index) const
读取数组的第i个元素,序号是 0 … Num() 1. HRegion &operator [] (long index)
将一个region赋值给区域的第j个元素,The index index can be ≥ Num(). HRegionArray operator () (long min, long max) const
选取介于min与max之间的数据 HRegionArray &Append(const HRegion )
将一个region附加到region array的后面

许多接受region的算子都接受region array作为输入参数。如形态学操作。

例2

#include "HalconCpp.h"
using namespace Halcon;
void main()
{ 
    HImage        image("E:\\halcon\\images\\control_unit.png
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++中的智能指针 下一篇C/C++中【提高程序效率的9个简单..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目