python中halcon環(huán)境配置的詳細步驟
很久以前發(fā)過一篇python版halcon的使用方法.
可能有些地方?jīng)]有說清楚,后臺有人私信問我:"不裝halcon怎樣使用python調用halcon"
事實上前篇介紹的非常詳細了,但是對初學者還是不夠友好.
不廢話,說步驟:首先系統(tǒng)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在環(huán)境變量和本地運行環(huán)境找不到依賴所以會報錯的.
你可以嘗試 刪掉
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 不報錯
就可以開始驗證其他的函數(shù).
打開一個窗口能讀取圖像并顯示就算環(huán)境正常:
下面給個簡單例子:
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]/2
image_height_half = Height[0]/2
pix = image_width*image_height
fillmode=['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() 到此這篇關于python中halcon環(huán)境配置的詳細步驟的文章就介紹到這了,更多相關python halcon環(huán)境配置內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Django利用LogEntry生成歷史操作實戰(zhàn)記錄
LogEntry是在后臺開發(fā)中經(jīng)常用到的模塊,它在admin是默認開啟的。文中給大家介紹了在admin頁面上查看操作日志的方法及實戰(zhàn)代碼,感興趣的朋友跟隨小編一起看看吧2021-12-12
Python數(shù)據(jù)分析之使用scikit-learn構建模型
這篇文章主要介紹了Python數(shù)據(jù)分析之使用scikit-learn構建模型,sklearn提供了model_selection模型選擇模塊、preprocessing數(shù)據(jù)預處理模塊、decompisition特征分解模塊,更多相關內容需要朋友可以參考下面文章內容2022-08-08
pymssql數(shù)據(jù)庫操作MSSQL2005實例分析
這篇文章主要介紹了pymssql數(shù)據(jù)庫操作MSSQL2005的方法,可實現(xiàn)基本的連接、查詢、插入、更新及調用存儲過程等功能,非常具有實用價值,需要的朋友可以參考下2015-05-05

