Hi35xx CX25828视频芯片手册移动侦测模块的翻译

    今天下午,一种莫名其妙的冲动,使我下定决心翻译 CX25828视频芯片手册移动侦测模块,刚开始还只是想了解了解,但我突然想做这个伟大的决定-->把他翻译出来;这可能会让那些英语很ok的人或者高手见笑,可我此时此刻对这种超越自己能力以及对英语的情结之心是难以意表的。见笑了,见笑了。害羞,欢迎拍砖。。。。。

    我刚开始做移动侦测是直接调用Hi3515 API完成的(软件实现,应该是基于海思自己的算法),搞了很长一段时间,觉得太郁闷了,很多参数或者功能都不太如意,所以,就想着从底层出发(硬件实现,CX25828A/D芯片有MD模块),通过I2C配置协处理器CX25828视频芯片的motion detect模块,翻译之后,真有点豁然开朗的感觉。由于对移动侦测有些了解,所以,翻译起来有些感觉,但,肯定有很多错误或不准确的地方,欢迎指正。大笑

    关于移动侦测技术原理与实现详情见:http://blog.csdn.net/huangminqiang201209/article/details/8252527

 

2.7 Motion Detection:移动侦测

    The CX25828 includes programmable motion detection logic which can immediately trigger flags to the host processor via the IRQ pin when motion is detected on any of the incoming analog video streams. This way, when the host receives a motion detection interrupt, it can, for example, alert other devices in the system to wake up and perform a certain function. These configuration parameters include:

大致意思:CX25828芯片包含移动侦测模块,当在输入视频流中侦测到有移动时,就会通过IRQ中断管脚立刻触发中断标识给主芯片(Hi3515)。通过这种方法,当主机接收到移动侦测中断时,它可以例如唤醒系统中其他设备以及运行某些操作,配置参数包括:

‹ Block Sizes for NTSC (720x480) and PAL (720x576)//块大小:N/P

‹ Even or Odd field for Motion Detection or no Motion Detection//运动/静止侦测中的奇/偶场

‹ Black/White Detection //黑白侦测

‹ Detection Frequency  //侦测频率(MD间隔)

‹ Motion Detection Thresholds  //侦测阈值

‹ Motion Detection Limits  //侦测限制

‹ Register Mask to mask off particular Motion Detection bits/functions //屏蔽寄存器,屏蔽特定侦测位或函数

 

   The CX25828 implements a hardware-based motion detection algorithm. The motion detection, as well as other image content based detection, is done through comparison of average luma values across fields, employing a grid-like system to divide the fields into 192 distinct regions. Each region can also be enabled or disabled through register control. The 192 distinct regions are referred to as blocks, organized as shown in Figure 1. Motion detection is performed on the unscaled output of the video decoders and on one field per frame.

大致意思:CX25828芯片移动侦测算法的实现是基于硬件的。移动侦测跟其他的基于图片内容的侦测一样,都是通过对图片平均亮度值比较实现的。它把图片分为192个小区域,每个区域都通过寄存器控制,192个区域如192个块一样如表1(呵呵,表太大了,不好输出)显示。移动侦测作用于未输出的视频解码器,并且每帧一场(top/bottom)。

 

   Motion and Still Image (No Motion) detection are mutually exclusive, i.e., they should not be enabled simultaneously. Black or White detection can be enabled simultaneously with either Motion or Still Image detection. Each is enabled or disabled through the programmable motion detection interrupt mask registers. The interrupt status for each decoder is reflected in a 5-bit interrupt status register provided for each of the detection methods, i.e., motion detection, white detection, black detection, still image detection, and end of field detection.

大致意思:移动或静止侦测是相对独立的,不能同时使能。黑/白侦测可以通过中断屏蔽寄存器控制同时使能,无论是移动或静止图像检测。侦测方法中,比如运动侦测、黑白侦测、静止图像检测以及尾场侦测等,每个编码器的中断状态寄存器状态位都是第5bit

 

   The motion detection logic can immediately trigger interrupts to the host processor via IRQ pin. Please refer to section Motion Detection Interrupt under Interrupts section for further details.

大致意思:移动侦测能通过IRQ管脚立刻触发中断给CPU,请根据以下中断部分获取更多信息。

 

2.7.1 Related Registers:相关寄存器

The following section discusses the motion detection feature in detail.

大致意思:接下来详细讨论移动侦测特点。

 

2.7.1.1 Programmable Block Size:可编程大小

   Block sizes are programmable to cover the PAL and NTSC video resolutions. Block sizes shown below, in pixel units, are halved in the vertical direction to represent the actual number of rows calculated for an interlaced frame. The following registers program the block size.

大致意思:可编程大小包括PALNTSC视频分辨率,如下,每个像素单元,一半在垂直方向的实际行数计算的交错帧,下面的寄存器将对此进行配置。

‹ PAL (720x576) - Block size of 44x24  //P值块大小

‹ NTSC (720x480) - Block size of 44x20 //N值块大小

MDET_[0-7]_GRID_XCNT0x810

[7:0] grid_blk_xcntà Width of block used in motion detection. For unscaled video this shouldbe set to 44. For scaled video it should be a multiple of 16块的宽度,用于未编码视频应该是44,用于编码视频应该是16默认44.

寄存器地址:

MDET_0_GRID_XCNT Address:0x810

MDET_1_GRID_XCNT Address:0x910

MDET_2_GRID_XCNT Address:0xA10

MDET_3_GRID_XCNT Address:0xB10

MDET_4_GRID_XCNT Address:0xC10

MDET_5_GRID_XCNT Address:0xD10

MDET_6_GRID_XCNT Address:0xE10

MDET_7_GRID_XCNT Address:0xF10

注:每个寄存器间相差0x100,下面只写0的地址

另外,因为寄存器的地址占16位即2个字节,而设备地址一个字节,I2C通信中(设备地址+寄存器地址+数据信息),每次只能发送一个int类型即4个字节,所以,每次只能对寄存器进行8位的配置,如果需要配置32为的地址,就只能通过连续4条指令完成了,并且要记得寄存器地址要++

MDET_[0-7]_GRID_YCNT0x814

[7:0] grid_blk_ycntà Height of block used in motion detection. For unscaled NTSC this value is 20. For unscaled PAL this value is 24. For scaled video, this should be a multiple of 12块的高度,用于未编码视频应该是24,用于编码视频应该是12默认12.

 

                  

2.7.1.2 Programmable Detection Frequency:可编程MD间隔

   Motion detection and other analytics performed by this block are performed on frames separated by a particular number of frames. This parameter can be programmed using the skip_frm_cnt register field. The following registers define the detection frequency.

大致意思:移动检测和其他分析的实现都是基于一个特定数量的帧分离。这个参数可以被编程使用的skip_frm_cnt寄存器配置。下面的寄存器定义了侦测的频率

MDET_[0-7]_SKIP0x80C

[12:8] skip_regionà Offsets the 16x12 grid from the left edge by the programmed number of pixels向左边缘偏移16*12块的像素数

[7:0] skip_frm_cntà Specify number of frames to skip. The default value 0 processes every frame跳过指定数量的帧(侦测间隔,单位为帧),默认0

 

2.7.1.3 Programmable Field Selection:可编程侦场选择

   The top_bot_field_sel register field indicates which fields can be used for motion detection, flat field detection, and constant frame detection. The supported modes are top field mode and bottom field mode.

In top field mode, average luma calculations and subsequent comparisons are only performed on top fields. In bottom field mode, average luma calculations and subsequent comparisons are only performed on bottom fields. The following registers program the field selection for motion detection.

大致意思:top_bot_field_sel寄存器可用于移动侦测侦场选择,平场侦测和固定帧检测。它支持底场模式和顶场模式。

顶场模式中,平均亮度计算和随后的比较只在顶场执行,底场模式也一样。下面的寄存器配置了场选择。

MDET_[0-7]_CTRL0x800

[0:0] ch_soft_rst —>Write a 1 to issue soft reset to channel. Self-Clearing:写1重置通道,自动清除。

[1:1] sram_rst—>1重置读取的本地内存地址,必须在读内存之前完成。

[2:2] channel_en—>1使能这个通道,0不使能这个通道

[3:3] top_bot_field_se—>1选择顶场,0选择底场。

注:实际上,普通电视的一帧画面需要由两遍扫描来完成,第一遍只扫描奇数行,即第l35……525行,第二遍扫描则只扫描偶数行,即第246……524行,这种扫描方式就是隔行扫描。一幅只含奇数行或偶数行的画面称为一(Field)”,其中只含奇数行的场称为奇数场或前场 (Top Field),只含偶数行的场称为偶数场或后场(Bottom Field)。也就是说一个奇数场加上一个偶数场等于一帧(一幅图象)

 

2.7.1.4 Programmable Motion Detection Threshold:可编程移动侦测阈值

   The motion detection threshold, mot_thresh, is an 8-bit programmable value used to determine the presence of motion. This value represents a minimum delta between scaled block average luma values to indicate motion within a block. The mot_numblk_det_thresh is an 8-bit programmable register field that controls how many blocks must detect motion before the frame comparison indicates motion detected to the host and external interrupt. The mot_numblk_det indicates the total number of blocks within the 192 grid regions that have detected motion. The following registers define the motion detection thresholds.

大致意思:移动侦测阈值,mot_thresh,是一个8位可编程值用来确定移动。这个值即最小亮度增量与平均亮度值对比来确定这个块是否移动。mot_numblk_det_thresh是一个8位的可编程寄存器,它控制必须移动侦测前帧比较的数量,并报告主机和外部中断。mot_numblk_det寄存器表示192个块中总共移动的块数。下面的寄存器定义了移动侦测的阈值。

MDET_[0-7]_MOTION_THRESH 0x820    

[7:0] mot_thresh—>Motion sensitivity threshold敏感度阈值

[15:8]mot_numblk_det_thresh—>Interrupt generated if mot_numblk_det is greater than this value如果mot_numblk_det大于此值,则产生中断。

[23:16] mot_numblk_det—> Number of blocks in the current field that meet motion detection criteria当前场满足移动侦测标准块的数量。

 

2.7.1.5 Programmable Still Image Threshold:可编程静止图像阈值

   The still image threshold, still_thresh, is an 8-bit programmable value used to determine a non-changing image. This value represents a maximum delta between scaled block average luma values to indicate a constant image within a block.

   The still_numblk_det register field indicates how many of the 192 grid regions detected a still image.

   The still_numblk_det_thresh register field controls how many blocks per frame must detect a still image to cause the still image frame counter to increment.

   The still_frm_thresh register field controls how many consecutive still frames are required before the interrupt is asserted. The following registers control the still image detection thresholds.

大致意思:见寄存器描述即可理解。

[7:0] still_thresh —> Still frame sensitivity threshold静止帧敏感度阈值。

[15:8] mot_numblk_det_thresh—>Number of blocks required for still frame.静止帧的块数

[23:16] still_frm_thresh—>Number of consecutive still frames required before interrupt中断前连续静止帧数

[31:24] still_numblk_det—>Number of blocks in the current field that meet still frame detection criteria当前场满足移动侦测标准块的数目。

 

2.7.1.6 Programmable Black and White Detection:可编程黑/色侦测

   Black and White detection is performed on each field/frame that is used for motion detection. In order to detect the Black and White, the following thresholds and limits are used. For every pixel of the field indicated by the top_bot_field_sel register field of the MDET_[0-7]_CTRL register, if the luma value is less than the black threshold, the black detection counter will be incremented. If the luma value is greater than the white threshold, the white detection counter will be incremented. If, at the end of the field, the black detection counter is greater than the black field limit value, a black detection will be signaled for that channel. If, at the end of the field, the white detection counter is greater than the white field limit value, a white detection will be signaled for that channel. The black and white detection counters will be reset before the beginning of the next field for detection.

大致意思:黑色和白色侦测用于移动侦测的每个场/帧。下面的阈值和限制用于黑白侦测,每场的像素由top_bot_field_sel寄存器中的MDET_[0-7]_CTRL寄存器决定,假如亮度值小于黑色的阈值,黑色检测计数器将递增。如果亮度值大于白色亮度阈值,白色检测计数器将会递增。在尾场,如果黑色计数器大于黑色场限制值,这个通道将发送黑色检测信号。白色同样。白色和黑色计数器在下一场侦测时将重置。

MDET_[0-7]_BLACK_THRESH 0x828

[7:0] black_thresh—>Threshold for black pixel detection.Pixel must be less than this value to be considered “black”黑色侦测像素阈值,像素必须小于“black”

[31:8] black_pix_cnt_thresh—>Black frame detected if number of “black” pixels is greater than this value:如果“black”个数大于此值则黑帧检测。

MDET_[0-7]_WHITE_THRESH0x82C白色侦测,类似黑色。

 

2.7.1.7 Programmable Motion Detection Interrupt Mask:可编程移动侦测中断屏蔽

   A motion detection interrupt mask register is provided to enable/disable the different types of detection; i.e., white detection, black detection, still image detection, motion detection, and end of field detection.

大致意思:中断屏蔽寄存器用于控制不同类型的侦测。如黑/白侦测、运动检测、静止图像检测以及尾场侦测等。

MDET_[0-7]_INTR_MSK0x804

[0:0] eof_msk—>End of field interrupt enable尾场中断使能

[1:1] mot_det_msk—>Motion detected interrupt enable移动侦测中断使能

[2:2] no_mot_det_msk—>No Motion detected interrupt enable无侦测中断使能

[3:3] black_det_msk —> Black detection Interrupt enable.黑侦测中断使能

[4:4] white_det_msk —>White detection Interrupt enable白侦测中断使能

注:初始化默认都为1,即都使能。

 

2.7.1.8 Programmable Motion Interrupt Status:可编程移动中断状态

   A 5-bit interrupt status register is provided for each of the detection methods, i.e., white detection, black detection, still image detection, motion detection, and end of field detection.

大致意思:一个5位的中断状态寄存器提供给每一种检测方法。如黑/白侦测、静止图像检测以及尾场侦测等。

MDET_[0-7]_INTR_STAT0x808

[4:4] white_det_stat —>White detection interrupt status. Write a 1 to clear.

[3:3] black_det_stat—>Black detection interrupt status. Write a 1 to clear.

[2:2] no_mot_det_stat —>No motion interrupt status. Write a 1 to clear.

[1:1] mot_det_stat —>Motion interrupt status. Write a 1 to clear.

[0:0] eof_stat —>End of field interrupt status. Write a 1 to clear.尾场中断状态,写1清零

 

2.7.1.9 Programmable Motion Detection Mask:可编程移动侦测屏蔽

   A 192-bit register field is provided to prevent individual blocks from causing the motion detection counter from incrementing. This will allow areas of the field to be masked off from motion detection. This mask will not affect the incrementing of the constant frame counter. The mask is controlled by the following registers.

大致意思:提供一个192bit的寄存器场来防止特定块造成的运动检测计数器递增。它将允许屏蔽场的区域,这不会影响不断帧计数器递增,由下面的寄存器控制。

MDET_[0-7]_MOT_MASK00x834

[31:0] mot_msk_31_0 —> Enable motion masking on a per block basis. Each frame is divided into 192 blocks. There is one mask bit per block.使能每一块运动屏蔽,每帧192块,每个块1bit

MDET_[0-7]_MOT_MASK10x838

MDET_[0-7]_MOT_MASK2:0x83C

MDET_[0-7]_MOT_MASK3:0x840

MDET_[0-7]_MOT_MASK4:0x844

MDET_[0-7]_MOT_MASK5:0x848

注:初始化都为0xffffffff,6*32=192.

 

2.7.1.10 Programmable Motion Detection Status:可编程移动侦测状态

   A 192-bit register field is provided to indicate that motion has been detected for each of the 192 blocks. The motion detection block status is tracked by the following registers.

大致意思:提供一个192bit的寄存器来检测192块中每一块是否移动,侦测块的状态有下面的寄存器触发。

MDET_[0-7]_MOT_STAT0:0x84C

[31:0] mot_stat_31_0 —> Status of motion detection for each block in the frame. A 1 indicates motion detected每帧图像移动侦测的状态,1表示检测到移动。

MDET_[0-7]_MOT_STAT1 :0x850

MDET_[0-7]_MOT_STAT2 :0x854

MDET_[0-7]_MOT_STAT3 :0x858

MDET_[0-7]_MOT_STAT4 :0x85C

MDET_[0-7]_MOT_STAT5 :0x860

注:初始化都为06*32=192.只读。

因为是第一次一下子就翻译那么多,而且就一下午时间,所以,难免有失误,望提醒纠正。

                                                                          2012.12.13  18:08  黄敏强


部分配置如下:

/***** 设置MD ************************************************************************************************/
unsigned int set_md(const int ch)
{
	int i = 0, tmp = 0;
	
    //soft reset to channel bit[0]
    tmp = IIC_Read( I2C_DEVADDR|1, MDET_0_CTRL + (0x100 * ch));
    IIC_Write(I2C_DEVADDR, MDET_0_CTRL + (0x100 * ch), tmp|0x1);

    //set motion sensitivity threshold bit[7:0] to 0x0a
    IIC_Write(I2C_DEVADDR, MDET_0_MOTION_THRESH + (0x100 * ch), 0x0a);
	//set motion number of blocks detected threshold bit[15:8] to 0x0a blocks
    IIC_Write(I2C_DEVADDR, MDET_0_MOTION_THRESH + (0x100 * ch) + 1, 0x0a);

    //set the skip frame count
	IIC_Write(I2C_DEVADDR, MDET_0_SKIP + (0x100 * ch), 0x02);
	//number of pixels bit[12:8]:16
	//tmp = IIC_Read(I2C_DEVADDR|1, MDET_0_SKIP + (0x100 * ch) + 1);
	//IIC_Write(I2C_DEVADDR, MDET_0_SKIP + (0x100 * ch) + 1, (tmp&0xe0)|0x10);
    
	//enable motion for all blocks
    for (i = 0; i < 24; i++)
    {
        IIC_Write(I2C_DEVADDR, MDET_0_MOT_MASK0 + (0x100 * ch) + (0x1 * i), 0xff);
    }
 
	//set Width and Height of block:PAL (720x576) - Block size of 44x24
    IIC_Write(I2C_DEVADDR, MDET_0_GRID_XCNT + (0x100 * ch), 0x2c);
    IIC_Write(I2C_DEVADDR, MDET_0_GRID_YCNT + (0x100 * ch), 0x18);

    return 0;
}

/***** 读取MD结果 ********************************************************************************************/
unsigned int process_read_md(const int ch)
{
	int i = 0, j = 0, cnt = 0, tmp = 0;
    int intr_msk, intr_stat;

	//open IIC device
	if( IIC_open() )
	{
        _ERROR("open %s err", I2C_DEVICE);
		return -1;
	}
	
	//read interrupt mask and status.
    intr_msk = IIC_Read(I2C_DEVADDR|1, MDET_0_INTR_MSK  + (0x100 * ch));
    intr_stat = IIC_Read(I2C_DEVADDR|1, MDET_0_INTR_STAT + (0x100 * ch));
	
	if(0 != (~intr_msk & intr_stat & 0x02))
	{
		for(i = 0; i < 24; i++)
		{
			tmp = IIC_Read(I2C_DEVADDR|1, MDET_0_MOT_STAT0 + (0x100 * ch) + (0x1 * i));
			for(j = 0; j < 8; j++)
			{
				if( (tmp & (1 << j)) )
				{
					cnt++;
				}
			}
		}
        
        if(1 <= cnt)//其实可以省略这个判断,只是为了避免0的发生。
        {
            printf("cnt: %d\n\n", cnt);
            //Read and write back the interrupt status register to clear it
            IIC_Write(I2C_DEVADDR, MDET_0_INTR_STAT + (0x100 * ch), intr_stat);
            
            IIC_close();
            return (1 << ch);
        }
	} 	
    
	//close IIC device
	IIC_close();	
	return 0;
}

附:关于I2C驱动可见:http://blog.csdn.net/huangminqiang201209/article/details/8506593



  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
/* CX20106A 超声波发送与接受程序 40KHz脉冲由单AT89S52单片机P1.0口送出,由P3.2(INT0)采用中断方式接收。 定时器0,定时器1中断方式工作,T1为8位自动重装模式(定时12.5us),T0为16位定时器(定时约65ms) 超声波接受采用外部中断INT0,接受到返回脉冲后,在外部中断程序中计算距离。 65ms超声波传播距离约65×10^(-3) × 340m/s =22.1m,距离足够了,远超CX20106A的测量范围。 40KHz对应波周期T=1/40KHz =25us,方波高占空比50%,高低电平宽度分别占0.5T=12.5us。 定时器T1采用8位自动重装模式(定时12.5us), 在单片机采用12MHz晶振的前提下,(2^8-X)×12/12 us =12.5us (1) 当X=0xF3时,2^8-X=13, (2) 当X=0xF4时,2^8-X = 12, 所以,取X=0xF3,0xF4均可以满足计时要求。 距离显示在4位数码管上,单位为cm。 */ /* 单片机P2口接74HC138(三八译码器)P2.3--74HC138:/EI、P2.2--74HC138:A2、P2.1--74HC138:A1、P2.0--74HC138:A0 译码器输出 Y0,Y1、Y2、Y3、Y4、Y5、Y6、Y7均低电平有效,分别选通1~8个数码管。包括2个四位一体数码管LG3641BH,共2x4=8个数码管。 数码管数据口为P0口。数码管为共阳4位一体数码管。 功能: 译码器输出为1——8个数码管的段选信号,轮流选择1——8数码管。 dispaly(uint d)将d(distance)的千、百、十、个依次显示在1~3号数码管上。 显示原理: 1、送出要显示的段数 2、P2译码,选择要显示的位 3、延时1——2ms,时间不能太长,否则会闪烁,也不能太短,否则会很暗。 4、取消段选,消隐! 若要显示多段,重复以上4步! */

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值