halcon 學習筆記


1、HsmartWindow 報錯問題

2、HwindowCtronl繪制圖形未結束又點擊繪制導致錯誤

3、論壇轉貼 常見問題

4、找圓找線部分參數設置

 5、實現基於形狀的模板匹配

6、一維測量-卡尺

 7、直線/圓擬合

 

 

 

 

----------------------------------------------------------------

 1-- HsmartWindow 控件除了會調用halcondonet.dll外還會調用halcon.dll,如果程序根目錄不存在halcon.dll,則會通過全局變量找到halcon mevtec目錄去調用,這樣是沒有問題的;

如果根目錄下存在halcon.dll,則會優先調用根目錄下的文件,然后halcon.dll內部如果使用到HsmartWindow的功能,則還會調用一個Hcanvas.dll的文件,如果根目錄下沒有這個文件則會報錯,程序編譯后啟動過程中報錯,

報錯內容為:

 

----------------------------------------------------------------------------------

2-   HsmartWindow不支持Draw開頭的函數,只能在Hwindow上面畫,在執行Draw函數的時候,程序停在該函數位置,未點擊鼠標右鍵確認Draw Region之前,程序會一直停留,此時再執行其他的Draw函數,就會導致在整個流程亂掉,避免這種情況的方法是在每個Draw函數之前都調用一次HalconApi.CancelDraw()函數,結束上次未完成的繪制。

 

 

--------------------------------------------------------------------

 3--以下引用ihalcon學習網上帖子《轉“Halcon基本問題解答”》

http://www.ihalcon.com/read-4666.html

----------------------------------------------------------
2. 裁剪圖像;從圖像上截取某段圖像進行保存。如何實現該操作 ?


首先應該知道,region不具有單獨構成圖像的要素,他沒有灰度值。有用過opencv的應該知道 ROI(感興趣區域),設置好它后,對圖像的大部分操作就轉為 圖像的一個矩形區域內進行。類似的,halcon有domain 概念。 首先 設置好一個矩形區,然后使用 reduce_domain(是一個矩形區域)后,再使用crop_domain 就裁剪出圖像。

----------------------------------------------------------------------------

25. 屏幕/窗口截圖 。


使用dump_window_image 保存對應窗口截圖,截圖為當前肉眼所見圖像,包括已經繪制到圖像上的region,xld等。

 

-------------------------------------------------------------------------------

31.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--  找圓找線工具,部分參數設置詳解

https://www.cnblogs.com/cumt-cwp/p/9713106.html

 

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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM