【机器视觉】 Halcon代码导出高级语言代码
发布日期:2021-06-29 20:52:39
浏览次数:2
分类:技术文章
本文共 5036 字,大约阅读时间需要 16 分钟。
00. 目录
文章目录
01. 概述
halcon是一款非常不错的视觉类辅助设计软件,它是由非常专业的MVtec公司全新推出的最新版本。在功能上拥有非常实用方便的机器视觉开发能力,其非常独特的内部结构能够很好的辅助各种机器的视觉功能,这样不管是在医学图像上面还是各种图像分析上面都能够起到非常大的帮助,并且软件内部搭在了非常先进智能的图像算法能力,用户们在制作各种产品的时候就可以节省非常多的时间,极大的提高了工作效率。在用途方面,它也有着非常广泛的应用,能够用于多个行业的使用,就比如形态学,测量图像以及blob等等相关图像领域。作为系列的最新版本,它不光是优化了许多内容还新增了一些非常便捷的功能,现在可以做到通过更加高级方便的算法来读取条形码,极大的加快了读取速度。还对软件的开发操作环境进行非常人性化的升级优化等等
02. 开发环境
Windows系统:Windows10
Halcon版本:HDevelop 19.11
03. Halcon源码
* 读取图片文件read_image (Image, 'fabrik')* 获取图片大小信息get_image_size (Image, Width, Height)dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
04. Halcon源码导出方法
4.1 选择文件–>导出
4.2 选择导出相关设置
支持导出的方式有:文本文件、C文件、C++文件、VB文件和C#文件。
05. Halcon源码导出为C++程序
5.1 导出文件选择C++
5.2 导出之后,查看导出的C++文件
///// File generated by HDevelop for HALCON/C++ Version 19.11.0.0// Non-ASCII strings in this file are encoded in local-8-bit encoding (cp936).// Ensure that the interface encoding is set to locale encoding by calling// SetHcppInterfaceStringEncodingIsUtf8(false) at the beginning of the program.// // Please note that non-ASCII characters in string constants are exported// as octal codes in order to guarantee that the strings are correctly// created on all systems, independent on any compiler settings.// // Source files with different encoding should not be mixed in one project.///#ifndef __APPLE__# include "HalconCpp.h"# include "HDevThread.h"#else# ifndef HC_LARGE_IMAGES# include# include # include # else# include # include # include # endif# include # include #endifusing namespace HalconCpp;#ifndef NO_EXPORT_MAIN// Main procedure void action(){ // Local iconic variables HObject ho_Image; // Local control variables HTuple hv_Width, hv_Height, hv_WindowHandle; //读取图片文件 ReadImage(&ho_Image, "fabrik"); //获取图片大小信息 GetImageSize(ho_Image, &hv_Width, &hv_Height); SetWindowAttr("background_color","black"); OpenWindow(0,0,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle); HDevWindowStack::Push(hv_WindowHandle);}#ifndef NO_EXPORT_APP_MAIN#ifdef __APPLE__// On OS X systems, we must have a CFRunLoop running on the main thread in// order for the HALCON graphics operators to work correctly, and run the// action function in a separate thread. A CFRunLoopTimer is used to make sure// the action function is not called before the CFRunLoop is running.// Note that starting with macOS 10.12, the run loop may be stopped when a// window is closed, so we need to put the call to CFRunLoopRun() into a loop// of its own.HTuple gStartMutex;H_pthread_t gActionThread;HBOOL gTerminate = FALSE;static void timer_callback(CFRunLoopTimerRef timer, void *info){ UnlockMutex(gStartMutex);}static Herror apple_action(void **parameters){ // Wait until the timer has fired to start processing. LockMutex(gStartMutex); UnlockMutex(gStartMutex); try { action(); } catch (HException &exception) { fprintf(stderr," Error #%u in %s: %s\n", exception.ErrorCode(), (const char *)exception.ProcName(), (const char *)exception.ErrorMessage()); } // Tell the main thread to terminate itself. LockMutex(gStartMutex); gTerminate = TRUE; UnlockMutex(gStartMutex); CFRunLoopStop(CFRunLoopGetMain()); return H_MSG_OK;}static int apple_main(int argc, char *argv[]){ Herror error; CFRunLoopTimerRef Timer; CFRunLoopTimerContext TimerContext = { 0, 0, 0, 0, 0 }; CreateMutex("type","sleep",&gStartMutex); LockMutex(gStartMutex); error = HpThreadHandleAlloc(&gActionThread); if (H_MSG_OK != error) { fprintf(stderr,"HpThreadHandleAlloc failed: %d\n", error); exit(1); } error = HpThreadCreate(gActionThread,0,apple_action); if (H_MSG_OK != error) { fprintf(stderr,"HpThreadCreate failed: %d\n", error); exit(1); } Timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(),0,0,0, timer_callback,&TimerContext); if (!Timer) { fprintf(stderr,"CFRunLoopTimerCreate failed\n"); exit(1); } CFRunLoopAddTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes); for (;;) { HBOOL terminate; CFRunLoopRun(); LockMutex(gStartMutex); terminate = gTerminate; UnlockMutex(gStartMutex); if (terminate) break; } CFRunLoopRemoveTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes); CFRelease(Timer); error = HpThreadHandleFree(gActionThread); if (H_MSG_OK != error) { fprintf(stderr,"HpThreadHandleFree failed: %d\n", error); exit(1); } ClearMutex(gStartMutex); return 0;}#endifint main(int argc, char *argv[]){ int ret = 0; try { #if defined(_WIN32) SetSystem("use_window_thread", "true");#endif // file was stored with local-8-bit encoding // -> set the interface encoding accordingly SetHcppInterfaceStringEncodingIsUtf8(false); // Default settings used in HDevelop (can be omitted) SetSystem("width", 512); SetSystem("height", 512);#ifndef __APPLE__ action();#else ret = apple_main(argc,argv);#endif } catch (HException &exception) { fprintf(stderr," Error #%u in %s: %s\n", exception.ErrorCode(), (const char *)exception.ProcName(), (const char *)exception.ErrorMessage()); ret = 1; } return ret;}#endif#endif
06. 附录
6.1 机器视觉博客汇总
网址:转载地址:https://dengjin.blog.csdn.net/article/details/117771025 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月19日 04时48分48秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
在 Android Studio 2.2 中愉快地使用 C/C++
2019-04-30
C++和JNI的数据转换
2019-04-30
JNI 传递结构体参数
2019-04-30
JNI中枚举类型作为参数
2019-04-30
qlineedit tab焦点处无法输入问题
2019-04-30
android精确绘制文字位置的方法
2019-04-30
Android中UI线程与后台线程交互设计的5种方法
2019-04-30
[Android]调用字符串资源的几种方法
2019-04-30
Android更新UI的两种方法——handler与runOnUiThread()
2019-04-30
Java中new Thread的弊端及Java四种线程池的使用
2019-04-30
android线程与UI消息传递
2019-04-30
java枚举定义
2019-04-30
[翻译][Java]ExecutorService的正确关闭方法
2019-04-30
QT父子窗口事件传递与事件过滤器
2019-04-30
Qt到Cortex-A8的移植
2019-04-30
Qt4.7.3交叉编译移植
2019-04-30
luvcview摄像头程序到Cortex A8的安装移植
2019-04-30
Android开发书籍书籍介绍:
2019-04-30
QT 的信号与槽机制介绍
2019-04-30
Qt信号槽机制与Q_OBJECT
2019-04-30