海思Hi3516A(4)HDR模式开发

简介:

1. HDR概述

  HDR(High-Dynamic Range)算法根据不同曝光的图片,合成最终HDR图片,比一般图片具有更宽的动态范围和图像细节。

  一般HDR算法有两种:一种是基于不同曝光时间的连续几幅图片合现,这种方法实现简单,只要能调曝光的sensor都可以实合成一幅图片;第二种是基于同一行不同曝光,最终成一幅图片,这种方法需要sensor支持行间长短曝光。

  这里使用500万分辨率摄像头芯片实现行间长短曝光实现HDR算法。


2. HDR模式传输方式

  在摄像头芯片中,视频信号通过MIPI接口传输,根据MIPI协议可将长短曝光行数据,通过两个virtual channel来传输。

  行间HDR数据读出时序如下:

wKioL1g-piSDdlSYAAAfJL22VJQ503.jpg

  • Fram_longFram_short输出偏差为max short exposure

  • max long exposure={帧长}-max short exposure


3. sensor的库文件生成(.so)

  Sensor的库文件需要在Linux服务器中的SDK包中编译得到,将生成的.so文件放到SDK包中的stream软件包中的Hi3516A_Stream_xxx/libs目录下。

XXXX_sensor_ctl.c实现sensor的初始化:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
void  sensor_init_5M_2lan_10bit_hdr()
{
     sensor_write_register(0x0100,0x00);sensor_write_register(0x363f,0x1c);
     sensor_write_register(0x3e03,0x03);sensor_write_register(0x3e08,0x00);
     sensor_write_register(0x3e09,0x10);sensor_write_register(0x3400,0x52);
     sensor_write_register(0x5000,0x21);sensor_write_register(0x5001,0x04);
     sensor_write_register(0x3627,0x02);sensor_write_register(0x320c,0x06);
     sensor_write_register(0x3f00,0xc6);sensor_write_register(0x3f01,0x04);
     sensor_write_register(0x3306,0x20);sensor_write_register(0x330b,0x38);
     sensor_write_register(0x4503,0xbb);sensor_write_register(0x3623,0x00);
     sensor_write_register(0x3622,0x0e);sensor_write_register(0x3630,0x34);
     sensor_write_register(0x3303,0x30);sensor_write_register(0x3309,0x30);
     sensor_write_register(0x331e,0x28);sensor_write_register(0x331f,0x28);
     sensor_write_register(0x3320,0x2c);sensor_write_register(0x3321,0x2c);
     sensor_write_register(0x3322,0x2c);sensor_write_register(0x3323,0x2c);
     sensor_write_register(0x5001,0x05);sensor_write_register(0x3902,0x05);
     sensor_write_register(0x3909,0x02);sensor_write_register(0x3907,0x00);
     sensor_write_register(0x3908,0x40);sensor_write_register(0x3416,0x00);
     sensor_write_register(0x3621,0x18);
     sensor_write_register(0x3627,0x04);sensor_write_register(0x3333,0x00);
     sensor_write_register(0x3334,0xf0);sensor_write_register(0x3662,0x82);
     sensor_write_register(0x3e09,0x50);sensor_write_register(0x3908,0x00);
     sensor_write_register(0x3620,0x62);sensor_write_register(0x5000,0x21);
     sensor_write_register(0x3e09,0xf0);sensor_write_register(0x3400,0x52);
     sensor_write_register(0x3638,0x84);sensor_write_register(0x3637,0x82);
     sensor_write_register(0x363f,0x0c);sensor_write_register(0x3622,0x02);
     sensor_write_register(0x330b,0x3c);sensor_write_register(0x363a,0x1c);
     sensor_write_register(0x3c00,0x41);sensor_write_register(0x3e01,0x10);
     sensor_write_register(0x3e05,0x00);sensor_write_register(0x3e06,0xf0);
     sensor_write_register(0x3221,0x80);sensor_write_register(0x4816,0x11);
     sensor_write_register(0x3e04,0x03);sensor_write_register(0x6000,0x21);
     sensor_write_register(0x320e,0x0f);  //max inttime
     sensor_write_register(0x320f,0x80);  //max inttime
     sensor_write_register(0x3e15,0x00);  //max short exposure
     sensor_write_register(0x3e16,0x40);  //max short exposure
     sensor_write_register(0x3c00,0x00);  //[2]: 0  mipi->fifo
     sensor_write_register(0x303f,0x02);  //[7]: 0  sel pll_pclk
     sensor_write_register(0x3031,0x0a);  //[3:0] 10bit
     sensor_write_register(0x3018,0x33);  //[7:5]  sel lane=reg+1
     sensor_write_register(0x3c03,0x10);  //fifo for 4lane
     sensor_write_register(0x3030,0x04);
     sensor_write_register(0x303d,0x01);sensor_write_register(0x303b,0x02);
     sensor_write_register(0x303c,0x08);sensor_write_register(0x3650,0x37);
     sensor_write_register(0x363f,0x0c);sensor_write_register(0x3300,0x10);
     sensor_write_register(0x3654,0x45);sensor_write_register(0x3902,0x45);
     sensor_write_register(0x3909,0x00);sensor_write_register(0x390a,0x00);
     sensor_write_register(0x3400,0x53);sensor_write_register(0x3039,0x10);
     sensor_write_register(0x303a,0x18);sensor_write_register(0x330a,0x01);
     sensor_write_register(0x330b,0x40);sensor_write_register(0x3306,0x80);
     sensor_write_register(0x3308,0x08);sensor_write_register(0x3416,0x20);
     sensor_write_register(0x320c,0x04);sensor_write_register(0x3907,0x03);
     sensor_write_register(0x3626,0x30);  //0909
     sensor_write_register(0x5000,0x21);sensor_write_register(0x330b,0xa0);
     sensor_write_register(0x3630,0x24);  //0x14
     sensor_write_register(0x3620,0x48);sensor_write_register(0x3f05,0xf0);
     sensor_write_register(0x320c,0x05);sensor_write_register(0x3e09,0x10);
     sensor_write_register(0x320d,0xa0);  //25fps
     sensor_write_register(0x3c00,0x41);  //fifo configsensor_write_register(0x3622,0x02);
     sensor_write_register(0x3638,0x83);sensor_write_register(0x3306,0x90);
     sensor_write_register(0x3f05,0xe0);sensor_write_register(0X3620,0X42);
     sensor_write_register(0x363a,0x14);sensor_write_register(0x3416,0x11);
     sensor_write_register(0x3334,0xa0);sensor_write_register(0x3333,0x90);
     sensor_write_register(0x3620,0x46);  //0x66  gain<2
     sensor_write_register(0x3303,0x48);sensor_write_register(0x3309,0x48);
     sensor_write_register(0x3627,0x08);
     sensor_write_register(0x335d,0x00);sensor_write_register(0x330e,0x10);
     sensor_write_register(0x303c,0x08);  //half mipi speed
     sensor_write_register(0x363c,0xc3);
     sensor_write_register(0x3010,0xe0);  //close dvp out
     sensor_write_register(0x300f,0xff);sensor_write_register(0x300e,0x0f);
     sensor_write_register(0x3635,0x38);sensor_write_register(0x3636,0x38);
     sensor_write_register(0x363f,0x80);sensor_write_register(0x3631,0x02);
     sensor_write_register(0x3637,0x82);sensor_write_register(0x3035,0xca);
     sensor_write_register(0x3300,0x30);sensor_write_register(0x330b,0x60);
     sensor_write_register(0x3f04,0x03);sensor_write_register(0x3f05,0x30);
     sensor_write_register(0x3633,0x1e);sensor_write_register(0x3630,0x1c);
     sensor_write_register(0x3622,0x06);sensor_write_register(0x0100,0x01);
}

  XXXX_cmos.c主要实现ISP需要的回调函数,传递参数,包括ISP、AE、AWB等。还需将变量genSensorMode赋值为WDR_MODE_2To1_LINE,以选择行间HDR模式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//ISP function
HI_S32 cmos_init_sensor_exp_function(ISP_SENSOR_EXP_FUNC_S *pstSensorExpFunc)
{
     memset (pstSensorExpFunc, 0,  sizeof (ISP_SENSOR_EXP_FUNC_S));
   
     pstSensorExpFunc->pfn_cmos_sensor_init = sensor_init;
     pstSensorExpFunc->pfn_cmos_sensor_exit = sensor_exit;
     pstSensorExpFunc->pfn_cmos_sensor_global_init = sensor_global_init;
     pstSensorExpFunc->pfn_cmos_set_image_mode = cmos_set_image_mode;
     pstSensorExpFunc->pfn_cmos_set_wdr_mode = cmos_set_wdr_mode;
       
     pstSensorExpFunc->pfn_cmos_get_isp_default = cmos_get_isp_default;
     pstSensorExpFunc->pfn_cmos_get_isp_black_level = cmos_get_isp_black_level;
     pstSensorExpFunc->pfn_cmos_set_pixel_detect = cmos_set_pixel_detect;
     pstSensorExpFunc->pfn_cmos_get_sns_reg_info = cmos_get_sns_regs_info;
   
     return  0;
}
   
//AE function
HI_S32 cmos_init_ae_exp_function(AE_SENSOR_EXP_FUNC_S *pstExpFuncs)
{
     memset (pstExpFuncs, 0,  sizeof (AE_SENSOR_EXP_FUNC_S));
   
     pstExpFuncs->pfn_cmos_get_ae_default    = cmos_get_ae_default;
     pstExpFuncs->pfn_cmos_fps_set           = cmos_fps_set;
     pstExpFuncs->pfn_cmos_slow_framerate_set= cmos_slow_framerate_set;    
     pstExpFuncs->pfn_cmos_inttime_update    = cmos_inttime_update;
     pstExpFuncs->pfn_cmos_gains_update      = cmos_gains_update;
     pstExpFuncs->pfn_cmos_again_calc_table  = cmos_again_calc_table;
     pstExpFuncs->pfn_cmos_get_inttime_max   = cmos_get_inttime_max; 
   
     return  0;
}
   
//AWB function
HI_S32 cmos_init_awb_exp_function(AWB_SENSOR_EXP_FUNC_S *pstExpFuncs)
{
     memset (pstExpFuncs, 0,  sizeof (AWB_SENSOR_EXP_FUNC_S));
   
     pstExpFuncs->pfn_cmos_get_awb_default = cmos_get_awb_default;
   
     return  0;
}
 
HI_U8 gu8SensorImageMode = SENSOR_5M_25FPS_MODE;
WDR_MODE_E genSensorMode = WDR_MODE_2To1_LINE;

  与一般sensor设置曝光不同,HDR行间模式需要行间交替实现曝光时间设置,也是在XXXX_cmos.c中实现,具体函数如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
static  HI_VOID cmos_inttime_update(HI_U32 u32IntTime)
{
     static  HI_BOOL bFirst = HI_TRUE;
 
     if  (WDR_MODE_2To1_LINE == genSensorMode)
     {
         if  (bFirst)  //short exposure
         {
             au32WDRIntTime[0] = u32IntTime;
             g_stSnsRegsInfo.astI2cData[4].u32Data = (u32IntTime >> 4) & 0xFF; ;
             g_stSnsRegsInfo.astI2cData[5].u32Data = (u32IntTime<<4) & 0xF0;
             bFirst = HI_FALSE;
         }
         else  //long exposure 
         {
             au32WDRIntTime[1] = u32IntTime;
             g_stSnsRegsInfo.astI2cData[0].u32Data = (u32IntTime >> 4) & 0xFF; ;
             g_stSnsRegsInfo.astI2cData[1].u32Data = (u32IntTime<<4) & 0xF0;
             bFirst = HI_TRUE;
         }
     }
     else
     {
         g_stSnsRegsInfo.astI2cData[0].u32Data = (u32IntTime >> 4) & 0xFF; ;
         g_stSnsRegsInfo.astI2cData[1].u32Data = (u32IntTime<<4) & 0xF0;
         bFirst = HI_TRUE;
     }
 
     return ;
}


4. 修改stream软件包的.ini文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[sensor]
Sensor_type   =XXXX                   ;sensor name
Mode          =2                        ;WDR_MODE_NONE = 0
                                         ;WDR_MODE_BUILT_IN = 1
                                         ;WDR_MODE_2To1_LINE = 2
                                         ;WDR_MODE_2To1_FRAME = 3
                                         ;WDR_MODE_2To1_FRAME_FULL_RATE =4 ...etc
DllFile   =libs /libsns_XXXX_2lan .so        ;sensor lib path
  
[mode]                               
input_mode =0                           ;INPUT_MODE_MIPI = 0
                                         ;INPUT_MODE_SUBLVDS = 1
                                         ;INPUT_MODE_LVDS = 2 ...etc
  
dev_attr = 0                             ;mipi_dev_attr_t = 0
                                         ;lvds_dev_attr_t = 1
                                         ;NULL =2
  
[mipi]    
;----------only  for  mipi_dev---------               
data_type = 1                         ;raw data  type : 8 /10/12/14  bit
                                         ;RAW_DATA_8BIT = 0
                                         ;RAW_DATA_10BIT = 1
                                         ;RAW_DATA_12BIT = 2 
                                         ;RAW_DATA_14BIT = 3 
lane_id = 0| 1 | -1 | -1 |-1|-1|-1|-1|        ;lane_id: -1 - disable
  
[isp_image]
Isp_x      =0
Isp_y      =0
Isp_W      =2560
Isp_H      =1920
Isp_FrameRate=25
Isp_Bayer  =3   ;BAYER_RGGB=0, BAYER_GRBG=1, BAYER_GBRG=2, BAYER_BGGR=3


5. 运行stream软件

  运行stream软件包中的HiIspTool.sh脚本,通过以太网卡与上位机的PQTools建立通信。

1
2
cd  Hi3516A_Stream_V1.0.5.0
. /HiIspTools .sh -a -p XXXX_5m_2lan.ini


6. 运行PQ Tools

  双击PQ Tools图片,弹出如下对话框,设置IP地址。

wKiom1g-rQOzEBwkAABXGsymKlU653.jpg

  在下拉菜单中选择TTP_Stream.exe选项.

wKiom1g-rWbxTn5iAAD8w5OOHLU056.jpg


7. 结果对比

  正常光照下的图片,日光灯显示模糊。

wKioL1g-rbyybcZhAAG1y_7YTJg874.jpg

  打开灯板后,无法捕捉宽动态范围的的场景,盒中的水果不能正常显示(偏黑),灯板的LED阵列无法识别,背景也非常昏暗。

wKiom1g-rqmB3J0xAAE6o8J6aow423.jpg

  开启行间HDR功能后,盒中中的水果可以清晰辨认,灯板的LED阵列也可清晰辨认,背景可见度有很大提升。

wKioL1g-r37RrK1bAAGhutXZO2Q040.jpg



本文转自 shugenyin 51CTO博客,原文链接:http://blog.51cto.com/shugenyin/1878262

相关文章
|
存储 监控 安全
TG7100CWiFi&BLE双模芯片 一键连接AIoT平台让你快速自定义智能方案
面对市面上眼花缭乱的双模芯片,许多应用方案商往往挑花了眼,不知道该选择哪款。今天我们推荐是天猫精灵联合平头哥推出的TG7100CWiFi&BLE双模芯片。它具有低功耗、宽工作温度等特点,广泛适用于智能家居,电工照明等领域。
TG7100CWiFi&BLE双模芯片 一键连接AIoT平台让你快速自定义智能方案
|
6月前
|
传感器 编解码
倍福推出新一代 EtherCAT 模拟量端子模块
**倍福发布7款 EtherCAT 高密度模拟量端子模块,提升IP20 I/O性能,具备16位分辨率和广泛应用。新品包括混合I/O模块EL4374,支持±107%扩展量程及NAMUR标准,以及EL3072/74输入模块和EL4072/74/78输出模块,提供8通道和更高密度。**
|
芯片 内存技术
STM32速成笔记(十三)—低功耗模式
本文介绍了三种STM32低功耗模式的进入和退出方法,针对待机唤醒给出了程序设计。
316 0
STM32速成笔记(十三)—低功耗模式
|
存储 编解码 人工智能
自媒体影视后期数字助理2--SDR与HDR中间件设计
阿里云提供的线上AI能力在处理视觉信息方面已经有较为成熟和通用的产品,对于开始兴建媒体资源管理平台的自媒体来说,采用阿里云的AI能力、函数计算以及OSS等产品进行平台搭建可以快速实现建设与能力扩充。本文为SDR与HDR中间件的开发思路、技术架构设计和开发实战中参数的设置介绍,对一些数字影像的基础概念和阿里云视觉人工智能的API细节进行了分析。
429 8
自媒体影视后期数字助理2--SDR与HDR中间件设计
高通平台开发系列讲解(PCIE篇)图解PCIe EP驱动初始化流程
高通平台开发系列讲解(PCIE篇)图解PCIe EP驱动初始化流程
1119 0
高通平台开发系列讲解(PCIE篇)图解PCIe EP驱动初始化流程
|
存储 编解码 缓存
RISC-V生态全景解析(十三):YoC组件介绍系列三:AV(多媒体)组件
编辑语: 芯片开放社区(OCC)面向开发者推出RISC-V系列内容,通过多角度、全方位解读RISC-V,系统性梳理总结相关理论知识,构建RISC-V知识图谱,促进开发者对RISC-V生态全貌的了解。
638 0
RISC-V生态全景解析(十三):YoC组件介绍系列三:AV(多媒体)组件
|
物联网 调度 开发工具
技术解码 | YoC组件开发系列一:如何向OCC发布芯片产品组件
技术解码栏目:是面向开发者详细解读芯片开放社区(OCC)上关于处理器、芯片、基础软件平台、集成开发环境及应用开发平台的相关技术,方便开发者学习及快速上手,提升开发效率。
422 0
技术解码 | YoC组件开发系列一:如何向OCC发布芯片产品组件