方便学习,转载,原文地址:http://blog.youkuaiyun.com/pbimage/article/details/22988199
1. vs2013平台阈值化图像
- #include "cpp/HalconCpp.h"
- #include "Halcon.h"
- #include <stdlib.h>
- using namespace Halcon;
- const char gImageName[256] = "lena.jpg";
- int main()
- {
- Hobject image, regions;
- HTuple width, height, windowId;
- read_image(&image, gImageName);//载入图像
- get_image_size(image, &width, &height);//获取图像宽、高
- open_window(0, 0, width, height, 0, "", "", &windowId);//创建窗口
- int w = width[0].I();//HTuple类型转换int
- int h = height[0].I();
- //auto_threshold(image, ®ions, 2);//基于直方图自适应二值化
- threshold(image, ®ions, 64, 128);//固定阈值二值化
- disp_obj(regions, windowId);//显示图像
- getchar();
- return 0;
- }
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++数据类型互转
- //HTuple与int互转:
- HTuple tuple;
- int val = 2;
- tuple[0] = val;//int 转HTuple
- val = tuple[0].I();//HTuple转int
- //HTuple与long互转:
- long val = 10;
- tuple[0] = val;
- val = tuple[0].L();
- //HTuple与double互转:
- double val = 3.3;
- tuple[0] = val;
- val = tuple[0].D();
- //HTuple转const char*:
- CString strVal = "Halcon";
- tuple[2] = strVal.GetBuffer();
- strVal = tuple[2].S();
- int num = tuple.Num();
- 注:初接触Halcon,我的理解是HTuple类似C++中的vector(可能比喻不够恰当), 但是又不同于vector,HTuple可以存不同类型数据,
- 如HTuple[0]存int型,HTuple[1]存double型,HTuple[2]存字符串...HTuple.Num()返回整个HTuple类型数据的总长度。