halcon学习1

来源:互联网 发布:淘宝店铺被监管要多久 编辑:程序博客网 时间:2024/05/20 18:01

方便学习,转载,原文地址:http://blog.csdn.net/pbimage/article/details/22988199

1. vs2013平台阈值化图像

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. #include "cpp/HalconCpp.h"  
  2. #include "Halcon.h"  
  3. #include <stdlib.h>  
  4.   
  5. using namespace Halcon;  
  6.   
  7. const char gImageName[256] = "lena.jpg";  
  8.   
  9. int main()  
  10. {  
  11.     Hobject image, regions;  
  12.   
  13.     HTuple width, height, windowId;  
  14.   
  15.     read_image(&image, gImageName);//载入图像  
  16.   
  17.     get_image_size(image, &width, &height);//获取图像宽、高  
  18.   
  19.     open_window(0, 0, width, height, 0, """", &windowId);//创建窗口  
  20.   
  21.     int w = width[0].I();//HTuple类型转换int  
  22.     int h = height[0].I();  
  23.   
  24.     //auto_threshold(image, &regions, 2);//基于直方图自适应二值化  
  25.     threshold(image, &regions, 64, 128);//固定阈值二值化  
  26.   
  27.     disp_obj(regions, windowId);//显示图像  
  28.   
  29.     getchar();  
  30.   
  31.     return 0;  
  32. }  


Halcon基础:

1. halcon显示图像的各个函数区别

    disp_image()    图像首通道灰度图,如3通道图像,也仅显示第一个数据通道图像;

    disp_color()      显示彩色图;

    disp_channel() 某特定通道;

    disp_obj()          自动判别类别,即图像为彩色图像,则显示为彩色;如图像为灰色图像,则显示为灰度;

2. write_image(image, "jpg", 0, "image.jpg");  将图像image以jpg格式存储到文件image.jpg中

3. HTuple数据结构与c++数据类型互转

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. //HTuple与int互转:  
  2. HTuple tuple;  
  3. int val = 2;  
  4. tuple[0] = val;//int 转HTuple  
  5. val = tuple[0].I();//HTuple转int  
  6. //HTuple与long互转:  
  7. long val = 10;  
  8. tuple[0] = val;  
  9. val = tuple[0].L();  
  10. //HTuple与double互转:  
  11. double val = 3.3;  
  12. tuple[0] = val;  
  13. val = tuple[0].D();  
  14. //HTuple转const char*:  
  15. CString strVal = "Halcon";  
  16. tuple[2] = strVal.GetBuffer();  
  17. strVal = tuple[2].S();  
  18.   
  19. int num = tuple.Num();  
  20.   
  21. 注:初接触Halcon,我的理解是HTuple类似C++中的vector(可能比喻不够恰当), 但是又不同于vector,HTuple可以存不同类型数据,  
  22. 如HTuple[0]存int型,HTuple[1]存double型,HTuple[2]存字符串...HTuple.Num()返回整个HTuple类型数据的总长度。  
0 0