前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >算法集锦(9)|自动驾驶|道路图像增强算法

算法集锦(9)|自动驾驶|道路图像增强算法

作者头像
用户7623498
发布2020-08-04 15:57:00
1.3K0
发布2020-08-04 15:57:00
举报

自动驾驶汽车是一项非常有挑战性的AI技术,与其他AI技术(如图像处理、语音识别等)相比,它有着本身的特殊性。比如,它不仅需要处理白天和黑夜的场景,还需要处理各种复杂的天气。一辆汽车在雪天与在晴天的驾驶方式肯定是不同的。为了让自动驾驶汽车更加安全,那就必须在不同的环境和路况下对其进行全面的训练。因此,在训练自动驾驶算法时,需要一些特殊的图像增强处理。

现阶段,训练自动驾驶汽车最可靠的方式是进行实际的路测,但实际路况的环境毕竟毕竟单一,难以对系统的CNN网络进行全面的训练(如考虑气候、光线等)。为了更有效的训练汽车的CNN网络,本文提供了一个可模拟各种气候及环境的图像增强算法-Automold。该算法基于python的Numpy和OpenCV库开发,可以将图像转换至各种气候环境及季节。比如,模拟雨天、晴天、大雾及雪天等,可以使系统在采集路况图像的时候,完成其在各种气候环境下的训练,大大增强了训练的样本数量及丰富程度。

接下来我们来看一些实际的处理效果,下图是汽车摄像头采集到的各种路况图像。

雨雪天气

向路况图像添加雨雪天气环境可以帮助自动驾驶汽车训练如何在恶劣的路况下如何行驶。雨雪天对于驾驶来说是一个很大的威胁,即使是人类有时也很难正确的进行处理。下面是利用Automold进行雨雪环境处理的效果。

雪天环境

雨天环境

雨天环境有三种模式:drizzle,heave和torrential,你可以选择自己需要的模式进行训练,以提高训练效率。详细代码如下:

添加雪天环境

代码语言:javascript
复制
 1def add_snow(image, snow_coeff=-1):
 2    verify_image(image)
 3    if(snow_coeff!=-1):
 4        if(snow_coeff<0.0 or snow_coeff>1.0):
 5            raise Exception(err_snow_coeff)
 6    else:
 7        snow_coeff=random.uniform(0,1)
 8    snow_coeff*=255/2
 9    snow_coeff+=255/3
10    if(is_list(image)):
11        image_RGB=[]
12        image_list=image
13        for img in image_list:
14            output= snow_process(img,snow_coeff)
15            image_RGB.append(output) 
16    else:
17        output= snow_process(image,snow_coeff)
18        image_RGB=output
19    return image_RGB

添加雨天环境

代码语言:javascript
复制
 1 def add_rain(image,slant=-1,drop_length=20,drop_width=1,drop_color=(200,200,200),rain_type='None'): ## (200,200,200) a shade of gray
 2    verify_image(image)
 3    slant_extreme=slant
 4    if not(is_numeric(slant_extreme) and (slant_extreme>=-20 and slant_extreme<=20)or slant_extreme==-1):
 5        raise Exception(err_rain_slant)
 6    if not(is_numeric(drop_width) and drop_width>=1 and drop_width<=5):
 7        raise Exception(err_rain_width)
 8    if not(is_numeric(drop_length) and drop_length>=0 and drop_length<=100):
 9        raise Exception(err_rain_length)
10    if(is_list(image)):
11        image_RGB=[]
12        image_list=image
13        imshape = image[0].shape
14        if slant_extreme==-1:
15            slant= np.random.randint(-10,10) ##generate random slant if no slant value is given
16        rain_drops,drop_length= generate_random_lines(imshape,slant,drop_length,rain_type)
17        for img in image_list:
18            output= rain_process(img,slant_extreme,drop_length,drop_color,drop_width,rain_drops)
19            image_RGB.append(output)
20    else:
21        imshape = image.shape
22        if slant_extreme==-1:
23            slant= np.random.randint(-10,10) ##generate random slant if no slant value is given
24        rain_drops,drop_length= generate_random_lines(imshape,slant,drop_length,rain_type)
25        output= rain_process(image,slant_extreme,drop_length,drop_color,drop_width,rain_drops)
26        image_RGB=output
27    return image_RGB

光线调整

Automold库可以通过设置不同的参数来改变图像的亮度,从而模拟光线的变化,实现诸如晴天、阴天、傍晚等不同的环境。

光线变亮

光线变暗

详细代码如下:

代码语言:javascript
复制
 1def brighten(image, brightness_coeff=-1): ##function to brighten the image
 2    verify_image(image)
 3    if(brightness_coeff!=-1):
 4        if(brightness_coeff<0.0 or brightness_coeff>1.0):
 5            raise Exception(err_brightness_coeff)
 6    if(is_list(image)):
 7        image_RGB=[]
 8        image_list=image
 9        for img in image_list:
10            if(brightness_coeff==-1):
11                brightness_coeff_t=1+ random.uniform(0,1) ## coeff between 1.0 and 1.5
12            else:
13                brightness_coeff_t=1+ brightness_coeff ## coeff between 1.0 and 2.0
14            image_RGB.append(change_light(img,brightness_coeff_t))
15    else:
16        if(brightness_coeff==-1):
17            brightness_coeff_t=1+ random.uniform(0,1) ## coeff between 1.0 and 1.5
18        else:
19            brightness_coeff_t=1+ brightness_coeff ## coeff between 1.0 and 2.0
20        image_RGB= change_light(image,brightness_coeff_t)
21    return image_RGB
22def darken(image, darkness_coeff=-1): ##function to darken the image
23    verify_image(image)
24    if(darkness_coeff!=-1):
25        if(darkness_coeff<0.0 or darkness_coeff>1.0):
26            raise Exception(err_darkness_coeff) 
27    if(is_list(image)):
28        image_RGB=[]
29        image_list=image
30        for img in image_list:
31            if(darkness_coeff==-1):
32                darkness_coeff_t=1- random.uniform(0,1)
33            else:
34                darkness_coeff_t=1- darkness_coeff            
35            image_RGB.append(change_light(img,darkness_coeff_t))
36    else:
37        if(darkness_coeff==-1):
38             darkness_coeff_t=1- random.uniform(0,1)
39        else:
40            darkness_coeff_t=1- darkness_coeff  
41        image_RGB= change_light(image,darkness_coeff_t)
42    return image_RGB

阴影与砂石

Automold库还可以帮助你向道路上添加阴影和碎石等,但有时候向特定的区域设置碎石及指定碎石的数量实现起来还比较困难。所以如果不是有特殊的要求,可以采用默认设置。向图像添加碎石后,可以训练自动驾驶汽车去躲避路障。

随机阴影

添加碎石

添加阴影

代码语言:javascript
复制
 1def add_shadow(image,no_of_shadows=1,rectangular_roi=(-1,-1,-1,-1), shadow_dimension=5):## ROI:(top-left x1,y1, bottom-right x2,y2), shadow_dimension=no. of sides of polygon generated
 2    verify_image(image)
 3    if not(is_numeric(no_of_shadows) and no_of_shadows>=1 and no_of_shadows<=10):
 4        raise Exception(err_shadow_count)
 5    if not(is_numeric(shadow_dimension) and shadow_dimension>=3 and shadow_dimension<=10):
 6        raise Exception(err_shadow_dimension)
 7    if is_tuple(rectangular_roi) and is_numeric_list_or_tuple(rectangular_roi) and len(rectangular_roi)==4:
 8        x1=rectangular_roi[0]
 9        y1=rectangular_roi[1]
10        x2=rectangular_roi[2]
11        y2=rectangular_roi[3]
12    else:
13        raise Exception(err_invalid_rectangular_roi)
14    if rectangular_roi==(-1,-1,-1,-1):
15        x1=0
16        if(is_numpy_array(image)):
17            y1=image.shape[0]//2
18            x2=image.shape[1]
19            y2=image.shape[0]
20        else:
21            y1=image[0].shape[0]//2
22            x2=image[0].shape[1]
23            y2=image[0].shape[0]
24    elif x1==-1 or y1==-1 or x2==-1 or y2==-1 or x2<=x1 or y2<=y1:
25        raise Exception(err_invalid_rectangular_roi)
26    if(is_list(image)):
27        image_RGB=[]
28        image_list=image
29        for img in image_list:
30            output=shadow_process(img,no_of_shadows,x1,y1,x2,y2, shadow_dimension)
31            image_RGB.append(output)
32    else:
33        output=shadow_process(image,no_of_shadows,x1,y1,x2,y2, shadow_dimension)
34        image_RGB = output
35    return image_RGB

添加碎石

代码语言:javascript
复制
 1def add_gravel(image,rectangular_roi=(-1,-1,-1,-1), no_of_patches=8):
 2    verify_image(image)
 3    if is_tuple(rectangular_roi) and is_numeric_list_or_tuple(rectangular_roi) and len(rectangular_roi)==4:
 4        x1=rectangular_roi[0]
 5        y1=rectangular_roi[1]
 6        x2=rectangular_roi[2]
 7        y2=rectangular_roi[3]
 8    else:
 9        raise Exception(err_invalid_rectangular_roi)
10    if rectangular_roi==(-1,-1,-1,-1):
11        if(is_numpy_array(image)):
12            x1=0
13            y1=int(image.shape[0]*3/4)
14            x2=image.shape[1]
15            y2=image.shape[0]
16        else:
17            x1=0
18            y1=int(image[0].shape[0]*3/4)
19            x2=image[0].shape[1]
20            y2=image[0].shape[0]
21    elif x1==-1 or y1==-1 or x2==-1 or y2==-1 or x2<=x1 or y2<=y1:
22        raise Exception(err_invalid_rectangular_roi)
23    color=[0,255]  
24    if(is_list(image)):
25        image_RGB=[]
26        image_list=image
27        for img in image_list:
28            output= gravel_process(img,x1,x2,y1,y2,no_of_patches)
29            image_RGB.append(output)
30    else:
31        output= gravel_process(image,x1,x2,y1,y2,no_of_patches)
32        image_RGB= output    
33    return image_RGB

闪光和大雾

在驾驶过程中,还经常会遇到的大雾天或者刺眼的光线这种影响视线的情况。对于闪光(sun flare),Automold库可以设置光源的位置、角度及光线的颜色等等,通过不是的组合可以创造出你想要的效果。

添加闪光

添加大雾

速度与季节

当汽车以很快的速度行驶时,周边的景物会变得模糊,Automold库依然可以模拟该效果。添加速度后,远处的景物依然保持清醒,而近处的景物则会变得模糊。

添加速度

此外,还可以改变图片的风格,以模拟不同的季节,下图是秋天的效果。通过改变叶子的颜色来实现秋天的风格。

添加季节

Automold库提供了一种便捷的方式,可以对图像随机添加增强效果,而不需要繁琐的去指定增强类型,使得该算法可以很好的嵌入到自动驾驶的CNN网络训练中。方法如下:

代码语言:javascript
复制
1aug_images= am.augment_random(images)
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-05-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 决策智能与机器学习 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
语音识别
腾讯云语音识别(Automatic Speech Recognition,ASR)是将语音转化成文字的PaaS产品,为企业提供精准而极具性价比的识别服务。被微信、王者荣耀、腾讯视频等大量业务使用,适用于录音质检、会议实时转写、语音输入法等多个场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档