交通标志识别之Halcon算法实现

* 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.

*这个例子展示了汽车行业的应用案例。在汽车中的监控系统检查人行道的路标,以支持司机在任何疏忽的情况下。这个例程主要关注两个路标,注意和前方无路路标。首先,生成两个标志的模型,然后在街道画面序列中检测。单帧检索时间最有7ms,最差25ms

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 ()

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.

为注意标志创建模型

access_channel (ImageAttentionSign, Image, Channel[0])取红色通道

zoom_image_factor (Image, ImageZoomed, 0.1, 0.1, 'weighted')

inspect_shape_model (ImageZoomed, ModelImages, ModelRegions, 3, 20)

创建一个用来展示出基于形状的模型(这里分了三层)

这个操作用于显示出形状模型的大概情况,主要设定NumLevels的层数和Contrast参数的合理值,属于一个检查工作,为后续创建做准备

注意:如果输入Image是单通道,创建模型的时候metrics可以用‘use_polarity’,‘ignore_global_polarity’and‘ignore_local_polarity’,当是多通道时该参数应该用‘ignore_global_polarity’

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])

gray_closing_shape (Image, ImageClosing, 5, 5, 'octagon')

zoom_image_factor (ImageClosing, ImageZoomed, 0.4, 0.4, 'weighted')

gen_rectangle1 (Rectangle1, 28, 71, 67, 95)

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.

*下面的程序,生成预期路标的ROI。即取得路标可能在的位置,舍弃不可能存在路标的区域,也就是车辆的正前方

gen_rectangle1 (Rectangle, 115, 0, 360, 640)

* Search in image sequence

然后在序列中寻找路标,即寻找model

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.

我们使用彩色图像,可以利用色彩区分来减少ROI的区域,提高效率

    determine_area_of_interest (Image, Rectangle, AreaOfInterest)

determine_area_of_interest是创建的一个函数封装,用于筛选交通标志可能存在的区域,先转化为3个单色图,在转化成HSV,然后在色差空间中进行灰度筛选

    reduce_domain (Image, AreaOfInterest, ImageReduced)

    dev_display (Image)

    for Index2 := 0 to |Models|-1 by 1

        根据被寻找的路标,我们使用不同的颜色通道来进行搜索

        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)

        进行模板匹配,HomMat2D是输出的转换矩阵,Score匹配的可信度

        count_seconds (Time2)

        Time := Time2-Time1

        TotalTime := TotalTime + Time

        *

        * Display found models.

           展示寻找到的model,展示搜索结果

        if (|HomMat2D|)如果上面的搜索结果不为空

            get_deformable_model_contours (ModelContours, Models[Index2], 1)

            获得一个可变模型的边界

            projective_trans_contour_xld (ModelContours, ContoursProjTrans, HomMat2D)

            对一个边界进行投影转换,利用扇面找到的转换矩阵HomMat2D转换之后,在原图的相应位置就会产生一个转换后的边界

            gen_region_contour_xld (ContoursProjTrans, Region, 'filled')

            利用边界生成一个区域

            union1 (Region, RegionU)

            area_center (RegionU, Area, R, C)

            get_region_runs (RegionU, Row, ColumnBegin, ColumnEnd)

把region按照chord的形式存储在tuples中,chord就是按照列来一行一行的遍历region,那么在这一行中region就是一条或者多条线段,chord就是记录下这些线段的起始点以及行号加以保存

            H := max(Row)-min(Row)

            Fac := H/HFac[Index2]

            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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,165评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,503评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,295评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,589评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,439评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,342评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,749评论 3 387
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,397评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,700评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,740评论 2 313
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,523评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,364评论 3 314
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,755评论 3 300
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,024评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,297评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,721评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,918评论 2 336

推荐阅读更多精彩内容

  • 有些人还未说再见道离别就不知不觉地走了 所谓的生命里的命数终究是你我都无法预测的 无法挣脱 也无法逃避 这颗心,究...
    d64c6bbfb059阅读 450评论 0 0
  • 今天遇到了最尴尬的事情、不管自己怎么努力给自己灌输正面信息、真正面对问题的时候才发现自己了解的太肤浅。就说最近心血...
    Snow吉阅读 204评论 0 1
  • 在没有当老师之前我是一枚当众说话会脸红的小苹果,记得第一次上微格课说课的时候由于紧张像数学课不会做题被挂在黑板上的...
    画有几画阅读 290评论 1 8
  • 摸摸摸
    过去往来阅读 128评论 0 0