2017-03-08 64 views
0

幫助,我迷路了!獲取圖片指紋stm32f205來自Arduino

我正在使用Waveshare的指紋stm32f205,我連接到Arduino Uno R3並通過Java與RXTXComm庫進行通信。

我已經成功地將每個請求的字節都獲得到了Arduino,但缺點是當我收到跟蹤圖像的字節時,我無法將它們保存爲位圖或JPG。

我看到數據在以字節形式發送之前是沒有符號(0到255)的整數。

字節存儲在字節數組中,也存儲在另一個整數數組中。

您能否解釋或告訴我應該使用什麼算法將字節轉換爲圖像?

image指示如何發送圖像的數據。 enter image description here

回答

0

爲8位灰度陣列轉換成RGB:

int[] greyArraySource = ...; 

int[] rgbArray = new int[greyArraySource.length]; 
for(int i=0; i<greyArraySource.length; i++) { 
    int color = (int)aImageData[i]; 
    if(color < 0) 
    { 
     color = 256 + color; 
    } 
    rgbArray[i] = Color.rgb(color,color,color); 
} 

後,您可以將您的RGB數組轉換爲BufferedImage

// Initialize BufferedImage 
int width = ...; 
int height = ...; 
BufferedImage bufferedImage = new BufferedImage(width, height, 
    BufferedImage.TYPE_INT_RGB); 

// Set RGB array to the BufferedImage 
BufferedImage.setRGB(0,0,BufferedImage.getWidth(), 
    BufferedImage.getHeight(),rgbArray, 0, BufferedImage.getWidth()); 

轉換BuffuredImage以JPG:

File outputfile = new File("image.jpg"); 
ImageIO.write(bufferedImage, "jpg", outputfile); 

看來你的圖像是4位的,所以你需要改變轉換。如果你發佈數組值,也許我可以檢查。

+0

@Geekar您已經成功地得到你的形象嗎? – LaurentY

0

非常感謝您回覆@LaurentY,沒錯,圖像是4位的。 只需稍加修改即可應用您提供的代碼。

imgS = cadena.split(","); 
int[] rgbArray = new int[imgS.length]; 
      for(int i=0; i<imgS.length; i++) { 
       int color = Integer.parseInt(imgS[i]); 
       if(color < 0) 
       { 
        color = 256 + color; 
       } 
       rgbArray[i] = new Color(color, color, color).getRGB(); 
      } 
      BufferedImage bufferedImage = new BufferedImage(biWidth, biHeight, 
        BufferedImage.TYPE_INT_RGB); 

      // Set RGB array to the BufferedImage 
      bufferedImage.setRGB(0,0,bufferedImage.getWidth(), bufferedImage.getHeight(),rgbArray, 0, bufferedImage.getWidth()); 
      File outputfile = new File("D:\\finger.jpg"); 
      ImageIO.write(bufferedImage, "jpg", outputfile); 
     } catch (IOException ex) { 
      Logger.getLogger(LeerArduino.class.getName()).log(Level.SEVERE, null, ex); 
     } 

結果是這樣的Image

這裏我將數組的值保留在txt File中。每個值都用逗號分隔。

見你!

-1

我最近使用過這個指紋模塊。我在Matlab上的項目,我可以提取指紋圖像。使用串行端口終端程序(我使用CoolTerm)以十六進制格式的文本文件捕獲的圖像數據僅與空間分離。 您的圖像不是140x140/2個字節。在matlab中掃描你的txt文件,124x148/2 = 9176字節。此外,您可以將這些數字分成上下兩個半字節(4位)。首先,您必須將這些uint8轉換爲8位字節或兩位十六進制數。我的Java知識不是很好,但在MATLAB:

fileID = fopen('Value.txt','r'); A=textscan(fileID,'%u8','Delimiter',','); %text file to matrix YI=reshape(A{1,1},[62,148]); % image reshaped imshow(YI');

有了這個代碼,你的Value.txt文件給出了這樣的finger image