计算机视觉 目标检测 机器学习 人工智能 识别和测量引脚(可能是电子元件的引脚)的长度、宽度和间距 - ) disp_message (WindowHandle, &#39

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力平台 👁️ 289 次阅读

计算机视觉 目标检测 机器学习 人工智能 识别和测量引脚(可能是电子元件的引脚)的长度、宽度和间距

这段代码是一个用于图像分析和测量的脚本,它主要解决的问题是在一个图像中识别和测量引脚(可能是电子元件的引脚)的长度、宽度和间距

read_image (Image, ‘ic_pin’) get_image_pointer1 (Image, Pointer, Type, Width, Height) dev_close_window () dev_open_window_fit_image (Image, 0, 0, 509, 509, WindowHandle) set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’) dev_display (Image) dev_set_draw (‘margin’) dev_set_line_width (3) *

Define and display the rectangular ROIs within which the edges will be detected Row := 55 RowBottom := 955 Column := 200 Phi := rad(-90) Length1 := 50 Length2 := 35 dev_set_color (‘gray’) gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2) gen_rectangle2 (Rectangle, RowBottom, Column, Phi, Length1, Length2) disp_continue_message (WindowHandle, ‘black’, ‘true’) stop ()Create a measure object for the ROI at the top of the image. Interpolation := ‘nearest_neighbor’ gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, Interpolation, MeasureHandle)Determine all edges and calculate the lead height at the top of the image Sigma := 1.0 Threshold := 30 Transition := ‘all’ Select := ‘all’ measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance) LeadLength1 := DistanceDisplay the results dev_set_color (‘white’) disp_line (WindowHandle, RowEdge, ColumnEdge - Length2, RowEdge, ColumnEdge + Length2) disp_message (WindowHandle, ‘Lead Length: ’ + LeadLength1$’.2f’, ‘window’, RowEdge[1] + 40, ColumnEdge[1] + 100, ‘yellow’, ‘false’)Shift the measure object and determine the lead height at the bottom of the image translate_measure (MeasureHandle, RowBottom, Column) measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance) LeadLength2 := DistanceDisplay the results dev_set_color (‘white’) disp_line (WindowHandle, RowEdge, ColumnEdge - Length2, RowEdge, ColumnEdge + Length2) disp_message (WindowHandle, ‘Lead Length: ’ + LeadLength2$’.2f’, ‘window’, RowEdge[1] - 120, ColumnEdge[1] + 100, ‘yellow’, ‘false’)Close the measure close_measure (MeasureHandle) disp_continue_message (WindowHandle, ‘black’, ‘true’) stop ()Now, define and display a rectangular ROI perpendicular to the leads and create the measure dev_display (Image) Row := 47 Column := 485 Phi := 0 Length1 := 420 Length2 := 8 Interpolation := ‘nearest_neighbor’ dev_set_color (‘black’) gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2) gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, Interpolation, MeasureHandle)Determine all edge pairs that have a negative transition, i.e., edge pairsthat enclose dark regions. Sigma := 1.0 Threshold := 30 Transition := ‘negative’ Select := ‘all’ measure_pairs (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance) disp_continue_message (WindowHandle, ‘black’, ‘true’) stop () dev_set_color (‘white’) disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond) avgLeadWidth := sum(IntraDistance) / |IntraDistance| avgLeadDistance := sum(InterDistance) / |InterDistance| numLeads := |IntraDistance| disp_message (WindowHandle, ‘Number of Leads: ’ + numLeads, ‘window’, 200, 100, ‘yellow’, ‘false’) disp_message (WindowHandle, ‘Average Lead Width: ’ + avgLeadWidth

′

.

2

f

′

,

′

w

i

n

d

o

w

′

,

260

,

100

,

′

y

e

l

l

o

w

′

,

′

f

a

l

s

e

′

)

d

i

s

p

m

e

s

s

a

g

e

(

W

i

n

d

o

w

H

a

n

d

l

e

,

′

A

v

e

r

a

g

e

L

e

a

d

D

i

s

t

a

n

c

e

:

′

+

a

v

g

L

e

a

d

D

i 拼多多帮助力入口

s

t

a

n

c

e

'.2f', 'window', 260, 100, 'yellow', 'false') disp_message (WindowHandle, 'Average Lead Distance: ' + avgLeadDistance

′.2f′,′window′,260,100,′yellow′,′false′)dispm​essage(WindowHandle,′AverageLeadDistance:′+avgLeadDistance’.2f’, ‘window’, 320, 100, ‘yellow’, ‘false’) disp_continue_message (WindowHandle, ‘black’, ‘true’) disp_continue_message (WindowHandle, ‘black’, ‘true’) stop ()Zoom in to visualize the measurement results in more detail.First, define and display the zoom window. Row1 := 0 Column1 := 600 Row2 := 100 Column2 := 700 dev_set_color (‘blue’) disp_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2) disp_continue_message (WindowHandle, ‘black’, ‘true’) stop ()Then, zoom the image and display the results. dev_set_part (Row1, Column1, Row2, Column2) dev_display (Image) dev_set_color (‘black’) dev_display (Rectangle) p_disp_edge_marker (RowEdgeFirst, ColumnEdgeFirst, Phi, 5, ‘white’, 3, WindowHandle) p_disp_edge_marker (RowEdgeSecond, ColumnEdgeSecond, Phi, 5, ‘white’, 3, WindowHandle)Close the measure close_measure (MeasureHandle)Reset the display parameters. dev_set_part (0, 0, Height - 1, Width - 1) dev_set_draw (‘fill’) dev_set_line_width (1)

程序运行结果:

以下是代码的主要步骤和功能:

图像读取和窗口设置:

read_image 读取名为 ‘ic_pin’ 的图像文件。 dev_open_window_fit_image 根据图像大小打开一个窗口。 set_display_font 设置窗口中显示文本的字体和样式。 定义和显示感兴趣区域(ROI):

通过 gen_rectangle2 函数定义两个矩形区域,这些区域用于检测图像中的边缘。 创建测量对象并测量引脚长度:

gen_measure_rectangle2 创建一个测量对象,用于测量矩形区域内的边缘。 measure_pos 函数用于测量边缘的位置,计算引脚的长度。 结果显示:

disp_line 在窗口中绘制测量线。 disp_message 在窗口中显示测量结果,如引脚长度。 移动测量对象并测量底部引脚长度:

translate_measure 将测量对象移动到图像的底部。 重复测量过程,显示底部引脚的长度。 定义并测量引脚之间的宽度和间距:

定义一个新的矩形区域,垂直于引脚。 measure_pairs 测量引脚之间的边缘对,计算引脚的宽度和间距。 结果显示:

显示引脚数量、平均宽度和平均间距。 放大显示测量结果:

定义一个放大窗口,用于更详细地查看测量结果。 dev_set_part 设置窗口的显示区域。 dev_display 显示放大后的图像和测量标记。 清理和重置显示参数:

close_measure 关闭测量对象。 dev_set_part 重置显示区域为整个图像。 dev_set_draw 和 dev_set_line_width 重置绘制样式。 代码中注释掉的部分(以 * 开头的行)表示这些行在执行时被忽略,不会影响程序的运行。这些注释可能是用于说明代码的功能或作为备选方案。

总的来说,这段代码通过图像分析和测量工具,能够自动化地测量电子元件引脚的长度、宽度和间距,这对于电子元件的质量控制和制造过程非常有用。

计算机视觉 目标检测 机器学习 人工智能 识别和测量引脚(可能是电子元件的引脚)的长度、宽度和间距

推荐文章

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧