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

python版halcon环境配置

很久以前发过一篇python版halcon的使用方法.

可能有些地方没有说清楚,后台有人私信问我:"不装halcon怎样使用python调用halcon"

事实上前篇介绍的非常详细了,但是对初学者还是不够友好.

不废话,说步骤:首先系统win10 X64 22H2 安装python3.8.8 x64

安装python依赖包;安装halcon-python

pip install mvtec-halcon==24111

 接下来依赖的dll复制到py程序运行目录: 如图所示 我在程序运行目录兴新建了"dll"文件夹 所有依赖复制到这里了.

 可以看到有这么一句:  主要有用的是 import halcon as ha

但是不安装halcon只复制dll python在环境变量和本地运行环境找不到依赖所以会报错的.

你可以尝试 删掉

 sys.path.append("../DLL")
os.chdir(f'{os.getcwd()}/DLL') #切换工作路径
os.chdir(f'{os.getcwd()}/..') #切换工作路径

只保留import halcon as ha看看会怎样.

sys.path.append("../DLL")
os.chdir(f'{os.getcwd()}/DLL') #切换工作路径
import halcon as ha
os.chdir(f'{os.getcwd()}/..') #切换工作路径

一旦 import halcon as ha 不报错 

就可以开始验证其他的函数.

打开一个窗口能读取图像并显示就算环境正常:

下面给个简单例子:

r""""""import os,sys,time,cv2
#print(os.environ)
import numpy as np
from ctypes import *sys.path.append("../DLL")
os.chdir(f'{os.getcwd()}/DLL') #切换工作路径
import halcon as ha
os.chdir(f'{os.getcwd()}/..') #切换工作路径def cmd(s="pause"):os.system(s)
def open_window(width, height):if os.name == 'nt':ha.set_system('use_window_thread', 'true')return ha.open_window(row=0,column=0,width=width,height=height,father_window=0,mode='visible',machine='')if __name__ == "__main__":ha.set_system("backing_store", 'false')Image = ha.read_image('1.bmp')Width, Height = ha.get_image_size(Image)print(Width[0], Height[0])image_width  = Width[0]image_height = Height[0]image_width_half  = Width[0]/2image_height_half = Height[0]/2    pix = image_width*image_heightfillmode=['margin','fill']WindowHandle1 =open_window(image_width_half/3, image_height_half/3)ha.set_draw (WindowHandle1, fillmode[1])ha.set_line_width (WindowHandle1, 1)ha.set_color (WindowHandle1, 'red')thres = ha.threshold(Image, 140, 255)ha.disp_obj(thres, WindowHandle1);cmd()binimg=ha.region_to_bin(thres,255,0,image_width,image_height)ha.disp_obj(binimg, WindowHandle1);#ha.write_image (Image, 'bmp', 0, "GG")cmd()  

http://www.lryc.cn/news/573356.html

相关文章:

  • 59-Oracle 10046事件-知识准备
  • 1.23Node.js 中操作 mongodb
  • Django中为api自定义一些装饰器:如参数校验等
  • 获取 Git 仓库
  • npm包冲突install失败
  • 深入浅出:Go语言中的Cookie、Session和Token认证机制
  • Snapchat矩阵运营新策略:亚矩阵云手机打造高效社交网络
  • SiteAzure:解决数据库服务器内存频繁吃满
  • 【Flutter】状态管理框架Provider和Get对比分析(面试常用)
  • 57-Oracle SQL Profile(23ai)实操
  • 编程基础:耦合
  • 跨平台SEH实现的方法
  • Skrill是什么?中国用户能用吗?安全吗?完整指南
  • DAY 38 Dataset和Dataloader类
  • Python编程语言:2025年AI浪潮下的技术统治与学习红利
  • Python UDP Socket 实时在线刷卡扫码POS消费机服务端示例源码
  • 自动化立体仓库堆垛机控制系统STEP7 FC3功能块 I/O映射
  • `provide` 和 `inject` 组件通讯:实现跨组件层级通讯
  • 机器学习15-XGBoost
  • 微服务拆分——nacos/Feign
  • 华为云Flexus+DeepSeek征文 | 基于Flexus X实例的金融AI Agent开发:智能风控与交易决策系统
  • 李宏毅2025《机器学习》第三讲-AI的脑科学
  • 蓝牙数据通讯,实现内网电脑访问外网电脑
  • WPF调试三种工具介绍:Live Visual Tree、Live Property Explorer与Snoop
  • SylixOS 下的消息队列
  • Jupyter notebook调试:设置断点运行
  • Redis后端的简单了解与使用(项目搭建前置)
  • DeepEP开源MoE模型分布式通信库
  • 洛谷P3953 [NOIP 2017 提高组] 逛公园
  • 【DCS开源项目】—— Lua 如何调用 DLL、DLL 与 DCS World 的交互