第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

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

相关推荐
玩转单片机与嵌入式1 分钟前
TinyML应用场景解析:动作识别!
人工智能·单片机·嵌入式硬件·嵌入式ai·ai+嵌入式
量子-Alex2 分钟前
【大模型】EvoLM论文LLM训练各个阶段效果
人工智能·算法·机器学习
2401_827499994 分钟前
机器学习05(黑马)-决策树
人工智能·决策树·机器学习
wayz116 分钟前
Day 17:神经网络入门(MLP、激活函数、反向传播、优化器)
人工智能·深度学习·神经网络
逻辑君7 分钟前
认知神经科学研究报告【20260019】
人工智能·神经网络
sali-tec8 分钟前
C# 基于OpenCv的视觉工作流-章59-九点标定
图像处理·人工智能·opencv·计算机视觉
GISer_Jing8 分钟前
AI原生全栈架构理论体系:从分布式范式演进到全链路工程化理论基石
前端·人工智能·学习·ai编程
一只叫煤球的猫9 分钟前
别再把 Codex 念成“Code-X”,全错了,AI编程英语发音纠正
人工智能·面试·程序员
GISer_Jing11 分钟前
从“切图仔”到“增长架构师”:AI时代营销前端的范式革命
前端·人工智能·ai编程
lohiecan12 分钟前
国产自研开源新语言|梦丘 MOS-LANG 重磅登场!深耕 AI 编程与嵌入式生态
人工智能·junit