欧美性猛交xxxx免费看_牛牛在线视频国产免费_天堂草原电视剧在线观看免费_国产粉嫩高清在线观看_国产欧美日本亚洲精品一5区

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

FPGA中如何使用Verilog處理圖像

OpenFPGA ? 來源:Hack電子 ? 作者:Hack電子 ? 2021-09-23 15:50 ? 次閱讀

FPGA項(xiàng)目旨在詳細(xì)展示如何使用Verilog處理圖像,從Verilog中讀取輸入位圖圖像(.bmp),處理并將處理結(jié)果寫入Verilog中的輸出位圖圖像。提供了用于讀取圖像、圖像處理和寫入圖像的完整 Verilog 代碼 。

在這個(gè)FPGA Verilog項(xiàng)目中,一些簡單的處理操作都是在Verilog中實(shí)現(xiàn)的,比如反相、亮度控制和閾值操作。圖像處理操作由“parameter.v”文件選擇,然后將處理后的圖像數(shù)據(jù)寫入位圖圖像 output.bmp 以供驗(yàn)證。所述圖像讀取Verilog代碼作為圖像傳感器/攝像機(jī)的模型的Verilog,它可以是用于在實(shí)時(shí)的功能驗(yàn)證真正有用的操作FPGA圖像處理項(xiàng)目。當(dāng)您想查看 BMP 格式的輸出圖像時(shí),圖像寫入部分對于測試也非常有用。在這個(gè)項(xiàng)目中,我在閱讀部分添加了一些簡單的圖像處理代碼來制作圖像處理的示例,但是您可以輕松地將其刪除以獲得原始圖像數(shù)據(jù)。學(xué)生提出的所有相關(guān)問題都在本文底部得到解答。首先,Verilog 不能直接讀取圖像。要在 Verilog 中讀取 .bmp 圖像,需要將圖像從位圖格式轉(zhuǎn)換為十六進(jìn)制格式。下面是將位圖圖像轉(zhuǎn)換為 .hex 文件的 Matlab 示例代碼。輸入圖像大小為 768x512,圖像 .hex 文件包括位圖圖像的 R、G、B 數(shù)據(jù)。

b=imread(‘kodim24.bmp’); % 24-bit BMP image RGB888

k=1;

for i=5121 % image is written from the last row to the first row

for j=1:768

a(k)=b(i,j,1);

a(k+1)=b(i,j,2);

a(k+2)=b(i,j,3);

k=k+3;

end

end

fid = fopen(‘kodim24.hex’, ‘wt’);

fprintf(fid, ‘%x

’, a);

disp(‘Text file write done’);disp(‘ ’);

fclose(fid);

要讀取圖像十六進(jìn)制數(shù)據(jù)文件,Verilog 使用以下命令:readmemb 如果圖像數(shù)據(jù)在二進(jìn)制文本文件中。讀取圖像.hex 文件后,將RGB 圖像數(shù)據(jù)保存到內(nèi)存中并讀出進(jìn)行處理。

下面是圖像讀取和處理部分的Verilog代碼:

/***************************************************** *****************************/

/******************** 模塊用于讀取和處理圖像 **************/

/***************************** ****************************************************/

/******************************************************************************/

/****************** Module for reading and processing image **************/

/******************************************************************************/

`include “parameter.v” // Include definition file

// fpga4student.com: FPGA projects for students

// FPGA project: Image processing in Verilog

module image_read

#(

parameter WIDTH = 768, // Image width

HEIGHT = 512, // Image height

INFILE = “。/img/kodim01.hex”, // image file

START_UP_DELAY = 100, // Delay during start up time

HSYNC_DELAY = 160,// Delay between HSYNC pulses

VALUE= 100, // value for Brightness operation

THRESHOLD= 90, // Threshold value for Threshold operation

SIGN=1 // Sign value using for brightness operation

// SIGN = 0: Brightness subtraction

// SIGN = 1: Brightness addition

input HCLK, // clock

input HRESETn, // Reset (active low)

output VSYNC, // Vertical synchronous pulse

// This signal is often a way to indicate that one entire image is transmitted.

// Just create and is not used, will be used once a video or many images are transmitted.

output reg HSYNC, // Horizontal synchronous pulse

// An HSYNC indicates that one line of the image is transmitted.

// Used to be a horizontal synchronous signals for writing bmp file.

output reg [7:0] DATA_R0, // 8 bit Red data (even)

output reg [7:0] DATA_G0, // 8 bit Green data (even)

output reg [7:0] DATA_B0, // 8 bit Blue data (even)

output reg [7:0] DATA_R1, // 8 bit Red data (odd)

output reg [7:0] DATA_G1, // 8 bit Green data (odd)

output reg [7:0] DATA_B1, // 8 bit Blue data (odd)

// Process and transmit 2 pixels in parallel to make the process faster, you can modify to transmit 1 pixels or more if needed

output ctrl_done // Done flag

);

//-------------------------------------------------

// Internal Signals

//-------------------------------------------------

parameter sizeOfWidth = 8; // data width

parameter sizeOfLengthReal = 1179648; // image data : 1179648 bytes: 512 * 768 *3

// local parameters for FSM

localparam ST_IDLE = 2‘b00,// idle state

ST_VSYNC = 2’b01,// state for creating vsync

ST_HSYNC = 2‘b10,// state for creating hsync

ST_DATA = 2’b11;// state for data processing

reg [1:0] cstate, // current state

nstate; // next state

reg start; // start signal: trigger Finite state machine beginning to operate

reg HRESETn_d; // delayed reset signal: use to create start signal

reg ctrl_vsync_run; // control signal for vsync counter

reg [8:0] ctrl_vsync_cnt; // counter for vsync

reg ctrl_hsync_run; // control signal for hsync counter

reg [8:0] ctrl_hsync_cnt; // counter for hsync

reg ctrl_data_run; // control signal for data processing

reg [7 : 0] total_memory [0 : sizeOfLengthReal-1];// memory to store 8-bit data image

// temporary memory to save image data : size will be WIDTH*HEIGHT*3

integer temp_BMP [0 : WIDTH*HEIGHT*3 - 1];

integer org_R [0 : WIDTH*HEIGHT - 1]; // temporary storage for R component

integer org_G [0 : WIDTH*HEIGHT - 1]; // temporary storage for G component

integer org_B [0 : WIDTH*HEIGHT - 1]; // temporary storage for B component

// counting variables

integer i, j;

// temporary signals for calculation: details in the paper.

integer tempR0,tempR1,tempG0,tempG1,tempB0,tempB1; // temporary variables in contrast and brightness operation

integer value,value1,value2,value4;// temporary variables in invert and threshold operation

reg [ 9:0] row; // row index of the image

reg [10:0] col; // column index of the image

reg [18:0] data_count; // data counting for entire pixels of the image

//-------------------------------------------------//

// -------- Reading data from input file ----------//

//-------------------------------------------------//

initial begin

$readmemh(INFILE,total_memory,0,sizeOfLengthReal-1); // read file from INFILE

end

// use 3 intermediate signals RGB to save image data

always@(start) begin

if(start == 1‘b1) begin

for(i=0; i《WIDTH*HEIGHT*3 ; i=i+1) begin

temp_BMP[i] = total_memory[i+0][7:0];

end

for(i=0; i《HEIGHT; i=i+1) begin

for(j=0; j《WIDTH; j=j+1) begin

// Matlab code writes image from the last row to the first row

// Verilog code does the same in reading to correctly save image pixels into 3 separate RGB mem

org_R[WIDTH*i+j] = temp_BMP[WIDTH*3*(HEIGHT-i-1)+3*j+0]; // save Red component

org_G[WIDTH*i+j] = temp_BMP[WIDTH*3*(HEIGHT-i-1)+3*j+1];// save Green component

org_B[WIDTH*i+j] = temp_BMP[WIDTH*3*(HEIGHT-i-1)+3*j+2];// save Blue component

end

end

end

end

//----------------------------------------------------//

// ---Begin to read image file once reset was high ---//

// ---by creating a starting pulse (start)------------//

//----------------------------------------------------//

always@(posedge HCLK, negedge HRESETn)

begin

if(!HRESETn) begin

start 《= 0;

HRESETn_d 《= 0;

end

else begin // ______

HRESETn_d 《= HRESETn; // | |

if(HRESETn == 1’b1 && HRESETn_d == 1‘b0) // __0___| 1 |___0____ : starting pulse

start 《= 1’b1;

else

start 《= 1‘b0;

end

end

//-----------------------------------------------------------------------------------------------//

// Finite state machine for reading RGB888 data from memory and creating hsync and vsync pulses --//

//-----------------------------------------------------------------------------------------------//

always@(posedge HCLK, negedge HRESETn)

begin

if(~HRESETn) begin

cstate 《= ST_IDLE;

end

else begin

cstate 《= nstate; // update next state

end

end

//-----------------------------------------//

//--------- State Transition --------------//

//-----------------------------------------//

// IDLE 。 VSYNC 。 HSYNC 。 DATA

always @(*) begin

case(cstate)

ST_IDLE: begin

if(start)

nstate = ST_VSYNC;

else

nstate = ST_IDLE;

end

ST_VSYNC: begin

if(ctrl_vsync_cnt == START_UP_DELAY)

nstate = ST_HSYNC;

else

nstate = ST_VSYNC;

end

ST_HSYNC: begin

if(ctrl_hsync_cnt == HSYNC_DELAY)

nstate = ST_DATA;

else

nstate = ST_HSYNC;

end

ST_DATA: begin

if(ctrl_done)

nstate = ST_IDLE;

else begin

if(col == WIDTH - 2)

nstate = ST_HSYNC;

else

nstate = ST_DATA;

end

end

endcase

end

// ------------------------------------------------------------------- //

// --- counting for time period of vsync, hsync, data processing ---- //

// ------------------------------------------------------------------- //

always @(*) begin

ctrl_vsync_run = 0;

ctrl_hsync_run = 0;

ctrl_data_run = 0;

case(cstate)

ST_VSYNC: begin ctrl_vsync_run = 1; end // trigger counting for vsync

ST_HSYNC: begin ctrl_hsync_run = 1; end // trigger counting for hsync

ST_DATA: begin ctrl_data_run = 1; end // trigger counting for data processing

endcase

end

// counters for vsync, hsync

always@(posedge HCLK, negedge HRESETn)

begin

if(~HRESETn) begin

ctrl_vsync_cnt 《= 0;

ctrl_hsync_cnt 《= 0;

end

else begin

if(ctrl_vsync_run)

ctrl_vsync_cnt 《= ctrl_vsync_cnt + 1; // counting for vsync

else

ctrl_vsync_cnt 《= 0;

if(ctrl_hsync_run)

ctrl_hsync_cnt 《= ctrl_hsync_cnt + 1; // counting for hsync

else

ctrl_hsync_cnt 《= 0;

end

end

// counting column and row index for reading memory

always@(posedge HCLK, negedge HRESETn)

begin

if(~HRESETn) begin

row 《= 0;

col 《= 0;

end

else begin

if(ctrl_data_run) begin

if(col == WIDTH - 2) begin

row 《= row + 1;

end

if(col == WIDTH - 2)

col 《= 0;

else

col 《= col + 2; // reading 2 pixels in parallel

end

end

end

//-------------------------------------------------//

//----------------Data counting---------- ---------//

//-------------------------------------------------//

always@(posedge HCLK, negedge HRESETn)

begin

if(~HRESETn) begin

data_count 《= 0;

end

else begin

if(ctrl_data_run)

data_count 《= data_count + 1;

end

end

assign VSYNC = ctrl_vsync_run;

assign ctrl_done = (data_count == 196607)? 1’b1: 1‘b0; // done flag

//-------------------------------------------------//

//------------- Image processing ---------------//

//-------------------------------------------------//

always @(*) begin

HSYNC = 1’b0;

DATA_R0 = 0;

DATA_G0 = 0;

DATA_B0 = 0;

DATA_R1 = 0;

DATA_G1 = 0;

DATA_B1 = 0;

if(ctrl_data_run) begin

HSYNC = 1‘b1;

`ifdef BRIGHTNESS_OPERATION

/**************************************/

/* BRIGHTNESS ADDITION OPERATION */

/**************************************/

if(SIGN == 1) begin

// R0

tempR0 = org_R[WIDTH * row + col ] + VALUE;

if (tempR0 》 255)

DATA_R0 = 255;

else

DATA_R0 = org_R[WIDTH * row + col ] + VALUE;

// R1

tempR1 = org_R[WIDTH * row + col+1 ] + VALUE;

if (tempR1 》 255)

DATA_R1 = 255;

else

DATA_R1 = org_R[WIDTH * row + col+1 ] + VALUE;

// G0

tempG0 = org_G[WIDTH * row + col ] + VALUE;

if (tempG0 》 255)

DATA_G0 = 255;

else

DATA_G0 = org_G[WIDTH * row + col ] + VALUE;

tempG1 = org_G[WIDTH * row + col+1 ] + VALUE;

if (tempG1 》 255)

DATA_G1 = 255;

else

DATA_G1 = org_G[WIDTH * row + col+1 ] + VALUE;

// B

tempB0 = org_B[WIDTH * row + col ] + VALUE;

if (tempB0 》 255)

DATA_B0 = 255;

else

DATA_B0 = org_B[WIDTH * row + col ] + VALUE;

tempB1 = org_B[WIDTH * row + col+1 ] + VALUE;

if (tempB1 》 255)

DATA_B1 = 255;

else

DATA_B1 = org_B[WIDTH * row + col+1 ] + VALUE;

end

else begin

/**************************************/

/* BRIGHTNESS SUBTRACTION OPERATION */

/**************************************/

// R0

tempR0 = org_R[WIDTH * row + col ] - VALUE;

if (tempR0 《 0)

DATA_R0 = 0;

else

DATA_R0 = org_R[WIDTH * row + col ] - VALUE;

// R1

tempR1 = org_R[WIDTH * row + col+1 ] - VALUE;

if (tempR1 《 0)

DATA_R1 = 0;

else

DATA_R1 = org_R[WIDTH * row + col+1 ] - VALUE;

// G0

tempG0 = org_G[WIDTH * row + col ] - VALUE;

if (tempG0 《 0)

DATA_G0 = 0;

else

DATA_G0 = org_G[WIDTH * row + col ] - VALUE;

tempG1 = org_G[WIDTH * row + col+1 ] - VALUE;

if (tempG1 《 0)

DATA_G1 = 0;

else

DATA_G1 = org_G[WIDTH * row + col+1 ] - VALUE;

// B

tempB0 = org_B[WIDTH * row + col ] - VALUE;

if (tempB0 《 0)

DATA_B0 = 0;

else

DATA_B0 = org_B[WIDTH * row + col ] - VALUE;

tempB1 = org_B[WIDTH * row + col+1 ] - VALUE;

if (tempB1 《 0)

DATA_B1 = 0;

else

DATA_B1 = org_B[WIDTH * row + col+1 ] - VALUE;

end

`endif

/**************************************/

/* INVERT_OPERATION */

/**************************************/

`ifdef INVERT_OPERATION

value2 = (org_B[WIDTH * row + col ] + org_R[WIDTH * row + col ] +org_G[WIDTH * row + col ])/3;

DATA_R0=255-value2;

DATA_G0=255-value2;

DATA_B0=255-value2;

value4 = (org_B[WIDTH * row + col+1 ] + org_R[WIDTH * row + col+1 ] +org_G[WIDTH * row + col+1 ])/3;

DATA_R1=255-value4;

DATA_G1=255-value4;

DATA_B1=255-value4;

`endif

/**************************************/

/********THRESHOLD OPERATION *********/

/**************************************/

`ifdef THRESHOLD_OPERATION

value = (org_R[WIDTH * row + col ]+org_G[WIDTH * row + col ]+org_B[WIDTH * row + col ])/3;

if(value 》 THRESHOLD) begin

DATA_R0=255;

DATA_G0=255;

DATA_B0=255;

end

else begin

DATA_R0=0;

DATA_G0=0;

DATA_B0=0;

end

value1 = (org_R[WIDTH * row + col+1 ]+org_G[WIDTH * row + col+1 ]+org_B[WIDTH * row + col+1 ])/3;

if(value1 》 THRESHOLD) begin

DATA_R1=255;

DATA_G1=255;

DATA_B1=255;

end

else begin

DATA_R1=0;

DATA_G1=0;

DATA_B1=0;

end

`endif

end

end

endmodule

“parameter.v”文件也是定義輸入輸出文件的路徑和名稱。對圖像進(jìn)行處理后,需要將處理后的數(shù)據(jù)寫入輸出圖像進(jìn)行驗(yàn)證。

以下Verilog代碼是將處理后的圖像數(shù)據(jù)寫入位圖圖像進(jìn)行驗(yàn)證:

/******************** 寫入.bmp圖像的模塊************/

/********** ****************************************************/

module image_write #(parameter

WIDTH = 768, // Image width

HEIGHT = 512, // Image height

INFILE = “output.bmp”, // Output image

BMP_HEADER_NUM = 54 // Header for bmp image

input HCLK, // Clock input

HRESETn, // Reset active low

input hsync, // Hsync pulse

input [7:0] DATA_WRITE_R0, // Red 8-bit data (odd)

input [7:0] DATA_WRITE_G0, // Green 8-bit data (odd)

input [7:0] DATA_WRITE_B0, // Blue 8-bit data (odd)

input [7:0] DATA_WRITE_R1, // Red 8-bit data (even)

input [7:0] DATA_WRITE_G1, // Green 8-bit data (even)

input [7:0] DATA_WRITE_B1, // Blue 8-bit data (even)

output reg Write_Done

);

// fpga4student.com FPGA projects, Verilog projects, VHDL projects

//-----------------------------------//

//-------Header data for bmp image-----//

//-------------------------------------//

// Windows BMP files begin with a 54-byte header

initial begin

BMP_header[ 0] = 66;BMP_header[28] =24;

BMP_header[ 1] = 77;BMP_header[29] = 0;

BMP_header[ 2] = 54;BMP_header[30] = 0;

BMP_header[ 3] = 0;BMP_header[31] = 0;

BMP_header[ 4] = 18;BMP_header[32] = 0;

BMP_header[ 5] = 0;BMP_header[33] = 0;

BMP_header[ 6] = 0;BMP_header[34] = 0;

BMP_header[ 7] = 0;BMP_header[35] = 0;

BMP_header[ 8] = 0;BMP_header[36] = 0;

BMP_header[ 9] = 0;BMP_header[37] = 0;

BMP_header[10] = 54;BMP_header[38] = 0;

BMP_header[11] = 0;BMP_header[39] = 0;

BMP_header[12] = 0;BMP_header[40] = 0;

BMP_header[13] = 0;BMP_header[41] = 0;

BMP_header[14] = 40;BMP_header[42] = 0;

BMP_header[15] = 0;BMP_header[43] = 0;

BMP_header[16] = 0;BMP_header[44] = 0;

BMP_header[17] = 0;BMP_header[45] = 0;

BMP_header[18] = 0;BMP_header[46] = 0;

BMP_header[19] = 3;BMP_header[47] = 0;

BMP_header[20] = 0;BMP_header[48] = 0;

BMP_header[21] = 0;BMP_header[49] = 0;

BMP_header[22] = 0;BMP_header[50] = 0;

BMP_header[23] = 2;BMP_header[51] = 0;

BMP_header[24] = 0;BMP_header[52] = 0;

BMP_header[25] = 0;BMP_header[53] = 0;

BMP_header[26] = 1; BMP_header[27] = 0;

end

//---------------------------------------------------------//

//--------------Write .bmp file ----------------------//

//----------------------------------------------------------//

initial begin

fd = $fopen(INFILE, “wb+”);

end

always@(Write_Done) begin // once the processing was done, bmp image will be created

if(Write_Done == 1’b1) begin

for(i=0; i《BMP_HEADER_NUM; i=i+1) begin

$fwrite(fd, “%c”, BMP_header[i][7:0]); // write the header

end

for(i=0; i《WIDTH*HEIGHT*3; i=i+6) begin

// write R0B0G0 and R1B1G1 (6 bytes) in a loop

$fwrite(fd, “%c”, out_BMP[i ][7:0]);

$fwrite(fd, “%c”, out_BMP[i+1][7:0]);

$fwrite(fd, “%c”, out_BMP[i+2][7:0]);

$fwrite(fd, “%c”, out_BMP[i+3][7:0]);

$fwrite(fd, “%c”, out_BMP[i+4][7:0]);

$fwrite(fd, “%c”, out_BMP[i+5][7:0]);

end

end

end

位圖圖像的標(biāo)頭數(shù)據(jù)非常重要,在這里發(fā)布。如果沒有標(biāo)題數(shù)據(jù),則無法正確顯示寫入的圖像。在 Verilog HDL 中,$fwrite 命令用于將數(shù)據(jù)寫入文件。

接下來,讓我們編寫一個(gè)測試平臺 Verilog 代碼來驗(yàn)證圖像處理操作。

`timescale 1ns/1ps /**************************************************/

/******* Testbench for simulation ****************/

/*********************************************/

// fpga4student.com FPGA projects, Verilog projects, VHDL projects

// Verilog project: Image processing in Verilog

`include “parameter.v” // include definition file module tb_simulation;

//------------------ // Internal Signals

//-------------------------------------------------

reg HCLK, HRESETn;

wire vsync;

wire hsync;

wire [ 7 : 0] data_R0;

wire [ 7 : 0] data_G0;

wire [ 7 : 0] data_B0;

wire [ 7 : 0] data_R1;

wire [ 7 : 0] data_G1;

wire [ 7 : 0] data_B1;

wire enc_done;

image_read #(.INFILE(`INPUTFILENAME))

u_image_read

( .HCLK (HCLK ),

.HRESETn (HRESETn ),

.VSYNC (vsync ),

.HSYNC (hsync ),

.DATA_R0 (data_R0 ),

.DATA_G0 (data_G0 ),

.DATA_B0 (data_B0 ),

.DATA_R1 (data_R1 ),

.DATA_G1 (data_G1 ),

.DATA_B1 (data_B1 ),

.ctrl_done (enc_done)

);

image_write #(.INFILE(`OUTPUTFILENAME))

u_image_write (

.HCLK(HCLK),

.HRESETn(HRESETn),

.hsync(hsync),

.DATA_WRITE_R0(data_R0),

.DATA_WRITE_G0(data_G0),

.DATA_WRITE_B0(data_B0),

.DATA_WRITE_R1(data_R1),

.DATA_WRITE_G1(data_G1),

.DATA_WRITE_B1(data_B1),

.Write_Done()

);

//------------- // Test Vectors

//-------------------------------------

initial

begin

HCLK = 0;

forever #10 HCLK = ~HCLK;

end

initial

begin

HRESETn = 0;

#25 HRESETn = 1;

end endmodule

最后,我們擁有一切來運(yùn)行模擬來驗(yàn)證圖像處理代碼。讓我們使用下圖作為輸入位圖文件:

運(yùn)行仿真 6ms,關(guān)閉仿真并打開輸出圖像以檢查結(jié)果。以下是參數(shù).v中選定操作處理的輸出圖像:

由于讀取代碼是為了模擬目的而對圖像傳感器/相機(jī)進(jìn)行建模,因此建議不要合成代碼。如果你真的想綜合處理代碼并直接在FPGA上運(yùn)行,你需要將代碼中的這些圖像數(shù)組(total_memory、temp_BMP、org_R、org_B、org_G)替換為塊存儲器(RAM)和設(shè)計(jì)地址生成器來讀取圖像塊內(nèi)存中的數(shù)據(jù)。

問題的答案:

此圖像處理項(xiàng)目的完整 Verilog 代碼可在此處下載。運(yùn)行模擬大約 6ms 并關(guān)閉模擬,然后您將能夠看到輸出圖像。

https://github.com/suisuisi/FPGAandImage/blob/main/Image/012_Others/Verilog_Image_Processing.zip

讀取部分作為圖像傳感器/相機(jī)的 Verilog 模型運(yùn)行(輸出 RGB 數(shù)據(jù)、HSYNC、VSYNC、HCLK)。Verilog 圖像讀取代碼對于實(shí)時(shí) FPGA 圖像/視頻項(xiàng)目中的功能驗(yàn)證非常有用。

3.在這個(gè)項(xiàng)目中,我添加了圖像處理部分,做一個(gè)圖像增強(qiáng)的例子。如果您只想使用圖像傳感器模型來驗(yàn)證您的圖像處理設(shè)計(jì),您可以輕松移除處理部分以僅獲取原始圖像數(shù)據(jù)。

4.圖像保存到三個(gè)獨(dú)立的RGB mem中:由于Matlab代碼是將圖像16進(jìn)制文件從最后一行寫到第一行,所以RGB保存代碼(org_R, org_B, org_G)在讀取temp_BMP內(nèi)存時(shí)也是這樣做的,保存RGB數(shù)據(jù)正確。如果您想以不同的方式進(jìn)行,您可以相應(yīng)地更改它。

如果您想更改圖像大小,您可能會發(fā)現(xiàn)以下對 BMP 標(biāo)題的解釋很有用:

圖像大小 = 768*512*3= 1179648 字節(jié)

BMP 標(biāo)題 = 54 字節(jié)

BMP 文件大小 = 圖像大小 + BMP 標(biāo)題 = 1179702 字節(jié)

將其轉(zhuǎn)換為十六進(jìn)制數(shù):1179702 in Decimal = 120036 in Hexade

然后 BMP 文件的 4 字節(jié)大?。?0H, 12 in Hexa = 18 Decimal, 00H, 36 in Hexa = 54 Decimal

這就是我們?nèi)绾蔚玫揭韵轮担?/p>

BMP_header[2] = 54;

BMP_header[3] = 0;

BMP_header[4] = 18;

BMP_header[5] = 0;

圖像寬度 = 768 =》 十六進(jìn)制:0x0300。圖像寬度的 4 個(gè)字節(jié)是

0、3、0、0。這就是您獲得以下值的方式:BMP_header[18] = 0;

BMP_header[19] = 3;

BMP_header[20] = 0;

BMP_header[21] = 0;

圖像高度 = 512 =》 十六進(jìn)制:0x0200。圖像寬度的 4 個(gè)字節(jié)是 0, 2, 0, 0。這就是我們?nèi)绾蔚玫揭韵轮担?/p>

BMP_header[22] = 0;

BMP_header[23] = 2;

BMP_header[24] = 0;

BMP_header[25] = 0;

您不應(yīng)綜合此代碼,因?yàn)樗皇菫樵?FPGA 上運(yùn)行而設(shè)計(jì)的,而是用于功能驗(yàn)證目的。 如果你真的想合成這段代碼(讀取和處理)并將圖像加載到 FPGA中直接在 FPGA 上處理,請將所有 temp. 變量 (org_R, org_B, org_G, tmp_BMP = total_memory) 并生成地址以讀取圖像數(shù)據(jù)(刪除 always @(start) 和所有“for 循環(huán)” - 這些用于模擬目的)。有兩種方式:1. 寫一段RAM代碼,用$readmemh將圖像數(shù)據(jù)初始化到內(nèi)存中;2. 使用 Xilinx Core Generator 或 Altera MegaFunction 生成塊存儲器并將圖像數(shù)據(jù)加載到存儲器的初始值(Xilinx Core Gen. 為 .coe 文件,Altera MegaFunction 為 .mif 文件),然后從存儲器中讀取圖像數(shù)據(jù)并處理它(FSM 設(shè)計(jì))。

在這個(gè)項(xiàng)目中,為了加快處理速度,同時(shí)讀取兩個(gè)偶數(shù)和舊像素,但您可以根據(jù)您的設(shè)計(jì)更改正在讀取的像素?cái)?shù)。

編寫Verilog代碼對于測試目的也非常有幫助,因?yàn)槟梢钥吹紹MP 格式的輸出。

9.如果要做實(shí)時(shí)圖像處理,可以查看camera接口代碼這個(gè):https://www.fpga4student.com/2018/08/basys-3-fpga-ov7670-camera.html

責(zé)任編輯:haq

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • FPGA
    +關(guān)注

    關(guān)注

    1630

    文章

    21801

    瀏覽量

    606318
  • Verilog
    +關(guān)注

    關(guān)注

    28

    文章

    1352

    瀏覽量

    110441
  • HDL
    HDL
    +關(guān)注

    關(guān)注

    8

    文章

    328

    瀏覽量

    47479

原文標(biāo)題:使用 Verilog HDL 在 FPGA 上進(jìn)行圖像處理

文章出處:【微信號:Open_FPGA,微信公眾號:OpenFPGA】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦

    FPGA圖像處理基礎(chǔ)----實(shí)現(xiàn)緩存卷積窗口

    像素行與像素窗口 一幅圖像是由一個(gè)個(gè)像素點(diǎn)構(gòu)成的,對于一幅480*272大小的圖片來說,其寬度是480,高度是272。在使用FPGA進(jìn)行圖像處理時(shí),最關(guān)鍵的就是使用
    的頭像 發(fā)表于 02-07 10:43 ?99次閱讀
    <b class='flag-5'>FPGA</b><b class='flag-5'>圖像</b><b class='flag-5'>處理</b>基礎(chǔ)----實(shí)現(xiàn)緩存卷積窗口

    基于FPGA實(shí)現(xiàn)圖像直方圖設(shè)計(jì)

    簡單,單采用FPGA來實(shí)現(xiàn)直方圖的統(tǒng)計(jì)就稍顯麻煩。若使用Xilinx和Altera的FPGA芯片,可以使用HLS來進(jìn)行圖像的加速處理。但這暫時(shí)不是我的重點(diǎn)。 用C語言實(shí)現(xiàn)直方圖統(tǒng)計(jì):u
    的頭像 發(fā)表于 12-24 10:24 ?241次閱讀
    基于<b class='flag-5'>FPGA</b>實(shí)現(xiàn)<b class='flag-5'>圖像</b>直方圖設(shè)計(jì)

    DFT在圖像處理的作用 DFT在音頻信號處理的應(yīng)用

    DFT在圖像處理的作用 離散傅里葉變換(Discrete Fourier Transform,簡稱DFT)是一種將信號從時(shí)域轉(zhuǎn)換到頻域的數(shù)學(xué)工具,它在圖像
    的頭像 發(fā)表于 12-20 09:18 ?492次閱讀

    Verilog 測試平臺設(shè)計(jì)方法 Verilog FPGA開發(fā)指南

    Verilog測試平臺設(shè)計(jì)方法是Verilog FPGA開發(fā)的重要環(huán)節(jié),它用于驗(yàn)證Verilog設(shè)計(jì)的正確性和性能。以下是一個(gè)詳細(xì)的
    的頭像 發(fā)表于 12-17 09:50 ?448次閱讀

    傅立葉變換在圖像處理的作用

    傅里葉變換在圖像處理中發(fā)揮著至關(guān)重要的作用。以下是傅里葉變換在圖像處理的幾個(gè)主要作用: 一、圖像
    的頭像 發(fā)表于 12-06 16:55 ?754次閱讀

    FPGA 實(shí)時(shí)信號處理應(yīng)用 FPGA圖像處理的優(yōu)勢

    優(yōu)勢之一是其并行處理能力。與傳統(tǒng)的CPU或GPU相比,FPGA可以同時(shí)執(zhí)行多個(gè)操作,這在圖像處理尤為重要,因?yàn)?/div>
    的頭像 發(fā)表于 12-02 10:01 ?894次閱讀

    Verilog vhdl fpga

    編程語言,熟悉時(shí)序約束、時(shí)序分析方法; 4.熟悉FPGA開發(fā)環(huán)境及仿真調(diào)試工具。 5.熟悉FPGA外部存儲控制器及數(shù)據(jù)傳輸接口,如E2PROM、FLASH、DDR等。有FPGA高速數(shù)據(jù)處理
    發(fā)表于 11-12 16:40

    FPGA圖像處理領(lǐng)域的優(yōu)勢有哪些?

    單元和可編程互聯(lián)線,可以實(shí)現(xiàn)高度并行的數(shù)據(jù)處理。在圖像處理任務(wù),如圖像預(yù)處理、特征提取和
    發(fā)表于 10-09 14:36

    FPGA Verilog HDL有什么奇技巧?

    今天給大俠帶來在FPAG技術(shù)交流群里平時(shí)討論的問題答疑合集(九),以后還會多推出本系列,話不多說,上貨。 交流問題(一) Q:Verilog 有什么奇技淫巧? A:在 Verilog ,以下這些
    發(fā)表于 09-12 19:10

    【招聘】verilog vhdl FPGA

    1.熟悉FPGA架構(gòu)及應(yīng)用,熟悉圖像算法的FPGA實(shí)現(xiàn)。 2.熟悉verilog vhdl,熟悉Xilinx或Intel等開發(fā)工具。 3.有AI算法
    發(fā)表于 09-02 15:50

    基于FPGA圖像采集與顯示系統(tǒng)設(shè)計(jì)

    源和固有的并行處理能力,在數(shù)字信號處理、硬件加速、汽車電子等領(lǐng)域得到了廣泛應(yīng)用。在圖像采集與顯示系統(tǒng),FPGA能夠?qū)崿F(xiàn)高速、并行的數(shù)據(jù)
    的頭像 發(fā)表于 07-17 10:58 ?2118次閱讀

    FPGA verilog HDL實(shí)現(xiàn)中值濾波

    今天給大俠簡單帶來FPGA verilog HDL實(shí)現(xiàn)中值濾波,話不多說,上貨。一、實(shí)現(xiàn)步驟: 1、查看了中值濾波實(shí)現(xiàn)相關(guān)的網(wǎng)站和paper; 2、按照某篇paper的設(shè)計(jì)思想進(jìn)行編程實(shí)現(xiàn)
    發(fā)表于 06-18 18:50

    FPGA設(shè)計(jì)經(jīng)驗(yàn)之圖像處理

    系列:基于 FPGA圖像邊緣檢測系統(tǒng)設(shè)計(jì)(sobel算法) FPGA設(shè)計(jì) Verilog HDL實(shí)現(xiàn)基本的
    發(fā)表于 06-12 16:26

    基于FPGA的實(shí)時(shí)邊緣檢測系統(tǒng)設(shè)計(jì),Sobel圖像邊緣檢測,FPGA圖像處理

    運(yùn)行時(shí), FPGA 并行運(yùn)算平臺首先完成對攝像頭的初始化和寄存器配置,配置完成之后讀取實(shí)時(shí)的圖像數(shù)據(jù)存入 SDRAM 存儲器,在 FPGA 芯片內(nèi)部并行實(shí)現(xiàn)
    發(fā)表于 05-24 07:45

    FPGA設(shè)計(jì) Verilog HDL實(shí)現(xiàn)基本的圖像濾波處理仿真

    今天給大俠帶來FPGA設(shè)計(jì)中用Verilog HDL實(shí)現(xiàn)基本的圖像濾波處理仿真,話不多說,上貨。 1、用matlab代碼,準(zhǔn)備好把圖片轉(zhuǎn)化成Vivado Simulator識別的
    發(fā)表于 05-20 16:44