初学halcon,遇到的dev_open_window的问题

本文记录了作者初次使用halcon进行CNC工件角度检测时遇到的dev_open_window问题。在尝试使用halcon软件和通过gcc编译halcon生成的Linux程序时,发现窗口与图像大小不匹配导致图像显示异常。通过将dev_open_window函数改为dev_open_window_fit_size,成功解决了图像匹配问题。
部署运行你感兴趣的模型镜像

第一次接触halcon,想使用halcon检测CNC工件的角度

如下图所示的工件


这是我在halcon软件中直接运行时得到的摄像头反馈的视频图像

这是我使用的代码

* Image Acquisition 01: Code generated by Image Acquisition 01
dev_update_window ('off')
dev_close_window()
open_framegrabber ('Video4Linux2', 640, 480, 0, 0, 0, 0, 'progressive', 8, 'gray', -1, 'false', 'auto', 'default', 0, -1, AcqHandle)
dev_open_window_fit_size (0, 0, 640, 480, 'black', WindowHandle)
grab_image_start (AcqHandle, -1)
while (true)
    grab_image_async (Image, AcqHandle, -1)
    dev_display (Image)
    * Image Acquisition 01: Do something
endwhile
close_framegrabber (AcqHandle)


这是使用gcc编译器将halcon导出的c代码编译成Linux下可执行的程序,但是运行后得到的视频图像却是如下图所示:


看出来是窗口大小和图像大小不一致导致的图像匹配问题。但是新建窗口和图像时定义的是同样的大小,没看出问题所在。

之后将dev_open_window改为dev_open_window_fit_size后问题解决。

更改之后的代码

* Image Acquisition 01: Code generated by Image Acquisition 01
dev_update_window ('off')
dev_close_window()
open_framegrabber ('Video4Linux2', 640, 480, 0, 0, 0, 0, 'progressive', 8, 'gray', -1, 'false', 'auto', 'default', 0, -1, AcqHandle)
dev_open_window_fit_size (0, 0, 640, 480, -1, -1, WindowHandle)
grab_image_start (AcqHandle, -1)
while (true)
    grab_image_async (Image, AcqHandle, -1)
    dev_display (Image)
    * Image Acquisition 01: Do something
endwhile
close_framegrabber (AcqHandle)

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值