* This example shows an application case from the automobile
* industry. A monitoring system in a car checks the sidewalk
* for roadsigns to support the driver in case of any inattention.
* To show the imaging process we focus on two road signs,
* the attention and the dead end road sign. First the models
* of both signs are generated and then detected in a street
* sequence.
*
dev_close_window ()
* Read in model images.
* While the attention sign is from a synthetic source,
* the model for the dead end sign is from another sequence.
read_image (ImageAttentionSign, 'road_signs/attention_road_sign')
read_image (ImageInit, 'road_signs/street_01')
dev_open_window_fit_image (ImageInit, 0, 0, -1, -1, WindowHandle)
dev_update_off ()
*设置线宽为2
dev_set_line_width (2)
*设置输出颜色为绿色
dev_set_color ('green')
*设置画轮廓边缘
dev_set_draw ('margin')
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*
* Some values for the later matching process are initialized
* The Attention sign has a significant red part, the
* dead end sign a blue one. Hence, we can extract the respective
* channels from the colour images.
Channel := [3, 1]
* In this example, we significant scalings of the road signs.
ScaleRMin := [0.5, 0.4]
ScaleRMax := [0.8, 2.0]
* One could add anisothropic scaling for the exhaustive search.
* However, this makes detection slower and is not required here.
ScaleCMin := [1.0, 1.0]
ScaleCMax := [1.0, 1.0]
* Add names to the signs.
RoadSign := ['Attention', 'Dead end']
HFac := [47.0,50.0]
*
* Prepare the attention sign picture for the model
* creation process.
*从多通道图像ImageAttentionSign中通道O获取图像,存储在Image中。
access_channel (ImageAttentionSign, Image, Channel[0])
*按照给定的比例因子缩放图像宽度和高度,之后按照“weighted"方式插值 缩放图像后一定得插值才行
zoom_image_factor (Image, ImageZoomed, 0.1, 0.1, 'weighted')
*获取图像感兴趣的边缘
inspect_shape_model (ImageZoomed, ModelImages, ModelRegions, 3, 20)
*创建一个可变形的模板,以供匹配
create_planar_uncalib_deformable_model (ImageZoomed, 3, 0.0, 0.0, 0.1, ScaleRMin[0], ScaleRMax[0], 0.05, 1.0, 1.0, 0.5, 'none', 'use_polarity', 'auto', 'auto', [], [], ModelID)
Models := ModelID
*
*
*
read_image (ImageDeadEnd, 'road_signs/dead_end_road_sign')
access_channel (ImageDeadEnd, Image, Channel[1])
*载入”octagon“获取一个5X5的模板,存入ImageClosing中
gray_closing_shape (Image, ImageClosing, 5, 5, 'octagon')
*缩放模板,比例因子均为0.4,插值方式为”weighted"
zoom_image_factor (ImageClosing, ImageZoomed, 0.4, 0.4, 'weighted')
*产生一个矩形框
gen_rectangle1 (Rectangle1, 28, 71, 67, 95)
*在ImageZoomed中,提取Rectangle1区域中的边缘
reduce_domain (ImageZoomed, Rectangle1, ImageReduced)
*产生一个可变形状大小的模板
create_planar_uncalib_deformable_model (ImageReduced, 3, 0.0, 0.0, 0.1, ScaleRMin[1], ScaleRMax[1], 0.05, ScaleRMin[1], ScaleRMax[1], 0.1, 'none', 'use_polarity', 'auto', 'auto', [], [], ModelID)
*
* the following three lines theoretically show how to
* query specific parameters of a model.
* Practically, the derived information is not needed
* within the program.
*获取可变模板角度步长值和行方向比例步长值
get_deformable_model_params (ModelID, 'angle_step', AngleStep)
get_deformable_model_params (ModelID, 'scale_r_step', ScaleRStep)
Models := [Models, ModelID]
*
* generate ROI in which the road signs are expected.
* We can discard not significant parts of the image, in which
* no road sign can be located.
gen_rectangle1 (Rectangle, 115, 0, 360, 640)
*
* Search in image sequence
for Index := 1 to 16 by 1
OutputString := []
TotalTime := 0
read_image (Image, 'road_signs/street_'+Index$'.02')
* We are using colour images, hence the ROI of the search image
* can significantly be reduced based on the colour.
determine_area_of_interest (Image, Rectangle, AreaOfInterest)
*提取边缘轮廓
reduce_domain (Image, AreaOfInterest, ImageReduced)
dev_display (Image)
*
for Index2 := 0 to |Models|-1 by 1
*
* Depending on the street sign to be found, we use different color
* channles of the image and the operator find_planar_uncalib_deformable_model
* with different parameters because of the varying dimensions of the models.
access_channel (ImageReduced, ImageChannel, Channel[Index2])
*开始时间
count_seconds (Time1)
*
find_planar_uncalib_deformable_model (ImageChannel, Models[Index2], 0, 0, ScaleRMin[Index2], ScaleRMax[Index2], ScaleCMin[Index2], ScaleCMax[Index2], 0.8, 1, 0, 2, 0.4, [], [], HomMat2D, Score)
*find_planna_uncalib_deformable_model(Image : : ModelID,AngleStart,AngleExtent,ScaleRMin,ScaleRMax,ScaleCMin,ScaleCMax,MinScore,NumMatches,MaxOverlap,NumLevels,Greediness,ParamName,ParamValue :HomMat2D,Score)
*Image :源图像
*ModelID:模板
*AngleStart:查找图像开始角度,为弧度制。
*AngleExtent:查找角度结束
*ScaleRMin:行方向上的最小比例
*ScaleRMax:行方向上的最大比例因子
*ScaleCMin:列方向上的最小比例
*ScaleCMax:列方向上的最大比例
*MinScore:匹配的最小可接受分数(0< <1)
*NumMatches:在Image中查找到的模板个数
*MaxOverlap:最大重合度问题。表示在Image中所查找的匹配图像存在重叠。当为0时候,表示不存在重叠
*NumLevels:金字塔等级
*Greediness:搜索精度及速度设置
*ParamName:一般参数名
*ParamValue:参数值
*HomMat2D:计算得到的模板和查找到的图像之间的转换映射。模板可以通过此映射转换到相应地找到的图像的位置上去
*Scale:查找到的匹配分数
*结束时间
count_seconds (Time2)
*得到查找时间
Time := Time2-Time1
*查找时间累积
TotalTime := TotalTime + Time
*
* Display found models.
if (|HomMat2D|)
*获取可变大小的模板的边缘轮廓
get_deformable_model_contours (ModelContours, Models[Index2], 1)
*将模板轮廓通过HomMat2D转换到ContoursProjTrans位置上
projective_trans_contour_xld (ModelContours, ContoursProjTrans, HomMat2D)
*从轮廓生成一个区域,filled表示为区域显示,marine则表示只显示轮廓
gen_region_contour_xld (ContoursProjTrans, Region, 'filled')
union1 (Region, RegionU)
*得到区域的面积和中心行列坐标
area_center (RegionU, Area, R, C)
get_region_runs (RegionU, Row, ColumnBegin, ColumnEnd)
H := max(Row)-min(Row)
Fac := H/HFac[Index2]
*画圆,圆心为(R,C),半径为45*Fac
gen_circle (Circle, R, C, 45*Fac)
dev_display (Circle)
gen_circle (Circle, R, C, 50*Fac)
dev_display (Circle)
*显示轮廓
dev_display (ContoursProjTrans)
if (Index2=0)
OutputString := 'Attention sign found in : '+(Time*1000)$'.2f'+' ms \n'
else
OutputString := 'Dead end sign found in : '+(Time*1000)$'.2f'+' ms \n'
endif
endif
endfor
if (|OutputString|=0)
OutputString := 'No sign found in : '+(Time*1000)$'.2f'+' ms \n'
endif
OutputString := ['Search for all models in: '+(TotalTime*1000)$'.2f'+' ms', OutputString]
disp_message (WindowHandle, OutputString, 'window', 10, 10, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
dev_display (Image)
disp_message (WindowHandle, 'Program finished.\nPress \'Run\' to clear all deformable models.', 'window', 10, 10, 'black', 'true')
stop ()
* Clean the memory of the models.
for Index1 := 0 to 1 by 1
clear_deformable_model (Models[Index1])
endfor