相机分辨率为2048*2048,通常VGA的分辨率不匹配,需要降低分辨率。可以3*3范围内的9个像素合并成1个像素,最终分辨率682*682,数据量为465K*8bit,采取简单的均值或者中值的方式,为了避免噪声的影响,采用灰度取中值的方式。
先做一个简单的中值算法:
重要的营造3*3矩阵,采用行缓存,一共缓存三行,在移位;
具体实现:
Line_Shift_RAM_8Bit
#(
.RAM_Length (IMG_HDISP)
)
u_Line_Shift_RAM_8Bit
(
.clock (clk),
.clken (shift_clk_en), //pixel enable clock
// .aclr (1'b0),
.shiftin (row3_data), //Current data input
.taps0x (row2_data), //Last row data
.taps1x (row1_data), //Up a row data
.shiftout ()
);
wire [23:0] matrix_row1 = {matrix_p11, matrix_p12, matrix_p13}; //Just for test
wire [23:0] matrix_row2 = {matrix_p21, matrix_p22, matrix_p23};
wire [23:0] matrix_row3 = {matrix_p31, matrix_p32, matrix_p33};
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
{matrix_p11, matrix_p12, matrix_p13} <= 24'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 24'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 24'h0;
end
else if(read_frame_href)
begin
if(read_frame_clken) //Shift_RAM data read clock enable
begin
{matrix_p11, matrix_p12, matrix_p13} <= {matrix_p12, matrix_p13, row1_data}; //1th shift input
{matrix_p21, matrix_p22, matrix_p23} <= {matrix_p22, matrix_p23, row2_data}; //2th shift input
{matrix_p31, matrix_p32, matrix_p33} <= {matrix_p32, matrix_p33, row3_data}; //3th shift input
end
else
begin
{matrix_p11, matrix_p12, matrix_p13} <= {matrix_p11, matrix_p12, matrix_p13};
{matrix_p21, matrix_p22, matrix_p23} <= {matrix_p21, matrix_p22, matrix_p23};
{matrix_p31, matrix_p32, matrix_p33} <= {matrix_p31, matrix_p32, matrix_p33};
end
end
else
begin
{matrix_p11, matrix_p12, matrix_p13} <= 24'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 24'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 24'h0;
end
再做均值;
reg [10:0] mean_value1, mean_value2, mean_value3;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
mean_value1 <= 0;
mean_value2 <= 0;
mean_value3 <= 0;
end
else
begin
mean_value1 <= matrix_p11 + matrix_p12 + matrix_p13;
mean_value2 <= matrix_p21 + 11'd0 + matrix_p23;
mean_value3 <= matrix_p31 + matrix_p32 + matrix_p33;
end
end
//Step2
reg [10:0] mean_value4;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
mean_value4 <= 0;
else
mean_value4 <= mean_value1 + mean_value2 + mean_value3;
end