Halcon-1D测量

代码如下

*/ main
dev_close_window ()
read_image (Image, 'board/board-06')
get_image_size(Image,Width, Height)
dev_open_window(0,0,Width, Height, 'black', WindowHandle)
dev_display(Image)
stop()

Row1 := 305.5  // 矩形中心y值坐标
Col1 := 375.5  // 矩形中心x值坐标
Phi1 := 0.982  // 角度
Length1 := 167 // 长度1(半长)
Length2 := 8   // 长度2(半长)

* 垂直与矩形的直线边缘的提取
gen_measure_rectangle2(Row1, Col1, Phi1, Length1, Length2, Width, Height,'nearest_neighbor',MeasureHandle1)

Row2 := 188.5  // 矩形中心y值坐标
Col2 := 202.5  // 矩形中心x值坐标
Phi2 := Phi1-rad(180)  // 角度
gen_measure_rectangle2(Row2, Col2, Phi2, Length1, Length2, Width, Height,'nearest_neighbor',MeasureHandle2)


*/ 通过2个点创建一个函数
create_funct_1d_pairs([0.0, 0.3],[1.0,0.0],FuzzyAbsSizeDiffFunction) // 从(X,Y)集合中创建一个函数
*/ 为边缘对定义一个归一化的fuzzy函数。
set_fuzzy_measure_norm_pair(MeasureHandle1, 11.0, 'size_abs_diff', FuzzyAbsSizeDiffFunction)
set_fuzzy_measure_norm_pair(MeasureHandle2, 11.0, 'size_abs_diff', FuzzyAbsSizeDiffFunction) 


*/ 提取垂直于矩形或环形圆弧的直边对
fuzzy_measure_pairs(Image, MeasureHandle1, 1, 30,0.5,'positive',RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, RowEdgeCenter, ColumnEdgeCenter, FuzzyScore, IntraDistance, InterDistance)
fuzzy_measure_pairs(Image, MeasureHandle2,1, 30, 0.5, 'all', RowEdgeFirst1, ColumnEdgeFirst1, AmplitudeFirst1, RowEdgeSecond1, ColumnEdgeSecond1, AmplitudeSecond1, RowEdgeCenter1, ColumnEdgeCenter1, FuzzyScore1, IntraDistance1, InterDistance1)

*/ 可视化
dev_display(Image)
dev_display_measure_object (Row1, Col1, Phi1, Length1, Length2)//显示尺寸物体
dev_display_measure_object (Row2, Col2, Phi2, Length1, Length2)//显示尺寸物体

dev_set_draw ('fill')
Pin := 1
dev_display_profile_points ([RowEdgeFirst1,RowEdgeSecond1], [ColumnEdgeFirst1,ColumnEdgeSecond1], Row1, Col1, Phi1, Length1, Length2)
for I := 0 to |ColumnEdgeFirst1| - 1 by 1
    disp_message (WindowHandle, 'size:' + IntraDistance1[I]$'.2f' + ' score:' + FuzzyScore1[I]$'.2f', 'image', RowEdgeSecond1[I], ColumnEdgeSecond1[I] + 10, 'yellow', 'false')
    MRow := RowEdgeSecond1[I] - 5
    MCol := ColumnEdgeSecond1[I] - 20
    dev_set_color ('white')
    gen_circle (Circle, MRow, MCol, 10)
    dev_display (Circle)
    get_string_extents (WindowHandle, Pin, Ascent, Descent, SWidth, SHeight)
    disp_message (WindowHandle, Pin, 'window', MRow - SHeight / 2, MCol - SWidth / 2, 'black', 'false')
    Pin := Pin + 1
endfor

stop ()
* dev_display_measure_object
RowStart := Row + sin(Phi) * Length1
RowEnd := Row - sin(Phi) * Length1
ColStart := Col - cos(Phi) * Length1
ColEnd := Col + cos(Phi) * Length1
drow := sin(rad(90) - Phi) * Length2
dcol := cos(rad(90) - Phi) * Length2
gen_contour_polygon_xld (Contour, [RowStart - drow,RowEnd - drow,RowEnd + drow,RowStart + drow,RowStart - drow], [ColStart - dcol,ColEnd - dcol,ColEnd + dcol,ColStart + dcol,ColStart - dcol])
dev_set_line_width (2)
dev_set_color ('green')
dev_display (Contour)
dev_display_profile_line (Row, Col, Phi, Length1, Length2)

return ()
*/ dev_display_profile_line
ArrowAngle := rad(45) / 2
ArrowLength := Length1 * 0.2
PSize := Length2 * 0.2
RowStart := Row + sin(Phi) * Length1
RowEnd := Row - sin(Phi) * Length1
ColStart := Col - cos(Phi) * Length1
ColEnd := Col + cos(Phi) * Length1
gen_contour_polygon_xld (CProfile, [RowStart,RowEnd], [ColStart,ColEnd])
gen_contour_polygon_xld (CArrow, [RowEnd - sin(ArrowAngle - Phi) * ArrowLength,RowEnd,RowEnd + sin(ArrowAngle + Phi) * ArrowLength], [ColEnd - cos(ArrowAngle - Phi) * ArrowLength,ColEnd,ColEnd - cos(ArrowAngle + Phi) * ArrowLength])
gen_contour_polygon_xld (CMidPoint, [Row - sin(rad(90) + Phi) * PSize,Row - sin(Phi - rad(90)) * PSize], [Col + cos(rad(90) + Phi) * PSize,Col + cos(Phi - rad(90)) * PSize])
dev_set_line_width (4)
dev_set_color ('white')
dev_display (CProfile)
dev_display (CArrow)
dev_set_line_width (2)
dev_set_color ('black')
dev_display (CProfile)
dev_display (CArrow)
return ()

*/ dev_display_profile_points
PSize := Length2 * 0.5
RowStart := Row + sin(Phi) * Length1
RowEnd := Row - sin(Phi) * Length1
ColStart := Col - cos(Phi) * Length1
ColEnd := Col + cos(Phi) * Length1
for idx := 0 to |PRows| - 1 by 1
  gen_contour_polygon_xld (CPoint, [PRows[idx] - sin(rad(90) + Phi) * PSize,PRows[idx] - sin(Phi - rad(90)) * PSize], [PCols[idx] + cos(rad(90) + Phi) * PSize,PCols[idx] + cos(Phi - rad(90)) * PSize])
  dev_set_color ('red')
  dev_set_line_width (3)
  dev_display (CPoint)
endfor
return ()

这次主要学习了gen_measure_rectangle2fuzzy_measure_pairs,set_fuzzy_measure_norm_pair,
效果
在这里插入图片描述

链接: 相关文章1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值