/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.sun.jna.ptr.FloatByReference
 *  com.sun.jna.ptr.PointerByReference
 */
package com.hst.hwface.utils;

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 javax.swing.JOptionPane;

public class Recognize {
    public static float compareTwoPhoto(byte[] feature1, BufferedImage image2) {
        PointerByReference pHandle = null;
        try {
            pHandle = HWFaceRecUtils.initHWCore();
            int width2 = image2.getWidth();
            int height2 = image2.getHeight();
            byte[] pImgGray2 = ImageUtils.convertRGB32ToGray(image2);
            HWFaceRecMultiSDK.HWFaceInfo[] pFaceInfos2 = (HWFaceRecMultiSDK.HWFaceInfo[])new HWFaceRecMultiSDK.HWFaceInfo().toArray(1);
            int faceCount2 = HWFaceRecUtils.locationFace(pHandle, pImgGray2, width2, height2, 1, pFaceInfos2);
            if (faceCount2 < 1) {
                JOptionPane.showMessageDialog(null, "\u672a\u80fd\u5728\u4eba\u8138\u6293\u62cd\u7167\u7247\u4e2d\u5b9a\u4f4d\u5230\u4eba\u8138\uff01");
                System.out.println("\u672a\u80fd\u5728\u4eba\u8138\u6293\u62cd\u7167\u7247\u4e2d\u5b9a\u4f4d\u5230\u4eba\u8138\uff01");
                return 0.0f;
            }
            if (faceCount2 > 1) {
                JOptionPane.showMessageDialog(null, "\u4eba\u8138\u6293\u62cd\u7167\u7247\u5b9a\u4f4d\u5230\u591a\u4e2a\u4eba\u8138\uff0c\u4e0d\u7b26\u5408\u8981\u6c42\uff0c\u8981\u6c42\u53ea\u80fd\u6709\u4e00\u4e2a\u4eba\u8138\uff01");
                System.out.println("\u4eba\u8138\u6293\u62cd\u7167\u7247\u5b9a\u4f4d\u5230\u591a\u4e2a\u4eba\u8138\uff0c\u4e0d\u7b26\u5408\u8981\u6c42\uff0c\u8981\u6c42\u53ea\u80fd\u6709\u4e00\u4e2a\u4eba\u8138\uff01");
                return 0.0f;
            }
            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) {
                float f = fScore.getValue();
                return f;
            }
            try {
                throw new Exception("\u5bf9\u6bd4\u5931\u8d25\uff01");
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        finally {
            HWFaceRecUtils.releaseHWCore(pHandle);
        }
        return 0.0f;
    }
}
