1):安装halocn包:pip install mvtec-halcon==20111
2):导入halcon包。一般使用import halcon as ha
3):根据官方示例:
下面的代码使用framegrabber获取图像序列的第一个图像,并以一种特定的方式显示该图
framegrabber = ha.open_framegrabber(
name='File',
horizontal_resolution=1,
vertical_resolution=1,
image_width=0,
image_height=0,
start_row=0,
start_column=0,
field='default',
bits_per_channel=-1,
color_space='default',
generic=-1,
external_trigger='default',
camera_type='board/board.seq',
device='default',
port=1,
line_in=-1
)
img = ha.grab_image(framegrabber)
width, height = ha.get_image_size_s(img)
window = ha.open_window(
row=0,
column=0,
width=width,
height=height,
father_window=0,
mode='visible',
machine=''
)
ha.disp_obj(img, window)
framegrabber参数设置可以参照halcon20.11中的设置
4)示例:正常取图
VSCode中不加wait_seconds函数显示窗口一闪而过,啥也看不到,在Python自己的IDLE里面显示窗口可以停留,原因暂时未知)