halcon程序初级学习(一)

来源:互联网 发布:sql 动态生成临时表 编辑:程序博客网 时间:2024/06/01 09:53

x:=16
y:=9
Result := 10
SqrtY_Result := sqrt(y)
Z:=90/180
Z_Result := sin(Z)
Z_Result:=sin(Z)*sin(y)
Tuple1:=[1,2,3,4,5,6,7,8,9]
insert (Tuple1, 10, 9, OutTuple)
OutTuple[10]:=11
Tuple2:=[12,13,14,15]
Tuple3:=[Tuple1,Tuple2]             //连接成新的数组
len:=|Tuple3|                           //得到数组长度
seletevalue:=Tuple3[10]                //选取第i个元素0<= i < |t|
Tuple4:=[]
Tuple4:=Tuple3[1:10] //选取i1到i2的元素
value4:=subset(Tuple4,4)//选取数组Tuple4中的第i个元素
value5:=remove(value4,4)//去除数组Tuple4中的第i个元素
stop()
tuple_gen_const (value5, 66, Newtuple)//创建一个具有value5个元素的,每个元素都为66的数组
tuple:=[]
for i := 1 to 5 by 1
   tuple:=[tuple,i*i] //将i方的值赋给数组的第i个元素
endfor
stop()

read_image (Mreut, 'mreut')               //读入图像(system auto open image)
threshold (Mreut, Region, 190, 255)      //阈值化,输出阈值在190-255的Regions
Areas:=[]
for Radius := 1 to 5 by 1
    dilation_circle (Region, RegionDilation, Radius)//利用半径为Radius的圆对Region进行膨胀运算,输出RegionDilation,输出形式仍然为Region。
    area_center (RegionDilation, Area, Row, Column) //输出区域的面积和中心像素坐标
    Areas[Radius-1]:=Area//对数组Areas的第Radius-1个元素进行赋值
endfor
stop()

read_image (Image, 'D:/用户目录/我的图片/jpg/9d82d158ccbf6c810eb700cabf3eb13533fa400b.jpg')  //RGB three color image
* read_image(Image,'monkey')
*将图像颜色区间(246,255)的图像设置成红色,输出区域 
threshold (Image, Regions, 246, 255)
dev_clear_window ()
*设置当前区域的颜色为'yellow'
dev_set_color('yellow')
dev_set_draw('fill')
dev_display(Regions)
*显示白色边缘
dev_set_color('white')
dev_set_draw('margin')
dev_display(Regions)
stop()

* example about blob analysis
*套环的数目和准确的位置统计出来,2、屏蔽非套环的干扰
*图像特征分析:实心物体与空心物体,套环由U形孔和圆组成,圆的位置比例比U形孔大,分析可知求出圆的中心点既可以确定套环的位置和个数
*设置显示模式:margin:边缘的意思
dev_set_draw ('margin')
read_image (Image, 'E:/BaiduYunDownload/套环检测/图像00228.BMP')
*图像阈值分割后也包括整张图片的外围长方体轮廓
threshold (Image, Region, 128, 255)
connection (Region, ConnectedRegions)
*开运算:去除毛刺/沟壑
opening_circle (ConnectedRegions, RegionOpening, 3.5)
*求出U形孔的最小外界矩形的面积130个像素 把圆分离出来区间(200,1996)  1996这个值如何得来?
select_shape (RegionOpening, SelectedRegions, 'area', 'and', 150.41, 1996.63)
*显示圆的中心
area_center (SelectedRegions, Area, Row, Column)
gen_cross_contour_xld (Cross, Row, Column, 6, 0.785398)
*count_obj (Cross, Number)
count_obj (SelectedRegions, Number)
disp_message (3600, 'find Circle:'+Number, 'Image', 40, 40, 'black', 'true')
stop()

0 0
原创粉丝点击