寻找区域中的面积和中心点
原图和最终效果图如下所示:


1.获取图像并打开新窗口,设置参数
*获取图像
read_image (Image, 'fabrik')
*关闭窗口
dev_close_window ()
*打开窗口
dev_open_window (0, 0, 512, 512, 'black', WindowID)
*设置输出字体,14号字,Courier字体,粗体
set_display_font (WindowID, 14, 'mono', 'true', 'false')
*设置输出颜色
dev_set_colored (6)
2.进行区域划分并计算所有不相连区域的面积和中心点坐标
*进行区域生长操作
regiongrowing (Image, Regions, 1, 1, 3, 200)
*显示区域
dev_display (Regions)
*计算所有区域的面积和中心点坐标
area_center (Regions, Area, Row, Column)
* 赋值给center
center:=|Area|
输出参数:
3.获取每个字符串的空间大小
get_string_extents (WindowID, 12345, Ascent, Descent, TxtWidth, TxtHeight)
* Ascent从基线到字符顶部的距离(上行高度)
* Descent从基线到字符底部的距离(下行高度)
实例如下图所示:
4.最后使用循环将面积计算结果以字符串形式显示在窗口中
for I := 0 to center-1 by 1disp_message (WindowID, Area[I], 'image', Row[I] - TxtHeight / 2, Column[I] - TxtWidth / 2, 'white', 'false')
endfor