使用 Morpho SDK 旋转指纹

问题描述

我正在使用 MOrpho sdk 来捕获指纹,但我遇到了一些设备以反向布局捕获指纹的问题(意味着捕获图像应该从左到右,但它是从右到左捕获) ,所以我到目前为止所做的是将接收到的字节 [] 转换为位图,然后旋转它。但是它没有工作,因为从位图转换回来后byte[]的内容有些改变。

我只想知道如何使用 morpho sdk 方法轻松更改布局。

下面是我正在捕获的函数。

 public FTPImage fpCapture(int timeoutInSeconds) {
        Logger.d("fpCapture ():::");
        if (context == null) {
            Logger.e("fpCapture()::Context is null");
            return null;
        }
        TemplateList templateList = new TemplateList();
        templateList.setActivateFullImageRetrieving(true);
        try {
            Logger.d("Device is not null:");
            MorphoImage morphoImage = new MorphoImage();
            int detectModeChoice = DetectionMode.MORPHO_ENROLL_DETECT_MODE.getValue() | DetectionMode.MORPHO_FORCE_FINGER_ON_TOP_DETECT_MODE.getValue();
            int detectModeChoice1= DetectionMode.MORPHO_ENROLL_DETECT_MODE.getValue() | DetectionMode.MORPHO_DEFAULT_DETECT_MODE.getValue();
            int detectModeChoice2= DetectionMode.MORPHO_VERIF_DETECT_MODE.getValue() | DetectionMode.MORPHO_DEFAULT_DETECT_MODE.getValue();
            int detectModeChoice3= DetectionMode.MORPHO_DEFAULT_DETECT_MODE.getValue();


            int acquisitionThreshold = 0;
            int compressionRate = 0;
            int callbackCmd = 0;
            int ret = morphoDevice.getImage(timeoutInSeconds,acquisitionThreshold,CompressionAlgorithm.MORPHO_NO_COMPRESS,compressionRate,detectModeChoice2,LatentDetection.LATENT_DETECT_ENABLE,morphoImage,callbackCmd,null);

            if (ret == 0) {

                Logger.d("MorphoPlugin::--------- "+"d="+detectModeChoice+"-d1"+detectModeChoice1+"d2="+detectModeChoice2+"d3"+detectModeChoice3);


               /* Logger.d("MorphoPlugin::--bytearray "+new String(morphoImage.getImage().toString()));
                Logger.d("MorphoPlugin::--bytearray-- "+Arrays.toString(morphoImage.getImage()).toString());

                String s = new String(morphoImage.getImage(),"UTF-8");

                Logger.d("MorphoPlugin::--sttinh image bytearay-- "+s.getBytes("UTF-8"));
                //fpCaptureAndConvert(20);

                String s1 = new String(morphoImage.getImage(),"UTF-8");

                Logger.d("MorphoPlugin::--template image bytearay-- "+s1.getBytes("UTF-8"));
*/
               /* Bitmap bitmap = BitmapFactory.decodeByteArray(morphoImage.getImage(),morphoImage.getImage().length);

                YuvImage yuvimage=new YuvImage(morphoImage.getImage(),ImageFormat.NV21,100,null);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                yuvimage.compressToJpeg(new Rect(0,100),80,baos);
                byte[] jdata = baos.toByteArray();

                // Convert to Bitmap
                Bitmap bmp = BitmapFactory.decodeByteArray(jdata,jdata.length);
                System.out.println("Bitmap Name 3" + bmp);

                if (bmp!=null)
                {
                    Logger.d("MorphoPlugin::--bitmap not null"+bmp.toString());
                    Logger.d("MorphoPlugin::--bitmap not null-a1-"+morphoImage.getImage().toString());
                    byte[] b1=getByteArray(bmp);
                    Logger.d("MorphoPlugin::--bitmap not null-bytearr-"+b1.toString());
                }else{
                    Logger.d("MorphoPlugin::--bitmap  null");
                }*/

             //   Logger.d("MorphoPlugin:: "+"normal bytearray"+fpCaptureAndConvert(5));

                Logger.d("MorphoPlugin::--------- "+"actual bytearray[]"+Arrays.toString(morphoImage.getImage()).toString());

              /*  byte[] bytearray1 =  getByteArray(bmp);

                Logger.d("MorphoPlugin:: "+"reversed bytearray1"+Arrays.toString(bytearray1).toString());
*/
                //byte[] rotatedbyte=rotateByteArray(morphoImage.getImage());

                //byte[] rotatedbyte1=rotateByteArray(rotatedbyte);

                int imageRowNumber = morphoImage.getMorphoImageHeader()
                        .getNbRow();
                int imageColumnNumber = morphoImage.getMorphoImageHeader()
                        .getNbColumn();

              //  byte[] rotated=rotateYUV420Degree90(morphoImage.getImage(),imageColumnNumber,imageRowNumber);


              /*  //For decoding
                String str=getStringImage(bitmp);
                byte convertedBytearray[]= android.util.Base64.decode(str,android.util.Base64.DEFAULT);
                Bitmap bmp=getBitmapFromRawImage(convertedBytearray);

//                Logger.d("MorphoPlugin::--------- "+"converted bytearray[]"+new String(convertedBytearray));
//                Logger.d("MorphoPlugin:: "+"converted bitmap"+bmp);

//
                Bitmap rotatetedBitmp= rotateImage(180,bmp);

                String rotatedstr=getStringImage(rotatetedBitmp);
                byte rotatedBytearray[]= android.util.Base64.decode(rotatedstr,android.util.Base64.DEFAULT);
*/
                Bitmap rotatetedBitmp=rotateImage(morphoImage.getImage());


               // createExternalImage(rotatetedBitmp);
                //createExternalImage(bitmp);




              //  Logger.d("MorphoPlugin:: "+"bitmap with rot"+rotatetedBitmp);

               // createExternalImage(bitmp);

               /* byte[] b1=getByteArray(bitmp);
                byte[] b2=getByteArray(rotatetedBitmp);
                Logger.d("MorphoPlugin:: "+"before rotation bytearray"+b1);
                Logger.d("MorphoPlugin:: "+"after rotation bytearray"+b2);
*/
                //Logger.d("MorphoPlugin::--bytearray "+new String(morphoImage.getImage()));
                FTPImage ftpImage = new FTPImage();
                ftpImage.imgData = morphoImage.getImage();
                ftpImage.imgHeight = morphoImage.getMorphoImageHeader().getNbRow();
                ftpImage.imgWidth = morphoImage.getMorphoImageHeader().getNbColumn();

                Bitmap bitmp=getBitmapFromRawImage(morphoImage.getImage(),imageRowNumber);

                createExternalImage(bitmp);

                // byte[] bytearray= getByteArray(bitmp);
                byte[] bytearray =  getByteArray(bitmp);

                Logger.d("MorphoPlugin:: "+"---ftp- bytearray"+Arrays.toString(bytearray).toString());

             /*   Logger.d("MorphoPlugin:: "+"ftp-actual"+new String(ftpImage.imgData));
                Bitmap ftpbitmp=getBitmapFromRawImage(morphoImage.getImage(),ftpImage.imgWidth,ftpImage.imgHeight);
                byte[] bytearrayftp= getByteArray(ftpbitmp);
                ftpImage.imgData = bytearrayftp;

                Logger.d("MorphoPlugin:: "+"ftp-reversed"+new String(bytearrayftp));*/


                return ftpImage;
            }
        } catch (Exception e) {
            Logger.e("Exception occurred " + e.getLocalizedMessage());
        }
        return null;
    }

解决方法

您不能将压缩的 byteArray 与从初始/源位图提取的原始 byteArray 进行比较。 压缩通常是有损的(如果没有另外指定),因此像素会以不同的方式重新排列、移动、合并等...,因此无法将解压缩的有损图像(png 或 jpg)与原始位图进行比较如果您尝试从有损压缩流开始返回位图,则也不会。

只有无损压缩图像可以再次解码并与原始位图进行比较。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...