海思Hi3516A(4)HDR模式开发

发布时间:2020-07-02 01:32:07 作者:shugenyin
来源:网络 阅读:12957

1. HDR概述

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

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

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


2. HDR模式传输方式

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

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

海思Hi3516A(4)HDR模式开发


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

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

XXXX_sensor_ctl.c实现sensor的初始化:

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模式。

//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_p_w_picpath_mode = cmos_set_p_w_picpath_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中实现,具体函数如下:

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文件

[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_p_w_picpath]
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建立通信。

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


6. 运行PQ Tools

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

海思Hi3516A(4)HDR模式开发

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

海思Hi3516A(4)HDR模式开发


7. 结果对比

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

海思Hi3516A(4)HDR模式开发

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

海思Hi3516A(4)HDR模式开发

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

海思Hi3516A(4)HDR模式开发

推荐阅读:
  1. 海思3516A与3516D的异同点
  2. 移植命令和库到海思相关芯片

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

海思 hdr 3516

上一篇:普通(实例)方法和实例方法的定义和调用

下一篇:网传Linux运维面试题解答(三)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》