【机器视觉】 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:【机器视觉】 Halcon批量加载图像
下一篇:【Qt】 Qt中实时更新UI程序示例

发表评论

最新留言

不错!
[***.144.177.141]2024年04月19日 04时48分48秒