halcon答题卡识别

发布时间:2024年01月20日

在这里插入图片描述
答题卡识别,在考试中老师阅卷也是越来越智能,只需要对比标准答题卡,就可以轻松识别考生的答题结果.
这里我们用简单的算法实现,自动识别考生答题卡涂抹的选项.

read_image (Image, ‘答题卡.jpg’)
rgb1_to_gray (Image, GrayImage)
emphasize (GrayImage, ImageEmphasize, 7, 7, 3)
bin_threshold (ImageEmphasize, Region)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, [‘width’,‘height’], ‘and’, [1,1], [74,39.3])

fill_up_shape (SelectedRegions, RegionFillUp, ‘area’, 1, 1800)
opening_circle (RegionFillUp, RegionOpening, 8.5)
closing_circle (RegionOpening, RegionClosing, 8.5)
connection (RegionClosing, ConnectedRegions1)

sort_region (ConnectedRegions1, SortedRegions, ‘character’, ‘true’, ‘column’)
count_obj (SortedRegions, Number)
selectRegion:=[]
Result:=[]
i:=0
for j:=0 to Number-1 by 1
select_obj (SortedRegions, ObjectSelected, j+1)
erosion_rectangle1 (ObjectSelected, RegionErosion, 8, 11)
reduce_domain (ImageEmphasize, RegionErosion, ImageReduced)

fast_threshold (ImageReduced, Region1, 0, 15, 5)
connection (Region1, ConnectedRegions2)
count_obj (ConnectedRegions2, Number1)
area_center (ConnectedRegions2, Area1, Row1, Column1)
if(Number1>1)
  selectRegion[i]:=j 
  n:=(j+1)/10
  Reslut[i]:=(j)%10

  i:=i+1
endif

endfor
stop()

tuple_gen_const (15, 40, R)
tuple_gen_const (15, 35, C)

dev_display (Image)
dev_get_window (WindowHandle)
for k:=0 to i-1 by 1
select_obj (SortedRegions, ObjectSelected1,selectRegion[k]+1)
area_center (ObjectSelected1, Area, Row, Column)
union1 (ObjectSelected1, RegionUnion)
disp_message (WindowHandle, Reslut[k], ‘image’, R[k], C[k]+k*70+25, ‘red’, ‘true’)
endfor

文章来源:https://blog.csdn.net/u011637657/article/details/135714978
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。