2017-03-08 68 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