HALCON示例程序inspect_bga.hdev測量bga焊點缺陷

HALCON示例程序inspect_bga.hdev測量bga焊點缺陷

示例程序源碼(加注釋)

  • 關于顯示類函數解釋
    read_image (Image, ‘bga_14x14_model’)
    get_image_pointer1 (Image, Pointer, Type, Width, Height)
    dev_update_off ()
    dev_close_window ()
    dev_open_window (0, 0, Width, Height, ‘light gray’, WindowHandle)
    set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
    dev_set_part (0, 0, Height - 1, Width - 1)
    dev_display (Image)
    dev_set_line_width (1)
    dev_set_color (‘green’)
    VisualizeIntermediate := true

  • 快速二值化
    fast_threshold (Image, Region, 95, 255, 3)

  • 分割定義域
    connection (Region, ConnectedRegions)

  • 通過面積與長短軸比篩選區域
    select_shape (ConnectedRegions, SelectedRegions, [‘area’,‘anisometry’], ‘and’, [20,1.0], [100,1.7])

  • 使用矩形元素膨脹區域
    dilation_rectangle1 (SelectedRegions, RegionDilation, 3, 3)

  • 求取灰度重心
    area_center_gray (RegionDilation, Image, Volume, Row, Column)

  • 創建像素點表示的區域
    gen_region_points (RegionBGACenters, Row, Column)

  • 求取可旋轉最小外接矩形
    smallest_rectangle2 (RegionBGACenters, RowBGARect, ColumnBGARect, PhiBGARect, Length1BGARect, Length2BGARect)
    if (VisualizeIntermediate)
    dev_display (Image)
    dev_set_color (‘red’)
    dev_display (RegionBGACenters)
    dev_set_color (‘green’)
    dev_set_draw (‘margin’)
    gen_rectangle2 (BGARect, RowBGARect, ColumnBGARect, PhiBGARect, Length1BGARect, Length2BGARect)
    dev_display (BGARect)
    dev_set_draw (‘fill’)
    endif
    disp_message (WindowHandle, ‘Reference BGA’, ‘window’, 10, 10, ‘black’, ‘false’)
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()

  • 定義變量并初始化
    BallsPerRow := 14
    BallsPerCol := 14

  • 二維仿射變換
    BallDistCol := 2 * Length1BGARect / (BallsPerCol - 1)
    BallDistRow := 2 * Length2BGARect / (BallsPerRow - 1)
    hom_mat2d_identity (HomMat2DIdentity)

  • 旋轉
    hom_mat2d_rotate (HomMat2DIdentity, -PhiBGARect, RowBGARect, ColumnBGARect, HomMat2DRotate)

  • 移動
    hom_mat2d_translate (HomMat2DRotate, -RowBGARect + Length2BGARect, -ColumnBGARect + Length1BGARect, HomMat2DTranslate)

  • 縮放
    hom_mat2d_scale (HomMat2DTranslate, 1 / BallDistRow, 1 / BallDistCol, 0, 0, HomMat2DScale)

  • 對點進行仿射變換
    affine_trans_point_2d (HomMat2DScale, Row, Column, RowNormalized, ColNormalized)

  • round轉換為整數
    BGARowIndex := round(RowNormalized)
    BGAColIndex := round(ColNormalized)
    NumBalls := |Row|
    dev_set_color (‘black’)
    if (VisualizeIntermediate)
    dev_clear_window ()
    dev_set_draw (‘margin’)
    for i := 0 to NumBalls - 1 by 1

      繪十字線disp_cross (WindowHandle, 10 + BGARowIndex[i] * 10, 10 + BGAColIndex[i] * 10, 6, 0)
    

    endfor
    dev_set_draw (‘fill’)
    endif

  • gen_tuple_const生成常量數組
    BallMatrix := gen_tuple_const(BallsPerRow * BallsPerCol,-1)
    for i := 0 to NumBalls - 1 by 1
    BallMatrix[BGARowIndex[i] * BallsPerCol + BGAColIndex[i]] := i
    endfor
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()
    read_image (Image, ‘bga_14x14_defects’)
    dev_display (Image)
    disp_message (WindowHandle, ‘BGA to be checked’, ‘window’, 10, 10, ‘black’, ‘false’)
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()

  • 線面一段代碼和上邊創建模板時一樣
    fast_threshold (Image, Region, 95, 255, 3)
    connection (Region, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, [‘area’,‘anisometry’], ‘and’, [20,1.0], [100,1.7])
    dilation_rectangle1 (SelectedRegions, RegionDilation, 3, 3)
    area_center_gray (RegionDilation, Image, VolumeCheck, RowCheck, ColumnCheck)
    elliptic_axis_gray (RegionDilation, Image, RaCheck, RbCheck, PhiCheck)
    AnisometryCheck := RaCheck / RbCheck
    gen_region_points (RegionBGACenters, RowCheck, ColumnCheck)
    smallest_rectangle2 (RegionBGACenters, RowBGACheck, ColumnBGACheck, PhiBGACheck, Length1BGACheck, Length2BGACheck)
    if (VisualizeIntermediate)
    dev_display (Image)
    dev_set_color (‘red’)
    dev_display (RegionBGACenters)
    dev_set_color (‘green’)
    dev_set_draw (‘margin’)
    gen_rectangle2 (BGARect, RowBGACheck, ColumnBGACheck, PhiBGACheck, Length1BGACheck, Length2BGACheck)
    dev_display (BGARect)
    dev_set_draw (‘fill’)
    endif
    BallDistCol := 2 * Length1BGACheck / (BallsPerCol - 1)
    BallDistRow := 2 * Length2BGACheck / (BallsPerRow - 1)
    hom_mat2d_identity (HomMat2DIdentity)
    hom_mat2d_rotate (HomMat2DIdentity, -PhiBGACheck, RowBGACheck, ColumnBGACheck, HomMat2DRotate)
    hom_mat2d_translate (HomMat2DRotate, -RowBGACheck + Length2BGACheck, -ColumnBGACheck + Length1BGACheck, HomMat2DTranslate)
    hom_mat2d_scale (HomMat2DTranslate, 1 / BallDistRow, 1 / BallDistCol, 0, 0, HomMat2DScale)
    affine_trans_point_2d (HomMat2DScale, RowCheck, ColumnCheck, RowNormalized, ColNormalized)
    BGARowIndex := round(RowNormalized)
    BGAColIndex := round(ColNormalized)
    NumBalls := |RowCheck|
    dev_set_color (‘black’)
    if (VisualizeIntermediate)
    dev_clear_window ()
    dev_set_draw (‘margin’)
    for i := 0 to NumBalls - 1 by 1
    disp_cross (WindowHandle, 10 + BGARowIndex[i] * 10, 10 + BGAColIndex[i] * 10, 6, 0)
    endfor
    dev_set_draw (‘fill’)
    endif
    BallMatrixCheck := gen_tuple_const(BallsPerRow * BallsPerCol,-1)
    for i := 0 to NumBalls - 1 by 1
    BallMatrixCheck[BGARowIndex[i] * BallsPerCol + BGAColIndex[i]] := i
    endfor
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()
    Rows1 := gen_tuple_const(NumBalls,0)
    Cols1 := gen_tuple_const(NumBalls,0)
    Rows2 := gen_tuple_const(NumBalls,0)
    Cols2 := gen_tuple_const(NumBalls,0)
    Phi2 := gen_tuple_const(NumBalls,0)
    Ra2 := gen_tuple_const(NumBalls,0)
    Rb2 := gen_tuple_const(NumBalls,0)
    Anisometry2 := gen_tuple_const(NumBalls,0)
    Volume2 := gen_tuple_const(NumBalls,0)
    j := 0
    for i := 0 to BallsPerRow * BallsPerCol - 1 by 1
    if (BallMatrix[i] >= 0 and BallMatrixCheck[i] >= 0)
    Rows1[j] := Row[BallMatrix[i]]
    Cols1[j] := Column[BallMatrix[i]]
    Rows2[j] := RowCheck[BallMatrixCheck[i]]
    Cols2[j] := ColumnCheck[BallMatrixCheck[i]]
    Phi2[j] := PhiCheck[BallMatrixCheck[i]]
    Ra2[j] := RaCheck[BallMatrixCheck[i]]
    Rb2[j] := RbCheck[BallMatrixCheck[i]]
    Anisometry2[j] := AnisometryCheck[BallMatrixCheck[i]]
    Volume2[j] := VolumeCheck[BallMatrixCheck[i]]
    j := j + 1
    endif
    endfor

  • 從至少兩個點對應關系近似剛性仿射變換,即由旋轉和平移組成的變換
    vector_to_rigid (Rows1, Cols1, Rows2, Cols2, HomMat2D)
    affine_trans_point_2d (HomMat2D, Rows1, Cols1, RowTrans, ColumnTrans)
    affine_trans_point_2d (HomMat2D, Row, Column, RowTransFull, ColumnTransFull)
    if (VisualizeIntermediate)
    dev_clear_window ()
    for i := 0 to |Rows2| - 1 by 1
    * 通過元組元素生成XLD邊緣輪廓
    gen_contour_polygon_xld (Lines, [Rows2[i],RowTrans[i]], [Cols2[i],ColumnTrans[i]])
    dev_display (Lines)

    endfor
    endif

  • 兩個點之間的距離
    distance_pp (Rows2, Cols2, RowTrans, ColumnTrans, Distance)

  • 求取最大距離
    MaxDistance := max(Distance)

dev_display (Image)
dev_set_draw (‘margin’)
gen_empty_obj (EllipseCorrect)
gen_empty_obj (EllipseDeviation)
gen_empty_obj (EllipseDeformation)
gen_empty_obj (EllipseVolume)
gen_empty_obj (Missing)
dev_set_color (‘white’)
VolumeMean := mean(Volume)
VolumeMin := min(Volume)
VolumeMax := max(Volume)
VolumecheckMean := mean(VolumeCheck)
VolumeCheckMin := min(VolumeCheck)
VolumeCheckMax := max(VolumeCheck)
j := 0
for i := 0 to BallsPerRow * BallsPerCol - 1 by 1
if (BallMatrix[i] >= 0 and BallMatrixCheck[i] >= 0)
gen_ellipse (Ellipse, Rows2[j], Cols2[j], Phi2[j], Ra2[j], Rb2[j])
if (Distance[j] > 0.05)
concat_obj (EllipseDeviation, Ellipse, EllipseDeviation)
else
if (Anisometry2[j] > 1.2)
concat_obj (EllipseDeformation, Ellipse, EllipseDeformation)
else
if (Volume2[j] < 5500 or Volume2[j] > 10000)
concat_obj (EllipseVolume, Ellipse, EllipseVolume)
else
concat_obj (EllipseCorrect, Ellipse, EllipseCorrect)
endif
endif
endif
j := j + 1
else

    if (BallMatrix[i] >= 0)生成XLD十字線gen_cross_contour_xld (Cross, RowTransFull[BallMatrix[i]], ColumnTransFull[BallMatrix[i]], 10, 0.785398)concat_obj (Missing, Cross, Missing)endif
endif

endfor

dev_set_line_width (2)
dev_display (Image)
disp_message (WindowHandle, ‘White cross: segmentation of ball failed’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (Missing)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()

dev_display (Image)
disp_message (WindowHandle, ‘Ellipse: center positions deviate’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (EllipseDeviation)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()

dev_display (Image)
disp_message (WindowHandle, ‘Ellipse: deformed balls’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (EllipseDeformation)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()

dev_display (Image)
disp_message (WindowHandle, ‘Ellipse: gray value volume out of range’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (EllipseVolume)

處理思路

這個例子是主要講解了焊點完整性檢測。gen_region_points生成點區域;hom_mat2d_identity、hom_mat2d_rotate、hom_mat2d_translate、hom_mat2d_scale、affine_trans_point_2d、vector_to_rigid仿射變換; gen_contour_polygon_xld;繪制十字線distance_pp求取兩點距離。

后記

大家有什么問題可以向我提問哈,我看到了第一時間回復,希望在學習的路上多多結交良師益友。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/255121.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/255121.shtml
英文地址,請注明出處:http://en.pswp.cn/news/255121.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

怎樣屏蔽微信朋友圈視頻?局域網如何禁止員工看朋友圈視頻?

上班時間刷刷朋友圈&#xff0c;一眨眼半小時就過去了。不但會影響工作效率&#xff0c;而且朋友圈的視頻會占用大量的帶寬。所以對企業管理人員來說&#xff0c;很多時候需要禁止員工在工作時段刷朋友圈。但是行政手段要和技術手段配合&#xff0c;才可以發揮真正的作用。本文…

cf414B(dp)

題目鏈接&#xff1a;http://codeforces.com/problemset/problem/414/B 題意&#xff1a;定義所有元素是其前一個元素的倍數的數列為good sequence&#xff0c;給出 n, 和 k&#xff0c;求1....n組成的長度為k的good sequence 的數目&#xff1b; 思路&#xff1a;dp 用dp[i][j…

安裝IIS

安裝IIS過程中我們需要很多系統文件,這個時候我們就要下載一個非GHOST版本的系統安裝文件就可以了, 雨林木風安裝版8.0 http://dx.lwkb.com/setup/YlmF_XPSP3_YS8.0F/YlmF_XPSP3_YS8.0F.iso 這個不錯 轉載于:https://www.cnblogs.com/toSeeMyDream/p/5574884.html

深入理解C++的動態綁定和靜態綁定

為了支持c的多態性&#xff0c;才用了動態綁定和靜態綁定。理解他們的區別有助于更好的理解多態性&#xff0c;以及在編程的過程中避免犯錯誤。需要理解四個名詞&#xff1a;1、對象的靜態類型&#xff1a;對象在聲明時采用的類型。是在編譯期確定的。2、對象的動態類型&#x…

增量值編碼器、單圈絕對值編碼器、多圈絕對值編碼器

主流的伺服電機位置反饋元件包括增量值編碼器&#xff0c;單圈絕對值編碼器&#xff0c;多圈絕對值編碼器&#xff0c;旋轉變壓器等。下面分別介紹&#xff1a; 增量值編碼器增量式編碼器是將位移轉換成周期性的電信號&#xff0c;再把這個電信號轉變成計數脈沖&#xff0c;用…

HALCON示例程序inspect_bottle_mouth.hdev玻璃瓶口缺陷檢測

HALCON示例程序inspect_bottle_mouth.hdev玻璃瓶口缺陷檢測 示例程序源碼&#xff08;加注釋&#xff09; 定義變量并初始化 SmoothX : 501 ThresholdOffset : 25 MinDefectSize : 50 PolarResolution : 640 RingSize : 70 get_system (‘store_empty_region’, StoreEmptyReg…

靜態主席樹總結(靜態區間的k大)

靜態主席樹總結(靜態區間的&#xff4b;大) 首先我們先來看一道題 給定N個正整數構成的序列&#xff0c;將對于指定的閉區間查詢其區間內的第K小值。 輸入格式&#xff1a; 第一行包含兩個正整數N、M&#xff0c;分別表示序列的長度和查詢的個數。 第二行包含N個正整數&a…

Java中MySQL事務處理舉例

實例&#xff08;以sql語句中的insert語句為例&#xff09; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;/*** 事務的基本用法**/ …

永磁交流伺服電機的工作原理與更換新編碼器后的常規零位校正方法

http://wuhuotun.blog.163.com/blog/static/73085450200910655748516/ 永磁交流伺服電機的編碼器相位為何要與轉子磁極相位對齊 其唯一目的就是要達成矢量控制的目標&#xff0c;使d軸勵磁分量和q軸出力分量解耦&#xff0c;令永磁交流伺服電機定子繞組產生的電磁場始終正交于…

理解Java中字符流與字節流的區別

1. 什么是流 Java中的流是對字節序列的抽象&#xff0c;我們可以想象有一個水管&#xff0c;只不過現在流動在水管中的不再是水&#xff0c;而是字節序列。和水流一樣&#xff0c;Java中的流也具有一個“流動的方向”&#xff0c;通常可以從中讀入一個字節序列的對象被稱為輸入…

HALCON示例程序inspect_solar_fingers.hdev太陽能電池板電路缺陷檢測

HALCON示例程序inspect_solar_fingers.hdev太陽能電池板電路缺陷檢測 示例程序源碼&#xff08;加注釋&#xff09; 關于顯示類函數解釋 dev_update_off () dev_close_window () ImageName : ‘solar_cell/solar_cell_’ read_image (Image, ImageName ‘01’) dev_open_win…

C++多線程 例子

C多線程 例子2008-08-21 15:11//這是2個線程模擬賣火車票的小程序#include <windows.h>#include <iostream.h>DWORD WINAPI Fun1Proc(LPVOID lpParameter);//thread dataDWORD WINAPI Fun2Proc(LPVOID lpParameter);//thread dataintindex0;inttickets10;HANDLE hM…

2018/03/25

2019獨角獸企業重金招聘Python工程師標準>>> March 25 2018 Sunday Weather&#xff1a;cloudy 1、需求&#xff1a; a0.5 b3 ca*b 求c的值&#xff1a; [rootDasoncheng sbin]# cat a.sh #!/bin/bash a0.5 b3 cecho $a*$b |bc echo $canswer referred&#xff1a;…

統計字符串中每種字符類型的個數demo

/** 統計字符串中每中字符類型的個數&#xff0c;思路&#xff1a;* 1、鍵盤錄入一個字符串* 2、獲取到每個字符&#xff0c;遍歷字符串* for (int i 0; i < s.length(); i) {char ch s.charAt(i);* 3、判斷每個字符屬于哪種類型&#xff0c;對應的個數*/package cn.strin…

css3 圖片放大縮小閃爍效果

直接把圖片替換就可以了&#xff0c;我的圖片是透明的&#xff0c;所以body設置為黑色的&#xff0c;不不要可以去掉 <!doctype html><html lang"en"><head> <meta charset"UTF-8"> <title>css3 圖片放大縮小閃爍效果</t…

HALCON示例程序max_connection.hdev確定分割區域的最大區域數目

HALCON示例程序max_connection.hdev確定分割區域的最大區域數目 示例程序源碼&#xff08;加注釋&#xff09; read_image (Image, ‘monkey’) get_system (‘max_connection’, Information) set_system (‘max_connection’, 0) threshold (Image, Region, 128, 255) 區域…

elasticsearch分詞聚合查詢demo

2019獨角獸企業重金招聘Python工程師標準>>> 我們在通過elasticsearch查詢text類型的字段時&#xff0c;我們使用aggs進行聚合某個text類型field。這時elasticsearch會自動進行分詞將分詞后的結果進行聚合。獲取每一個分詞出現在文檔的文檔個數。注意&#xff1a;是…

軟件工程進度條-第十五周

第十五周 所花時間&#xff08;包括上課&#xff09; 23 代碼量&#xff08;行&#xff09; 1200 博客量&#xff08;篇&#xff09; 6 了解到的知識點 1、了解ListView的基本用法&#xff0c;并改變焦點觸碰事件&#xff1b; 2、理解團隊開發后進行軟件項目總結的益處…

Spring實戰第七章

一、SpringMVC配置代替方案 1自定DispatcherServlet 按照AbstractAnnotationConfigDispatcherServletInitializer的定義&#xff0c;它會創建DispatcherServlet和ContextLoaderListener。 AbstractAnnotationConfigDispatcherServletInitializer有三個方法是必須要重載的abstra…

EPSON TCP/IP 通信

EPSON SCARA機器人TCP/IP 通信時&#xff0c;涉及到的相關指令說明。 14.3 TCP/IP命令。 OpenNet //打開TCP/IP端口。 ChkNet //返回端口狀態&#xff1a;等待讀取的字節數或錯誤條件。 CloseNet //關閉TCP/IP端口。 SetNet //運行時或從命令窗口中設置通信端…