在使用C++编写halcon之前,确定自己有较好的C++基础,并熟悉一套开发平台如VC
 
Programmers_guide.pdf chapter7中有关于creating Aplicatin with halcon/c++的详细介绍
 
 
以vs2008为例 工具---》选项  (有图介绍不配文字啦)
 
 
 
用C++写例子  ~~取狒狒的眼睛
//
#include "stdafx.h"
#include "HalconCpp.h"
#pragma comment(lib,"halconcpp.lib")
 
 
int main()
{
    using namespace Halcon;
    HImage Mandrill("monkey");
    HWindow w;
    w.Display(Mandrill);
    w.Click();
    HRegion Bright = (Mandrill >=128); // 取亮度大于128的区域
    HRegionArray conn = Bright.Connection();
    //取面积在500~9000的区域,狒狒的大鼻子也是大于128的,显然不是我们检测的重点根据面积舍去它
    HRegionArray large = conn.SelectShape("area","and",500,9000); 
    //眼睛是椭圆形的anisometry 是离心率即ra/rb 两半径之比,目测来看取1.2 -1.7
    HRegionArray eyes = large.SelectShape("anisometry","and",1.2,1.7);
    eyes.Display(w);
    w.Click();
    return 0;

}

 
 
//~~ 提取字符
#include "stdafx.h"
#include "HalconCpp.h"
#include <iostream>
#pragma comment(lib,"halconcpp.lib")
using namespace std;
using namespace Halcon;
 
int main()
{
    HImage image("alpha1");
    HRegion region;
    HWindow w;
    long threshold;
    image.Display(w);
    w.Click();
    // image.GetDomain -- 获得图像region
    //sigma --- 高斯平滑系数
    //Percent --- 前景背景灰度不同百分比 95 代表 至多有5%是最大灰度值 
    region = image.CharThreshold(image.GetDomain(),2,95,&threshold);
    image.Display(w);
    region.Display(w);
    w.Click();
    cout<<"Threshold for 'alpha': "<<threshold;
    w.Click();
    return 0;

}

注意:参考手册中的操作符不全,A complete list can be found in the file include\cpp\HCPPGlobal.h.
 
 
1.关于参数:
①.halcon的输入参数 (input parameters)不会被操作符改变,也就是说是按值传递的
 
如下代码示例
HImage original_image("monkey"), smoothed_image;
smoothed_image = original_image.MeanImage(11, 11);
 
meanimage不会改变original_image,而中值后的图像保存在返回值 smoothed_image中
 
②.与之相反的是输出参数(output parameters),所以传的是指针或者引用
 
 
2.halcon /C++关于面向对象和过程
 
这是通过类来调用方法的 ,面向对象方式
HImage image("barcode/ean13/ean1301");

HTuple paramName, paramValue;
HBarCode barcode(paramName, paramValue);
HRegionArray code_region;
HTuple result;
code_region = barcode.FindBarCode(image, "EAN-13", &result);
code_region = image.FindBarCode(barcode, "EAN-13", &result);
 
面向过程的方式
Hobject image;
HTuple barcode;
Hobject code_region;
HTuple result;
read_image(&image, "barcode/ean13/ean1301");
create_bar_code_model(HTuple(), HTuple(), &barcode);

find_bar_code(image, &code_region, barcode, "EAN-13", &result);

 
3.halcon/c++所有的 对象 可以在C:\Program Files\MVTec\HALCON-10.0\include\cpp 中找到 (以halcon安装在C盘为例)
 
4.halcon/c++的数组模式
 
  我们可以用操作符来 打开多个图片 region 等等 看该操作是否支持 数组模式 要看它的定义了
 
如图所示
 
 
 数组的几点说明:
① 创建,初始化数组
    C++ 可以通过 [] 
    C 通过 gen_empty_obj 增加数组 concat_obj
 
②操纵对象
   C++ 通过[N] ,统计数组元素个数 num()
   C  select_obj       count_obj
 
③iconic 数组以 0 开始  , Hobject 数组 以 1 开始
 
④通过例子说明第四点
 
#include "stdafx.h"
#include "HalconCpp.h"
#include <iostream>
#pragma comment(lib,"halconcpp.lib")
using namespace std;
using namespace Halcon;
 
//~~ 提取字符
int main()
{
    HImageArray images;
    HRegionArray regions;
    HTuple thresholds;
    HWindow w;
    for (int i = 1; i <=2;++i)
    {
        //HTuple("alpha") +i 的解释
        //HTuple 中有对 operater + 的重载 
        //HTuple("alpha") +i ~~~ alpha1 alpha2.....
        images[i-1] = HImage::ReadImage(HTuple("alpha") +i);
    }
 
    //这一句相当于对 images中所有的对象进行了 charthreshold操作
    regions = images.CharThreshold(images[0].GetDomain(),2,95,&thresholds);
 
    for (int i = 0 ; i<regions.Num();++i)
    {
        images[i].Display(w);
        w.Click();
        regions[i].Display(w);
        w.Click();
        cout<<"threshold : "<<thresholds[i].L()<<endl;
    }
    w.Click();
 
    return 0;
}
 
5. 关于参数转换
• Converting Hobject into iconic parameter classes
 
Hobject p_image;
read_image(&p_image, "barcode/ean13/ean1301");
HImage o_image(p_image);
 
Iconic parameters can be converted from Hobject to, e.g., HImage simply by calling the construc-
tor with the procedural variable as a parameter.
 
• Converting handles into handle classes
 
HTuple p_barcode;
create_bar_code_model(HTuple(), HTuple(), &p_barcode);
HBarCode o_barcode;
o_barcode.SetHandle(p_barcode[0]);
o_code_region = o_barcode.FindBarCode(o_image, "EAN-13", &result);
 
Handles cannot be converted directly via a constructor; instead, you call the method SetHandle()
with the procedural handle as a parameter.
 
• Converting handle classes into handles
 
p_barcode = o_barcode.GetHandle();
 
Similarly, a handle can be extracted from the corresponding class via the method GetHandle().
You can even omit the method, as the handle classes provide cast operators which convert them
automatically into handles.       
 
 p_barcode = o_barcode;
 
•Converting iconic parameter classes into Hobject
 
Hobject p_code_region = o_code_region.Id();
 
Iconic parameters can be converted from classes like HRegion back into Hobject via the method
Id(). In contrast to the handle classes no cast operator is provided.
 
 
• Converting HWindow into a window handle
 
long p_window;
open_window(0, 0, width/2, height/2, 0, "visible", "", &p_window);
HWindow o_window(0, 0, 100, 100, 0, "visible", "");
p_window = o_window.WindowHandle();
disp_obj(p_code_region, p_window);
 
In contrast to other handles, procedural window handles cannot be converted into instances of the
class HWindow! However, you can extract the handle from an instance of HWindow via the method
WindowHandle().
 
 
6 . The halcon Parameter classes
 
6.1 Iconic Objects
 
    基类为Hobject
    HImage ,HRegion,HXLD 基类为Hobject
 
6.1.1 Reions
 
region 是图像平面的一组坐标点 , 它可能不是连接的,可能含有洞,它可以比图像还大。
通过一个例子来了解HRegion
 
#include "stdafx.h"

#include "HalconCpp.h"
#include <iostream>
#pragma comment(lib,"halconcpp.lib")
using namespace std;
using namespace Halcon;
/*
    例子介绍了region的用法 ,更详细的介绍在 progarma_guide  chapter6.1.1
*/
int main()
{
    HImage image("mreut");
    HRegion region;
    HWindow w;
    region = image >=190;
    w.SetColor("red");
    region.Display(w);
    w.Click();
 
    //region.Fillup() 调用方法
    HRegion filled = region.FillUp();
    filled.Display(w);
    w.Click();
 
    //运算符重载 开运算 >> 腐蚀 <<膨胀 , 半径4.5
    HRegion open = (filled >>4.5)<<4.5;
    w.SetColor("green");
    open.Display(w);
    w.Click();
 
    w.ClearWindow();
    //平移
    HDPoint2D trans(-100 , -150);
    HRegion moved = open + trans;
    HRegion zoomed = moved * 2.0;
    zoomed.Display(w);
    w.Click();
 
    return 0;

}

 
 
 
 
#include "stdafx.h"
#include "HalconCpp.h"
#include <iostream>
#pragma comment(lib,"halconcpp.lib")
using namespace std;
using namespace Halcon;
/*
    例子介绍了regionArry的用法
*/
int main()
{
    HImage image("fabrik");
    // 1 1 row col 越小越精细
    // 4 容差 种子和被检测像素值差
    // 100 最小region size 
    HRegionArray regs = image.Regiongrowing(1,1,4,100);
    HWindow w;
    w.SetColored(12);
    image.Display(w);
    w.Click();
    regs.Display(w);
    w.Click();
 
 
    HRegionArray rect;
    for (int i = 0 ; i < regs.Num() ; ++ i )
    {
        // compactness ~~ 在图像处理中经常叫做圆形度 而这里用作 region的紧密度
        //C = L^2 / (4 F pi)) L = 周长 F = 面积
        //C = 1 是 为圆 ,region 较长是 或者region 有洞洞时 C >1
        //这里就是得出了 比较方正的 没小洞洞的 region
        if ( (regs[i].Area() > 1000) && ( regs[i].Compactness() < 1.5) )
            rect.Append(regs[i]); //RegionArry 添加元素哦
    }
    image.Display(w);
    rect.Display(w);
    w.Click();
 
    return 0;
}
 
 
6.1.2 Images
 
#include "stdafx.h"

#include "HalconCpp.h"
#include <iostream>
#pragma comment(lib,"halconcpp.lib")
using namespace std;
using namespace Halcon;
/*
  drawregion 画感兴趣区域
  meanimage 做个中值滤波
  和中值滤波前图像比较
*/
int main()
{
 
    HImage image("mreut");
    HWindow w;
    image.Display(w);
    cout<< " width = " << image.Width()<<endl;
    cout << " height = " << image.Height() <<endl;
 
    HRegion mask= w.DrawRegion();
 
  //  & 重载  取感兴趣区域的图像
    HImage reduced = image & mask;
    w.ClearWindow();
    reduced.Display(w);
    w.Click() ; 
 
    HImage mean = reduced.MeanImage(61,61);
    mean.Display(w);
 
    HRegion reg = reduced.DynThreshold(mean,3,"light");
    reg.Display(w);
    w.Click();
    return 0;
}
 
6.1.2.2  像素值
 
操纵像素的两种方法
int main()

{
    HByteImage in("mreut");
    HByteImage out = in ;
    HWindow w;
    in.Display(w);
    w.Click() ; 
 
    int nwidht = in.Width();
    int nheight = in.Height();
    long end = nwidht * nheight;
 
    for (int k = 0 ; k < end ; k++)
    {
        //方法1
        //int pix = in.GetPixVal(k);
        //out.SetPixVal(k,255 - pix);
 
        //方法2
        out[k]= 255 - in[k];
    }
    out.Display(w);
    w.Click();
    return 0;

}

 
6.1.3 XLD Objects
 
 
XLD is the abbreviation for eXtended Line Description. This is a data structure used for describing areas
 
(e.g., arbitrarily sized regions or polygons) or any closed or open contour, i.e., also lines. In contrast to
 
regions, which represent all areas at pixel precision, XLD objects provide subpixel precision. There are
 
two basic XLD structures: contours and polygons.
 
Similarly to images, HALCON/C++ provides both a base class HXLD and a set of specialized classes
 
derived from HXLD, e.g., HXLDCont for contours or HXLDPoly for polygons. For all classes there exists
 
a corresponding container class, e.g., HXLDArray.
 
In contrast to the classes described in the previous sections, the XLD classes provide only member
 
functions corresponding to HALCON operators (see also section 5.2.2 on page 35).
 
 
6.1.4 Low - level iconic objects 底层iconic 对象
 
 the class Hobject is used for all iconic parameters, be it an image, a region, or even an image array
 
 In fact, the class Hobject is HALCON’s basic class for accessing the internal data management
 
Furthermore, Hobject serves as the basis for the class HObject and the derived classes, e.g., HImage.
 
As noted above, an instance of Hobject can also contain a tuple (array) of iconic objects. Unfortunately,
 
Hobject provides no special member functions to add objects or select them; instead, you must use the
 
operators gen_empty_obj, concat_obj, select_obj, and count_obj 。
 
一个Hobject实例可以包含一组iconic 对象,但Hobject 没有提供增加或选择它们的成员函数,所以必须通过
gen_empty_obj, concat_obj, select_obj, and count_obj 来解决。
 
 
6.2 Control parameters
 
 

附件列表

halocn/C++ (第一篇)的更多相关文章

  1. 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)

    从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...

  2. Python爬虫小白入门(四)PhatomJS+Selenium第一篇

    一.前言 在上一篇博文中,我们的爬虫面临着一个问题,在爬取Unsplash网站的时候,由于网站是下拉刷新,并没有分页.所以不能够通过页码获取页面的url来分别发送网络请求.我也尝试了其他方式,比如下拉 ...

  3. Three.js 第一篇:绘制一个静态的3D球体

    第一篇就画一个球体吧 首先我们知道Three.js其实是一个3D的JS引擎,其中的强大之处就在于这个JS框架并不是依托于JQUERY来写的.那么,我们在写这一篇绘制3D球体的文章的时候,应该注意哪些地 ...

  4. 深入学习jQuery选择器系列第一篇——基础选择器和层级选择器

    × 目录 [1]id选择器 [2]元素选择器 [3]类选择器[4]通配选择器[5]群组选择器[6]后代选择器[7]兄弟选择器 前面的话 选择器是jQuery的根基,在jQuery中,对事件处理.遍历D ...

  5. 【第一篇】ASP.NET MVC快速入门之数据库操作(MVC5+EF6)

    目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...

  6. Android基础学习第一篇—Project目录结构

    写在前面的话: 1. 最近在自学Android,也是边看书边写一些Demo,由于知识点越来越多,脑子越来越记不清楚,所以打算写成读书笔记,供以后查看,也算是把自己学到所理解的东西写出来,献丑,如有不对 ...

  7. 深入理解ajax系列第一篇——XHR对象

    × 目录 [1]创建对象 [2]发送请求 [3]接收响应[4]异步处理[5]实例演示 前面的话 ajax是asynchronous javascript and XML的简写,中文翻译是异步的java ...

  8. 深入理解javascript对象系列第一篇——初识对象

    × 目录 [1]定义 [2]创建 [3]组成[4]引用[5]方法 前面的话 javascript中的难点是函数.对象和继承,前面已经介绍过函数系列.从本系列开始介绍对象部分,本文是该系列的第一篇——初 ...

  9. 深入理解this机制系列第一篇——this的4种绑定规则

    × 目录 [1]默认绑定 [2]隐式绑定 [3]隐式丢失[4]显式绑定[5]new绑定[6]严格模式 前面的话 如果要问javascript中哪两个知识点容易混淆,作用域查询和this机制绝对名列前茅 ...

随机推荐

  1. iOS 机智的修改导航栏返回事件

    只需要一个在自定义的基类控制器的UIBarButtonItem,在需要的时候继承该类,实现selector方法即可(如果大部分处理都是一样的,只需在基类控制器内实现操作). self.navigati ...

  2. 在vi中打开多个文件,复制一个文件中多行到另一个文件中

    :set number 查看行号1.vi a.txt b.txt或者vi *.txt 2.文件间切换 :n切换到下一个文件,:wn保存再切换 :N到上一个文件,:wN保存再切换 :.=看当前行 3.比 ...

  3. c++类static成员

    转自:http://blog.csdn.net/heyabo/article/details/8681516 参考文献:1.http://www.yesky.com/20010828/194000.s ...

  4. C#基础--多线程

    一.微软早期操作系统中的问题 在早期的操作系统中,应用程序都是在同一个地址空间中运行的,每个程序的数据其它程序都是可见的,并且因为早期CPU是单内核 的所以所有的执行都是线性的.这就引出两个问题: 第 ...

  5. Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors

    Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors 1,分析原因: 根本原因是Chromedriver和Chrome的版本不兼容: 网 ...

  6. JAVA面试题整理(4)-Netty

    1.BIO.NIO和AIO 2.Netty 的各大组件 3.Netty的线程模型 4.TCP 粘包/拆包的原因及解决方法 5.了解哪几种序列化协议?包括使用场景和如何去选择 6.Netty的零拷贝实现 ...

  7. 20145307陈俊达《信息安全系统设计基础》第5周学习总结PT1

    20145307陈俊达<信息安全系统设计基础>第5周学习总结 教材学习内容总结 X86寻址方式经历三代: DOS时代的平坦模式,不安全,原因是没有区分用户空间和内核空间 8086的分段模式 ...

  8. 20144303 《Java程序设计》课程总结

    20144303 <Java程序设计>课程总结 每周读书笔记链接汇总 第一周:http://www.cnblogs.com/20144303sys/p/5248979.html 第二周:h ...

  9. 【读书笔记】《深入浅出nodejs》第四章 异步编程

    1. 异步编程的基础 -- 函数式编程 (1)高阶函数 -- 是可以把函数作为参数,或是将函数作为返回值的函数. (2)偏函数用法 -- 创建一个调用另外一个部分 -- 参数或变量已经预置的函数 -- ...

  10. git分支合并脚本

    为什么要写这个脚本 工作中经常会有合并分支的操作,一开始也不以为然,后来发现如果更新频繁的话,根本就停不下来,昨天上午正好有空,就完成了下面的这个初版 可能存在的问题 一般的应用场景都是:从maste ...