554325746@qq.com
2019-08-07 2539f53391765abb74b6fe63f46e5a2c701e950f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.basic.security.utils;
 
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
 
import com.basic.security.base.BaseApplication;
import com.basic.security.manager.impl.cblite.BaseManager;
import com.basic.security.manager.impl.cblite.DeviceManager;
import com.basic.security.manager.IdCardManager;
import com.basic.security.manager.impl.cblite.PersonIdentityManager;
import com.basic.security.manager.impl.cblite.PersonManager;
import com.couchbase.lite.Blob;
import com.basic.security.model.ModelAdapter;
 
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
 
// 批量导入人脸到数据库
public class SaveTestData {
 
    public static void savePicToDatabase() {
 
        new Thread(new Runnable() {
            @Override
            public void run() {
 
                File f = new File(Environment.getExternalStorageDirectory() + "/APicData/data/");
 
                if (!f.exists()) {//判断路径是否存在
                    return;
                }
 
                File[] files = f.listFiles();
 
                if (files == null) {//判断权限
                    return;
                }
 
                int i = 0;
                for (File _file : files) {//遍历目录
                    if (_file.isFile()) {
                        String _name = _file.getName();
                        String filePath = _file.getAbsolutePath();//获取文件路径
                        String fileName = _file.getName().substring(0, _name.lastIndexOf("."));//获取文件名
 
                        Log.e("savePicToDatabase", "第" + i + "个" + "name = " + _name + "filePath = " + filePath + "fileName = " + fileName);
                        i += 1;
 
                        Bitmap bitmap = BitmapFactory.decodeFile(filePath);
                        if (bitmap == null) {
                            continue;
                        }
                        Log.e("savePicToDatabase", "file_name = " + fileName + "  height = " + bitmap.getHeight() + "  weight = " + bitmap.getWidth());
 
 
                        BaseApplication.getApplication().detectLock.lock();
                        byte[] featureData = FaceId.instance.extractFeature1(IdCardManager.getPixelsBGR(bitmap), bitmap.getWidth(), bitmap.getHeight());
                        BaseApplication.getApplication().detectLock.unlock();
 
                        ByteArrayOutputStream stream = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                        byte[] jpgData = stream.toByteArray();
 
 
                        try {
                            stream.close();
                        } catch (IOException e) {
                            Log.e("savePicToDatabase", "stream.close  = error = error = error = error = error = error = " + e.getMessage());
                            e.printStackTrace();
                        }
 
                        ModelAdapter person = new ModelAdapter()
                                .setString("name", fileName)
                                .setString("sign_up_status", "已注册")
                                .setString("verify_status", "不需要验证身份证")
                                .setString("sign_up_method", "统一导入")
                                .setString("sign_up_time", System.currentTimeMillis() + "")
                                .setString("device_id", DeviceManager.getDeviceId())
                                .setString("company_id", DeviceManager.getCompareId())
                                .setString("table", "person");
 
                        try {
                            byte[] feature = featureData;//new Blob("image/jpeg", featureData);
                            person.setBlob("camera_image_feature", feature);
                            byte[] jpg = jpgData;// new Blob("image/jpeg", jpgData);
                            person.setBlob("camera_image_path", jpg);
                        } catch (Exception e) {
                            Log.e("savePicToDatabase", "setBlob setBlob setBlob  = error = error = error = error = error = error = " + e.getMessage());
                            e.printStackTrace();
                        }
 
                        try {
                            PersonManager.savePerson(person);
                        } catch (Exception e) {
                            Log.e("savePicToDatabase", "CouchbaseUtil.database.save  = error = error = error = error = error = error = " + e.getMessage());
                            e.printStackTrace();
                        }
 
                        ModelAdapter person_identity = new ModelAdapter()
                                .setString("person_id", person.getId())
//                                .setString("identity_id", normal_person.getId())
                                .setString("table", "person_identity")
                                .setString("device_id", DeviceManager.getDeviceId())
                                .setString("company_id", DeviceManager.getCompareId());
                        PersonIdentityManager.savePersonIdentity(person_identity);
                        FaceId.instance.addFeatureToDb(person.getId(), featureData);
                    }
                }
 
            }
        }).start();
 
    }
}