第8篇 QT联合halcon12在vs2019搭建环境开发图像处理

QT联合halcon12在vs2019开发图像处理

示范如何把图像中矩形单个抠出来,优先在Hdevelop处理

参考:

https://txwtech.blog.csdn.net/article/details/150425073

处理完成后

halcon代码如下:

复制代码
* Matching 02: BEGIN of generated code for model initialization
set_system ('border_shape_models', 'false')
* Matching 02: Obtain the model image
read_image (Image, 'D:/halcon_project/20250815154346a.jpg')
* Matching 02: build the ROI from basic regions
gen_rectangle1 (ModelRegion, 237.855, 379.686, 284.475, 426.199)
* Matching 02: reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
* Matching 02: create the shape model
create_shape_model (TemplateImage, 4, rad(0), rad(360), rad(2.0161), ['none','no_pregeneration'], 'use_polarity', [10,14,4], 4, ModelId)
* Matching 02: get the model contour for transforming it later into the image
get_shape_model_contours (ModelContours, ModelId, 1)
* Matching 02: END of generated code for model initialization
* Matching 02: BEGIN of generated code for model application
* Matching 02: the following operations are usually moved into
* Matching 02: that loop where the aquired images are processed
* Matching 02: Find the model
find_shape_model (Image, ModelId, rad(0), rad(360), 0.5, 186, 0.5, 'least_squares', [4,1], 0.75, ModelRow, ModelColumn, ModelAngle, ModelScore)
* Matching 02: transform the model contours into the detected positions
for MatchingObjIdx := 0 to |ModelScore| - 1 by 1
    hom_mat2d_identity (HomMat)
    hom_mat2d_rotate (HomMat, ModelAngle[MatchingObjIdx], 0, 0, HomMat)
    hom_mat2d_translate (HomMat, ModelRow[MatchingObjIdx], ModelColumn[MatchingObjIdx], HomMat)
    affine_trans_contour_xld (ModelContours, TransContours, HomMat)
    dev_display (TransContours)
    
    gen_rectangle1 (ModelRegion, ModelRow[MatchingObjIdx]-19, ModelColumn[MatchingObjIdx]-19, ModelRow[MatchingObjIdx]+19, ModelColumn[MatchingObjIdx]+19)
* Matching 15: reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage) //截取图片
crop_domain (TemplateImage, ImagePart) //去除黑色区域
write_image (ImagePart, 'jpg', 0, MatchingObjIdx +'.jpg') //写入文件
endfor
* Matching 02: Clear model when done
clear_shape_model (ModelId)
* Matching 02: END of generated code for model application

练习图片:

导出c++代码

生成了test3a.cpp

打开test3a.cpp,复制void action()里面所有内容

粘贴到vs2019 qt项目的cpp文件里面


修改void action()为:void QtWidgetsApplication6::action()


头文件添加:

cpp文件添加:

#include "HalconCpp.h"

using namespace HalconCpp;

函数放在程序启动时运行:

添加action()

项目-》属性,包含halcon12安装目录(找到自己安装的位置,复制路径)

包含对应的库目录

链接器-》输入,添加halconcpp.lib

选择x64

编译生成后,点击本地调试器查看效果

相关推荐
John_ToDebug6 分钟前
2025年度个人总结:在技术深海中锚定价值,于时代浪潮中重塑自我
人工智能·程序人生
自可乐17 分钟前
n8n全面学习教程:从入门到精通的自动化工作流引擎实践指南
运维·人工智能·学习·自动化
king of code porter21 分钟前
百宝箱企业版搭建智能体应用-创建应用
人工智能·大模型·智能体
HDO清风26 分钟前
CASIA-HWDB2.x 数据集DGRL文件解析(python)
开发语言·人工智能·pytorch·python·目标检测·计算机视觉·restful
策知道32 分钟前
依托政府工作报告准备省考【经验贴】
大数据·数据库·人工智能·搜索引擎·政务
工程师老罗43 分钟前
Pytorch如何加载和读取VOC数据集用来做目标检测?
人工智能·pytorch·目标检测
测试_AI_一辰44 分钟前
Agent & RAG 测试工程05:把 RAG 的检索过程跑清楚:chunk 是什么、怎么来的、怎么被命中的
开发语言·人工智能·功能测试·自动化·ai编程
Henry-SAP1 小时前
SAP(ERP) 组织结构业务视角解析
大数据·人工智能·sap·erp·sap pp
龙腾亚太1 小时前
航空零部件加工变形难题破解:数字孪生 + 深度学习的精度控制实战
人工智能·深度学习·数字孪生·ai工程师·ai证书·转型ai
Coding茶水间1 小时前
基于深度学习的输电电力设备检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
开发语言·人工智能·深度学习·yolo·目标检测·机器学习