halcon学习笔记
1、HsmartWindow 报错问题
2、HwindowCtronl绘制图形未结束⼜点击绘制导致错误
3、论坛转贴常见问题
4、圆线部分参数设置
5、实现基于形状的模板匹配
6、⼀维测量-卡尺
7、直线/圆拟合
----------------------------------------------------------------
 1-- HsmartWindow 控件除了会调⽤halcondonet.dll外还会调⽤halcon.dll,如果程序根⽬录不存在halcon.dll,则会通过全局变量到halcon mevtec⽬录去调⽤,这样是没有问题的;
rectangle函数opencv如果根⽬录下存在halcon.dll,则会优先调⽤根⽬录下的⽂件,然后halcon.dll内部如果使⽤到HsmartWindow的功能,则还会调⽤⼀个Hcanvas.dll的⽂件,如果根⽬录下没有这个⽂件则会报错,程序编译后启动过程中报错,
报错内容为:
----------------------------------------------------------------------------------
2-  HsmartWindow不⽀持Draw开头的函数,只能在Hwindow上⾯画,在执⾏Draw函数的时候,程序停在该函数位置,未点击⿏标右键确认Draw Region之前,程序会⼀直停留,此时再执⾏其他的Draw函数,就会导致在整个流程乱掉,避免这种情况的⽅法是在每个Draw函数之前都调⽤⼀次HalconApi.CancelDraw()函数,结束上次未完成的绘制。
--------------------------------------------------------------------
3--以下引⽤ihalcon学习⽹上帖⼦《转“Halcon基本问题解答”》
----------------------------------------------------------
2. 裁剪图像;从图像上截取某段图像进⾏保存。如何实现该操作?
⾸先应该知道,region不具有单独构成图像的要素,他没有灰度值。有⽤过opencv的应该知道 ROI(感兴趣区域),设置好它后,对图像的⼤部分操作就转为图像的⼀个矩形区域内进⾏。类似的,halcon有domain 概念。⾸先设置好⼀个矩形区,然后使⽤ reduce_domain(是⼀个矩形区域)后,再使⽤crop_domain 就裁剪出图像。
----------------------------------------------------------------------------
25. 屏幕/窗⼝截图。
使⽤dump_window_image 保存对应窗⼝截图,截图为当前⾁眼所见图像,包括已经绘制到图像上的region,xld等。
-------------------------------------------------------------------------------
Halcon绘制有paint和overpaint,区别是overpaint是绘制⾃⾝,paint输出可以是其他图像。
-------------------------------------------------------------------------------------------------------------------------
36.遍历⽂件夹,读取指定格式⽂件/图像。
* 遍历⽂件夹D:/资料库/Downloads
list_files ('D:/资料库/Downloads', ['files','follow_links'], ImageFiles)
* 筛选bmp或jpg格式的⽂件
tuple_regexp_select (ImageFiles, ['\\.(bmp|jpg)$','ignore_case'], ImageFiles)
--------------------------------------------------------------------------------------------------
39.halcon⾥⾯有没有检测条码质量分析的算⼦?
条码质量评测算⼦为 get_bar_code_result 。参见⽰例 print_quality_isoiec15416.hdev 。
------------------------------------------------------------
4--  圆线⼯具,部分参数设置详解
5-halcon实现模板匹配
reduce_domain (Image, Rectangle, ImageReduced)
create_shape_model (ImageReduced, 4, 0, rad(360), rad(1), 'none', 'use_polarity', 30, 10, ModelID)
//显⽰模板
get_shape_model_contours (ShapeModel, ModelID, 1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, Row, Column, HomMat2DTranslate)
affine_trans_contour_xld (ShapeModel, ShapeModelTrans, HomMat2DTranslate)
//寻模板
find_shape_model (ImageCheck, ModelID, 0, rad(360), 0.7, 1, 0.5, 'least_squares', 4, 0.7, RowCheck, ColumnCheck, AngleCheck, Score)
count_seconds (S2)
dev_display (ImageCheck)
if (|Score| > 0)
dev_set_color ('green')
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, RowCheck, ColumnCheck, HomMat2DTranslate)
hom_mat2d_rotate (HomMat2DTranslate, AngleCheck, RowCheck, ColumnCheck, HomMat2DRotate)
affine_trans_contour_xld (ShapeModel, ShapeModelTrans, HomMat2DRotate)
6-⼀维测量-卡尺
gen_measure_rectangle2 (Rect1Row, Rect1Col, RectPhi, RectLength1, RectLength2, Width, Height, 'bilinear', MeasureHandle1) measure_pos()
6-直线/圆拟合
* Create the metrology model data structure
create_metrology_model (MetrologyHandle)
* The image size is set in advance to speed up the
* first call of apply_metrology_model.
set_metrology_model_image_size (MetrologyHandle, Width, Height)
* Create two metrology line objects and set parameters
add_metrology_object_line_measure (MetrologyHandle, LineRow1, LineColumn1, LineRow2, LineColumn2, Tolerance, 10, 1, 20, [], [], Index1) set_metrology_model_param (MetrologyHandle, 'reference_system', [Rows[0],Columns[0],0])
* Use the top of the diamond to align the metrology model in
* the current image
*
align_metrology_model (MetrologyHandle, Rows[0], Columns[0], 0)
*
*
* Perform the measurement for both lines in one call
*
apply_metrology_model (Image, MetrologyHandle)
*
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', LineParameter)
get_metrology_object_result_contour (ResultContour, MetrologyHandle, 'all', 'all', 1.5)
get_metrology_object_measures (Contour, MetrologyHandle, 'all', 'all', MRow, MColumn)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。