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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package com.iailab.netsdk.demo.frame.TargetRecognition;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;
 
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
 
import com.iailab.netsdk.common.BorderEx;
import com.iailab.netsdk.common.DateChooserJButton;
import com.iailab.netsdk.common.Res;
import com.iailab.netsdk.demo.module.LoginModule;
import com.iailab.netsdk.demo.module.TargetRecognitionModule;
import com.iailab.netsdk.lib.NetSDKLib.MEDIAFILE_FACERECOGNITION_INFO;
 
/**
 * 查找人脸事件的信息记录
 */
public class FindFaceEventRecordDialog extends JDialog{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private Vector<String> chnList = new Vector<String>(); 
    
    public FindFaceEventRecordDialog(){
        setTitle("查找人脸事件的信息记录");
        setLayout(new BorderLayout());
        setModal(true);   
        pack();
        setSize(750, 430);
        setResizable(false);
        setLocationRelativeTo(null); 
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);   // 释放窗体    
        
        FaceEventRecordPanel faceRecordPanel = new FaceEventRecordPanel();
        add(faceRecordPanel, BorderLayout.CENTER);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e){
                dispose();
            }
        });
    }
    
    public class FaceEventRecordPanel extends JPanel{
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public FaceEventRecordPanel() {
            BorderEx.set(this, "", 4);
            setLayout(new BorderLayout());
            
            JPanel panel1 = new JPanel();    
            JPanel panel2 = new JPanel();    
            add(panel1, BorderLayout.NORTH);
            add(panel2, BorderLayout.CENTER);
            
            //
            JLabel chnlabel = new JLabel(Res.string().getChannel());
            chnComboBox = new JComboBox(); 
            for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) {
                chnList.add(Res.string().getChannel() + " " + String.valueOf(i));
            }
            
            // 登陆成功,将通道添加到控件
            chnComboBox.setModel(new DefaultComboBoxModel(chnList));
            chnComboBox.setPreferredSize(new Dimension(80, 20));
            
            JLabel startLabel = new JLabel(Res.string().getStartTime());
            startTimeBtn = new DateChooserJButton("2018-10-30 11:11:11");
            
            JLabel endLabel = new JLabel(Res.string().getEndTime());
            endTimeBtn = new DateChooserJButton();
            
            searchBtn = new JButton(Res.string().getSearch());
            searchBtn.setPreferredSize(new Dimension(70, 20));
            
            JButton downloadBth = new JButton("下载查询到的图片");
            downloadBth.setPreferredSize(new Dimension(140, 20));
            
            msgTextArea = new JTextArea();
            
            Dimension dimension1 = new Dimension();
            dimension1.width = 130;
            dimension1.height = 20;
            startTimeBtn.setPreferredSize(dimension1);
            endTimeBtn.setPreferredSize(dimension1);
            
            panel1.setLayout(new FlowLayout());
            panel1.add(chnlabel);
            panel1.add(chnComboBox);
            panel1.add(startLabel);
            panel1.add(startTimeBtn);
            panel1.add(endLabel);
            panel1.add(endTimeBtn);
            panel1.add(searchBtn);
            panel1.add(downloadBth);
            
            panel2.setLayout(new BorderLayout());
            panel2.add(new JScrollPane(msgTextArea), BorderLayout.CENTER);
 
            searchBtn.addActionListener(new ActionListener() {            
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    SwingUtilities.invokeLater(new Runnable() {                    
                        @Override
                        public void run() {
                            searchBtn.setEnabled(false);
                        }
                    });
                    findEventInfo();
                }
            });
            
            downloadBth.addActionListener(new ActionListener() {            
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    DownloadPictureDialog dialog = new DownloadPictureDialog();
                    dialog.setVisible(true);
                }
            });
        }    
    }
    
    
    private JComboBox chnComboBox;
    private DateChooserJButton startTimeBtn;
    private DateChooserJButton endTimeBtn;
    private JTextArea msgTextArea;
    private JButton searchBtn;
    
    public void findEventInfo() {
        new SwingWorker<Boolean, StringBuffer>() {                    
            @Override
            protected Boolean doInBackground() {
                int count = 0;        // 循环查询了几次    
                int index = 0;           // index + 1 为查询到的总个数    
                int nFindCount = 10;  // 每次查询的个数
                StringBuffer message = null;
                msgTextArea.setText("");
        
                // 获取查询句柄
                if(!TargetRecognitionModule.findFile(chnComboBox.getSelectedIndex(), startTimeBtn.getText(), endTimeBtn.getText())) {
                    message = new StringBuffer();
                    message.append("未查询到相关信息");
                    publish(message);
                    return false;
                }            
        
                // 查询具体信息, 循环查询, nFindCount为每次查询的个数
                while(true) {
                    MEDIAFILE_FACERECOGNITION_INFO[] msg = TargetRecognitionModule.findNextFile(nFindCount);
                    if(msg == null) {
                        message = new StringBuffer();
                        message.append("查询结束!");
                        publish(message);
                        break;
                    }
                    
                    for(int i = 0; i < msg.length; i++) {
                        index = i + count * nFindCount + 1;        
    
                        // 清空
                        message = new StringBuffer();
                            
                        message.append("[" + index + "]通道号 :" + msg[i].nChannelId + "\n");
                        message.append("[" + index + "]报警发生时间 :" + msg[i].stTime.toStringTime() + "\n");
                        message.append("[" + index + "]全景图 :" + new String(msg[i].stGlobalScenePic.szFilePath).trim() + "\n");
                        message.append("[" + index + "]人脸图路径 :" + new String(msg[i].stObjectPic.szFilePath).trim() + "\n");
                        message.append("[" + index + "]匹配到的候选对象数量 :" + msg[i].nCandidateNum + "\n");        
                        
                        for(int j = 0; j < msg[i].nCandidateNum; j++) {  
                            for(int k = 0; k < msg[i].stuCandidatesPic[j].nFileCount; k++) {
                                message.append("[" + index + "]对比图路径 :" + new String(msg[i].stuCandidatesPic[j].stFiles[k].szFilePath).trim() + "\n");
                            }    
                        }    
 
                        message.append("[" + index + "]匹配到的候选对象数量 :" + msg[i].nCandidateExNum + "\n");
                        
                        // 对比信息   
                        for(int j = 0; j < msg[i].nCandidateExNum; j++) {  
                            message.append("[" + index + "]人员唯一标识符 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szUID).trim() + "\n");
                            
                            // 以下参数,设备有些功能没有解析,如果想要知道   对比图的人员信息,可以根据上面获取的 szUID,来查询人员信息。
                            // findFaceRecognitionDB() 此示例的方法是根据 GroupId来查询的,这里的查询,GroupId不填,根据 szUID 来查询
                            message.append("[" + index + "]姓名 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szPersonName).trim() + "\n");
                            message.append("[" + index + "]相似度 :" + msg[i].stuCandidatesEx[j].bySimilarity + "\n");
                            message.append("[" + index + "]年龄 :" + msg[i].stuCandidatesEx[j].stPersonInfo.byAge + "\n");
                            message.append("[" + index + "]人脸库名称 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szGroupName).trim() + "\n");
                            message.append("[" + index + "]人脸库ID :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szGroupID).trim() + "\n");
                        }
                        message.append("\n");
                        publish(message);
                    }
        
                    if (msg.length < nFindCount) {
                        message = new StringBuffer();
                        message.append("查询结束!");
                        publish(message);
                        break;
                    } else {
                        count ++;
                    }
                }
                
                // 关闭查询接口
                TargetRecognitionModule.findCloseFile();
 
                return true;
            }
            
            @Override
            protected void process(java.util.List<StringBuffer> chunks) {
                for(StringBuffer data : chunks) {
                    msgTextArea.append(data.toString());
                    msgTextArea.updateUI();
                }
                
                super.process(chunks);
            }
            
            @Override
            protected void done() {    
                searchBtn.setEnabled(true);
            }
        }.execute();
    }
}