opt光源控制部分

opt光源通过串口无法进行控制打开和关闭通道。只能修改光强部分。

软件部分实现控制的话通过服务器发送指令进行打开关闭。

binary_threshold (Image, Region, 'smooth_histo', 'light', UsedThreshold)

connection (Region, ConnectedRegions)
*closing_rectangle1 (ConnectedRegions, RegionClosing, 45,45)
*opening_rectangle1 (ConnectedRegions, RegionOpening, 30, 30)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1500, 99999)
area_center (SelectedRegions, Area, Row, Column)
orientation_region (SelectedRegions, Phi2)
vector_angle_to_rigid (Row, Column, Phi2, Row, Column, Phi2, HomMat2D)
affine_trans_region (SelectedRegions, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
*gen_contour_region_xld (RegionAffineTrans, Contours, 'border')
smallest_rectangle2(RegionAffineTrans,Row, Column, Phi, Length1, Length2)
gen_rectangle2_contour_xld (Rectangle,Row, Column, Phi, Length1, Length2)
orientation_region(RegionAffineTrans, Phi11)
get_contour_xld (Rectangle, Row6, Col6)
gen_cross_contour_xld (Cross2, Row, Column, 6, Phi)
*orientation_region (RegionAffineTrans, Phi1)
*gen_cross_contour_xld (Cross1, Row6, Col6, 60, Phi)
if(abs(deg(Phi))>45)
    Phi:=rad(deg(Phi)-90*(Phi/abs(Phi)))
    Tmp:=Length1
    Length1:=Length2
    Length2:=Tmp
endif
tuple_sin (Phi, Sin)
tuple_cos (Phi, Cos)

*左上角
TopLeft_X := -Length1*Cos - Length2*Sin
TopLeft_Y := -Length1*Sin + Length2*Cos
TopLeft_Row := Row - TopLeft_Y 
TopLeft_Col := Column + TopLeft_X 

*右上角
TopRight_X := Length1*Cos - Length2*Sin
TopRight_Y := Length1*Sin + Length2*Cos
TopRight_Row := Row - TopRight_Y 
TopRight_Col := Column + TopRight_X 

*右下角
LowerRight_X := Length1*Cos + Length2*Sin
LowerRight_Y := Length1*Sin - Length2*Cos
LowerRight_Row := Row - LowerRight_Y 
LowerRight_Col := Column + LowerRight_X 
 
*左下角
LowerLeft_X := -Length1*Cos + Length2*Sin
LowerLeft_Y := -Length1*Sin - Length2*Cos
LowerLeft_Row := Row - LowerLeft_Y 
LowerLeft_Col := Column + LowerLeft_X 

 affine_trans_pixel (HomMat2D, TopLeft_Row, TopLeft_Col, RowTrans, ColTrans)
 affine_trans_pixel (HomMat2D, LowerLeft_Row, LowerLeft_Col, RowTrans1, ColTrans1)
gen_region_line (RegionLines3, RowTrans, ColTrans, RowTrans1, ColTrans1)
LinePara:=[RowTrans, ColTrans, RowTrans1, ColTrans1]

dev_display (RegionLines3)
*测试
*边缘强度
MeasureThreshold:=100
*创建卡尺句柄
create_metrology_model (MetrologyHandle)
*设置被测图尺寸
set_metrology_model_image_size (MetrologyHandle, 120, 40)
*添加直线模型,卡尺尺寸设定,边缘强度设定
add_metrology_object_line_measure (MetrologyHandle,RowTrans, ColTrans, RowTrans1, ColTrans1, 20, 5, 1, 30, [], [], Index)
*add_metrology_object_generic (MetrologyHandle, 'line', LinePara, 20, 3, 1, 40, [], [], Index)
set_metrology_object_param (MetrologyHandle, 'all', 'num_measures',6)
*set_metrology_object_param (MetrologyHandle, 'all', 'num_instances', 1)
*set_metrology_object_param (MetrologyHandle, 'all', 'measure_sigma', 1)
*set_metrology_object_param (MetrologyHandle, 'all', 'measure_threshold',15)
*set_metrology_object_param (MetrologyHandle, 'all', 'measure_interpolation', 'bicubic')
*set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'all')
*set_metrology_object_param (MetrologyHandle, 'all', 'min_score', 0.7)
*执行测量
apply_metrology_model (Image, MetrologyHandle)
*获取测量Contours
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row3, Column3)
*gen_cross_contour_xld (Cross1, Row3, Column3, 3, 0)
*dev_display (Contours)
*获取测量数据
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)
*获取测量直线
get_metrology_object_result_contour (Contour, MetrologyHandle,'all', 'all', 1.5)
*获取直线的两个端点
*smallest_rectangle1_xld (Contour, Row4, Column4, Row21, Column21)

*angle_lx ( Row4, Column4, Row21, Column21, Angle)
*andle:=deg(Angle)
*显示 交点
*gen_cross_contour_xld (Cross, Row21, Column21, 3, Phi+rad(30))
dev_display (Image)
dev_set_color ('red')
dev_display (Contour)
dev_display (Contours)
dev_display (Cross2)

你可能感兴趣的:(笔记,开发语言)