当前位置: 首页 > news >正文

第7篇 halcon12导出c++在vs2019配置环境显示图片

halcon代码

read_image (DSC_0097, 'D:/halcon_project/test3.bmp')
dev_open_window_fit_image(DSC_0097,0,0,-1,-1,WindowHandle)
dev_clear_window()
dev_display(DSC_0097)

文件导出:

显示导出路径,点击导出,生成了test2.cpp备用

vs2019打开,新建一个空项目

右键-》添加-》新建项

打开test2.cpp,复制所有内容

再打开main.cpp,粘贴

///////////////////////////////////////////////////////////////////////////////
//  File generated by HDevelop for HALCON/C++ Version 12.0
///////////////////////////////////////////////////////////////////////////////#ifndef __APPLE__
#  include "HalconCpp.h"
#  include "HDevThread.h"
#  if defined(__linux__) && !defined(NO_EXPORT_APP_MAIN)
#    include <X11/Xlib.h>
#  endif
#else
#  ifndef HC_LARGE_IMAGES
#    include <HALCONCpp/HalconCpp.h>
#    include <HALCONCpp/HDevThread.h>
#  else
#    include <HALCONCppxl/HalconCpp.h>
#    include <HALCONCppxl/HDevThread.h>
#  endif
#  include <stdio.h>
#  include <HALCON/HpThread.h>
#  include <CoreFoundation/CFRunLoop.h>
#endifusing namespace HalconCpp;#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.
HTuple      gStartMutex;
H_pthread_t gActionThread;static void timer_callback(CFRunLoopTimerRef timer, void* info)
{UnlockMutex(gStartMutex);
}static Herror apple_action(void** parameters)
{LockMutex(gStartMutex);action();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);CFRunLoopRun();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;
}
#endif
//using namespace HalconCpp;// Procedure declarations 
// Chapter: Develop
// Short Description: Open a new graphics window that preserves the aspect ratio of the given image. 
void dev_open_window_fit_image(HObject ho_Image, HTuple hv_Row, HTuple hv_Column,HTuple hv_WidthLimit, HTuple hv_HeightLimit, HTuple* hv_WindowHandle);// Procedures 
// Chapter: Develop
// Short Description: Open a new graphics window that preserves the aspect ratio of the given image. 
void dev_open_window_fit_image(HObject ho_Image, HTuple hv_Row, HTuple hv_Column,HTuple hv_WidthLimit, HTuple hv_HeightLimit, HTuple* hv_WindowHandle)
{// Local iconic variables// Local control variablesHTuple  hv_MinWidth, hv_MaxWidth, hv_MinHeight;HTuple  hv_MaxHeight, hv_ResizeFactor, hv_ImageWidth, hv_ImageHeight;HTuple  hv_TempWidth, hv_TempHeight, hv_WindowWidth, hv_WindowHeight;//This procedure opens a new graphics window and adjusts the size//such that it fits into the limits specified by WidthLimit//and HeightLimit, but also maintains the correct image aspect ratio.////If it is impossible to match the minimum and maximum extent requirements//at the same time (f.e. if the image is very long but narrow),//the maximum value gets a higher priority,////Parse input tuple WidthLimitif (0 != (HTuple((hv_WidthLimit.TupleLength()) == 0).TupleOr(hv_WidthLimit < 0))){hv_MinWidth = 500;hv_MaxWidth = 800;}else if (0 != ((hv_WidthLimit.TupleLength()) == 1)){hv_MinWidth = 0;hv_MaxWidth = hv_WidthLimit;}else{hv_MinWidth = ((const HTuple&)hv_WidthLimit)[0];hv_MaxWidth = ((const HTuple&)hv_WidthLimit)[1];}//Parse input tuple HeightLimitif (0 != (HTuple((hv_HeightLimit.TupleLength()) == 0).TupleOr(hv_HeightLimit < 0))){hv_MinHeight = 400;hv_MaxHeight = 600;}else if (0 != ((hv_HeightLimit.TupleLength()) == 1)){hv_MinHeight = 0;hv_MaxHeight = hv_HeightLimit;}else{hv_MinHeight = ((const HTuple&)hv_HeightLimit)[0];hv_MaxHeight = ((const HTuple&)hv_HeightLimit)[1];}////Test, if window size has to be changed.hv_ResizeFactor = 1;GetImageSize(ho_Image, &hv_ImageWidth, &hv_ImageHeight);//First, expand window to the minimum extents (if necessary).if (0 != (HTuple(hv_MinWidth > hv_ImageWidth).TupleOr(hv_MinHeight > hv_ImageHeight))){hv_ResizeFactor = (((hv_MinWidth.TupleReal()) / hv_ImageWidth).TupleConcat((hv_MinHeight.TupleReal()) / hv_ImageHeight)).TupleMax();}hv_TempWidth = hv_ImageWidth * hv_ResizeFactor;hv_TempHeight = hv_ImageHeight * hv_ResizeFactor;//Then, shrink window to maximum extents (if necessary).if (0 != (HTuple(hv_MaxWidth < hv_TempWidth).TupleOr(hv_MaxHeight < hv_TempHeight))){hv_ResizeFactor = hv_ResizeFactor * ((((hv_MaxWidth.TupleReal()) / hv_TempWidth).TupleConcat((hv_MaxHeight.TupleReal()) / hv_TempHeight)).TupleMin());}hv_WindowWidth = hv_ImageWidth * hv_ResizeFactor;hv_WindowHeight = hv_ImageHeight * hv_ResizeFactor;//Resize windowSetWindowAttr("background_color", "black");OpenWindow(hv_Row, hv_Column, hv_WindowWidth, hv_WindowHeight, 0, "visible", "", &(*hv_WindowHandle));HDevWindowStack::Push((*hv_WindowHandle));if (HDevWindowStack::IsOpen())SetPart(HDevWindowStack::GetActive(), 0, 0, hv_ImageHeight - 1, hv_ImageWidth - 1);return;
}#ifndef NO_EXPORT_MAINint main(int argc, char* argv[])
{// Default settings used in HDevelop (can be omitted) SetSystem("use_window_thread", "true");int ret = 0;SetSystem("width", 512);SetSystem("height", 512);HObject  ho_Img5131;HTuple  hv_WindowHandle;ReadImage(&ho_Img5131, "D:/halcon_project/test3.jpg");dev_open_window_fit_image(ho_Img5131, 0, 0, -1, -1, &hv_WindowHandle);if (HDevWindowStack::IsOpen())ClearWindow(HDevWindowStack::GetActive());if (HDevWindowStack::IsOpen())DispObj(ho_Img5131, HDevWindowStack::GetActive());system("pause");#if defined(_WIN32)SetSystem("use_window_thread", "true");
#elif defined(__linux__)XInitThreads();
#endif#ifndef __APPLE__// action();
#elseret = apple_main(argc, argv);
#endifreturn ret;
}#endif#endif

配置环境

打开属性页,根据halcon安装的目录进行相应的配置

包含目录:

库目录

链接器-》常规-》附件库目录

输入-》附加依赖项 halconcpp.lib

编译后,点击

选择x64

运行成功

黑屏不显示图片添加这句代码

SetSystem("use_window_thread", "true");

http://www.dtcms.com/a/494591.html

相关文章:

  • Socket.IO 聊天应用实例
  • 首发即交付,智元精灵G2携均胜集团过亿订单落地
  • 网站建设需要步骤到哪里查网站备案信息
  • 哈尔滨网站制作哪里专业西安公司网站制作要多少钱
  • WPF中的DataTemplate
  • 浙江建设局网站泰安北京网站建设公司哪家好
  • TensorFlow2 Python深度学习 - 使用Dropout层解决过拟合问题
  • Python数据分析实战:基于5年地铁犯罪数据构建多维安全评估模型【数据集可下载】
  • YOLO系列——OpenCV DNN模块在YOLOv11检测物体时输出的边界框坐标问题
  • 网站地图怎么用wordpress发布文章添加新字段
  • OpenCV轻松入门_面向python(第六章 阈值处理)
  • Visual Studio 2017(VS2017)可以编译 OpenCV 4.5.5 为 32 位(x86)版本
  • 使用 Wireshark 进行 HTTP、MQTT、WebSocket 抓包的详细教程
  • 一个基于BiTCN-LSTM混合神经网络的时间序列预测MATLAB程序
  • 火是用什么做的视频网站wordpress贴吧主题
  • 团购网站开发网址交易网站
  • git revert commit和undo commit的区别
  • HTTP 协议的演进之路:从 1.1 到 3.0
  • 开源CICD工具Arbess,从安装到入门零基础指南
  • Maya动画基础:自动关键帧切换、曲线图编辑器、摄影机录制动画
  • Unreal5从入门到精通之一些有用的编辑器首选项
  • 深度解析:HTTP/2 与 HTTP/3 的适用场景与技术取舍
  • 三勾软件| 用SpringBoot+Element-UI+UniApp+Redis+MySQL打造的点餐连锁系统
  • 优化网站多少钱网站怎么做排查修复
  • 成都最好的网站推广优化公司学ui需要什么基础呢
  • 高并发系统性能测试:JMeter_Gatling 压测实战,测试场景设计与结果分析
  • 高并发体育直播平台架构实战:熊猫比分源码设计解析
  • 重庆网站建设开发wordpress哪里查看id
  • Docker下部署RocketMQ5.3.3
  • 桥田动态 | 多展位跨域协同,桥田快换盘持续赋能机器人“无界切换”