| | |
| | | |
| | | import com.basic.security.activity.MainActivity; |
| | | import com.basic.security.model.ModelAdapter; |
| | | import com.basic.security.model.PersonA; |
| | | import com.basic.security.utils.Constants; |
| | | import com.basic.security.utils.FaceId; |
| | | |
| | | import java.util.List; |
| | | |
| | | public class FeatureManager { |
| | | |
| | | public static void initCppFeatureMap() { |
| | | List<ModelAdapter> list = PersonManager.findPersonList("select * from person where del_flag='0'"); |
| | | for (ModelAdapter result : list) { |
| | |
| | | String all_device = result.getString("all_device"); |
| | | byte[] camera_image_feature = result.getBlob("camera_image_feature"); |
| | | if (camera_image_feature != null && camera_image_feature != null) { |
| | | FaceId.instance.addFeatureToDb(id, camera_image_feature); |
| | | addFeature(id, camera_image_feature); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | initAllPersonFeaturesMap(); |
| | | MainActivity.faceDbInitComplete = true; |
| | | } |
| | | |
| | | public static void initAllPersonFeaturesMap() { |
| | | List<ModelAdapter> personList = PersonManager.findPersonList("select * from person where 1==1"); |
| | | for (ModelAdapter person : personList) { |
| | | try { |
| | | String id = person.getId(); |
| | | String all_device = person.getString("all_device"); |
| | | byte[] camera_image_feature = person.getBlob("camera_image_feature"); |
| | | if (camera_image_feature != null) { |
| | | addFeatureToAllFeatures(id, camera_image_feature); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | List<ModelAdapter> personAList = PersonAManager.findPersonAList("select * from " + PersonA.tableName); |
| | | for (ModelAdapter personA : personAList) { |
| | | try { |
| | | String id = personA.getString(PersonA.id); |
| | | byte[] faceFeature = personA.getBlob(PersonA.faceFeature); |
| | | if (faceFeature != null) { |
| | | addFeatureToAllFeatures(id, faceFeature); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void addFeatureToAllFeatures(String personId, byte[] featureData) { |
| | | FaceId.instance.addFeatureToAllDb(personId, featureData); |
| | | } |
| | | |
| | | public static String compareFeatureInAllDb(byte[] featureArray, int score) { |
| | | String compareResultStr = FaceId.instance.compareFeatureInAllDb(featureArray, score); |
| | | return compareResultStr; |
| | | } |
| | | |
| | | public static void addFeature(String personId, byte[] featureData) { |
| | | addFeatureToAllFeatures(personId, featureData); |
| | | FaceId.instance.addFeatureToDb(personId, featureData); |
| | | } |
| | | |
| | | public static void removeFeature(String personId) { |
| | | FaceId.instance.removeFeatureFromDb(personId); |
| | | } |
| | | |
| | | public static String compareFeature(byte[] featureArray, int score) { |
| | | String compareResultStr = FaceId.instance.compareFeatureInDb(featureArray, score); |
| | | return compareResultStr; |
| | | } |
| | | |
| | | public static String isDuplicateInAllDb(ModelAdapter selectedPerson) { |
| | | try { |
| | | byte[] camera_image_feature = selectedPerson.getBlob("camera_image_feature"); |
| | | return isDuplicateInAllDb(camera_image_feature); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static String isDuplicateInAllDb(byte[] camera_image_feature) { |
| | | try { |
| | | if (camera_image_feature != null && camera_image_feature.length > 0) { |
| | | String compareResultStr = FeatureManager.compareFeatureInAllDb(camera_image_feature, Constants.minRecognizeScore); |
| | | return compareResultStr.split(",", -1)[0]; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |