/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.sun.jna.ptr.FloatByReference
 *  com.sun.jna.ptr.PointerByReference
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 */
package com.hst.framework.util;

import com.hst.common.util.Base64;
import com.hst.hwface.sdk.HWFaceRecMultiSDK;
import com.hst.hwface.utils.HWFaceRecUtils;
import com.hst.hwface.utils.ImageUtils;
import com.sun.jna.ptr.FloatByReference;
import com.sun.jna.ptr.PointerByReference;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HstHwFaceUtil {
    public static Log _logger = LogFactory.getLog(HstHwFaceUtil.class);
    static PointerByReference pHandle = null;

    public static Map<String, String> comparePhoto(String img1Base64, String img2Base64) {
        HashMap<String, String> resMap = new HashMap<String, String>();
        try {
            ByteArrayInputStream ins1 = new ByteArrayInputStream(Base64.stringToByte(img1Base64.replaceAll("\r\n", "").replaceAll("\\s", "\\+")));
            ByteArrayInputStream ins2 = new ByteArrayInputStream(Base64.stringToByte(img2Base64.replaceAll("\r\n", "").replaceAll("\\s", "\\+")));
            BufferedImage image1 = ImageIO.read(ins1);
            BufferedImage image2 = ImageIO.read(ins2);
            if (image1 == null || image2 == null) {
                resMap.put("code", "01");
                resMap.put("mess", "\u4f20\u5165\u7167\u7247\u683c\u5f0f\u9519\u8bef");
                return resMap;
            }
            int width1 = image1.getWidth();
            int height1 = image1.getHeight();
            byte[] pImgGray1 = ImageUtils.convertRGB32ToGray(image1);
            int width2 = image2.getWidth();
            int height2 = image2.getHeight();
            byte[] pImgGray2 = ImageUtils.convertRGB32ToGray(image2);
            HWFaceRecMultiSDK.HWFaceInfo[] pFaceInfos1 = (HWFaceRecMultiSDK.HWFaceInfo[])new HWFaceRecMultiSDK.HWFaceInfo().toArray(2);
            HWFaceRecMultiSDK.HWFaceInfo[] pFaceInfos2 = (HWFaceRecMultiSDK.HWFaceInfo[])new HWFaceRecMultiSDK.HWFaceInfo().toArray(2);
            int faceCount1 = HWFaceRecUtils.locationFace(pHandle, pImgGray1, width1, height1, 2, pFaceInfos1);
            if (faceCount1 < 1) {
                throw new Exception("\u7167\u7247\u672a\u80fd\u5728\u7167\u7247\u4e2d\u5b9a\u4f4d\u5230\u4eba\u8138\uff01");
            }
            if (faceCount1 > 1) {
                throw new Exception("\u8eab\u4efd\u8bc1\u5b9a\u4f4d\u5230" + faceCount1 + "\u4e2a\u4eba\u8138\uff0c\u4e0d\u7b26\u5408\u8981\u6c42\uff0c\u8981\u6c42\u53ea\u80fd\u6709\u4e00\u4e2a\u4eba\u8138\uff01 ");
            }
            int faceCount2 = HWFaceRecUtils.locationFace(pHandle, pImgGray2, width2, height2, 2, pFaceInfos2);
            if (faceCount2 < 1) {
                throw new Exception("\u7167\u7247\u672a\u80fd\u5728\u7167\u7247\u4e2d\u5b9a\u4f4d\u5230\u4eba\u8138\uff01");
            }
            if (faceCount2 > 1) {
                throw new Exception("\u7167\u7247\u5b9a\u4f4d\u5230" + faceCount2 + "\u4e2a\u4eba\u8138\uff0c\u4e0d\u7b26\u5408\u8981\u6c42\uff0c\u8981\u6c42\u53ea\u80fd\u6709\u4e00\u4e2a\u4eba\u8138\uff01 ");
            }
            HWFaceRecMultiSDK.HWFaceInfo.ByReference pFaceInfo1 = new HWFaceRecMultiSDK.HWFaceInfo.ByReference();
            pFaceInfo1.m_FaceRect = pFaceInfos1[0].m_FaceRect;
            pFaceInfo1.m_afKeyPoint = pFaceInfos1[0].m_afKeyPoint;
            pFaceInfo1.m_KeyPos = pFaceInfos1[0].m_KeyPos;
            byte[] feature1 = HWFaceRecUtils.extractFeatureWithoutLocation(pHandle, pImgGray1, width1, height1, pFaceInfo1);
            HWFaceRecMultiSDK.HWFaceInfo.ByReference pFaceInfo2 = new HWFaceRecMultiSDK.HWFaceInfo.ByReference();
            pFaceInfo2.m_FaceRect = pFaceInfos2[0].m_FaceRect;
            pFaceInfo2.m_afKeyPoint = pFaceInfos2[0].m_afKeyPoint;
            pFaceInfo2.m_KeyPos = pFaceInfos2[0].m_KeyPos;
            byte[] feature2 = HWFaceRecUtils.extractFeatureWithoutLocation(pHandle, pImgGray2, width2, height2, pFaceInfo2);
            FloatByReference fScore = new FloatByReference(0.0f);
            int result = HWFaceRecMultiSDK.INSTANCE.HWCompareFeature(pHandle.getValue(), feature1, feature2, fScore);
            if (result == 0) {
                System.out.println("\u5bf9\u6bd4\u7ed3\u679c\uff1a" + fScore.getValue());
                System.out.println(fScore.getValue());
                resMap.put("code", "00");
                resMap.put("mess", String.valueOf(fScore.getValue()));
                return resMap;
            }
            throw new Exception("\u5bf9\u6bd4\u5931\u8d25\uff01");
        }
        catch (Exception e) {
            String cfr_ignored_0 = "\u53d1\u751f\u9519\u8bef\uff1a" + e.getLocalizedMessage();
            resMap.put("code", "01");
            resMap.put("mess", e.getLocalizedMessage());
            return resMap;
        }
    }

    public class init
    extends Thread {
        @Override
        public void run() {
            try {
                System.out.println("-------------\u521d\u59cb\u5316-----------");
                pHandle = HWFaceRecUtils.initHWCore();
                if (pHandle != null) {
                    _logger.info((Object)"\u521d\u59cb\u5316\u6838\u5fc3\u6210\u529f\uff01");
                } else {
                    _logger.info((Object)"\u521d\u59cb\u5316\u6838\u5fc3\u5931\u8d25\uff01");
                }
            }
            catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
}
