MATLAB achieved by converting the image data into a format for transmission on a USB2.0 .bin

      USB2.0 recently prepared to do some FPGA-based data transmission, especially in image transmission. We encountered a variety of problems in the process of doing. Here's to do for the problem and how to deal encountered at the relevant summary.

     1, USB2.0 for transfer of image data can not be transferred ASCII code as UART as direct transmission TXT file, because the data would be in the TXT (this is the USB test software I use is related to I use Cypress USb Console) result in data transmission errors.

     2, if the direct transmission of the selected image will produce some of the image signal is not present, such as file transfer .bmp format, write header files represent this format appears.

    So the file should be transferred into the relevant .bin file. On the code:

          

CLC; 
Clear; 
% reading the image is converted into data, imread function () is a function, which can actually fill path according to their 
IMG = imread ( 'test.bmp'); 
% because of RGB image data having the three arrays were extracted 
IMG_R = IMG (:,:,. 1); 
img_g = IMG (:,:, 2); 

img_b = IMG (:,:,. 3); 

% of all of the data into, because we want to ultimately to convert data to be displayed on the VGA, 
% so should convert the raw data into 16BIT, RGB = 565 is taken high R 5BIT, G taken high 6BIT, B, taken high 5BIT 
[COL the ROW] = size (IMG_R);% acquiring an image size 
for R & lt =. 1: the ROW; 
       for C =. 1: COL; 
           out_data_h ((R & lt-. 1) * COL + C) = BITAND (IMG_R (R & lt, C), 248) + bitShift (BITAND (img_g (R & lt, C), 224), -. 5); 
           out_data_l ((R & lt-. 1) * COL + C) = bitShift (BITAND (img_g (R & lt, C), 28),. 3) + bitShift (BITAND (img_b (R & lt, C) , 248), -. 3); 
           
       End 
End 

% spliced writes data to a file .BIN  
fid = fopen ( 'test.bin', 'wb');
for i = 1: ROW * COL ;
    fwrite(fid,out_data_h(i));
    fwrite(fid,out_data_l(i));
end
fclose(fid);

  

   Need to explain that, when using MATLAB simulation is too big a picture is not set, otherwise not generate .BIN file, or generate the data does not open

   

This is the data format after we read the image data display table, that this picture size of the current reading is 100 * 100, the dimension is 3, representing the three RGB components, it uint8 represent each partition l is an amount represented by eight BIT.

And we often transmit the same data or general data is displayed in units of a byte, such as the actual situation and USB2.0 support 8BIT 16BIT data transmission. And for RGB565 mode.

 

     

Guess you like

Origin www.cnblogs.com/lgy-gdeu/p/11409492.html