潘志宝
2024-11-11 aa1aa68141e3ee33f98cdd785ddc5c244fedc592
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.TargetRecognition;
H 2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.FlowLayout;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.WindowAdapter;
9 import java.awt.event.WindowEvent;
10 import java.util.Vector;
11
12 import javax.swing.DefaultComboBoxModel;
13 import javax.swing.JButton;
14 import javax.swing.JComboBox;
15 import javax.swing.JDialog;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import javax.swing.JScrollPane;
19 import javax.swing.JTextArea;
20 import javax.swing.SwingUtilities;
21 import javax.swing.SwingWorker;
22
23 import com.iailab.netsdk.common.BorderEx;
24 import com.iailab.netsdk.common.DateChooserJButton;
25 import com.iailab.netsdk.common.Res;
26 import com.iailab.netsdk.demo.module.LoginModule;
27 import com.iailab.netsdk.demo.module.TargetRecognitionModule;
28 import com.iailab.netsdk.lib.NetSDKLib.MEDIAFILE_FACERECOGNITION_INFO;
29
30 /**
31  * 查找人脸事件的信息记录
32  */
33 public class FindFaceEventRecordDialog extends JDialog{
34     /**
35      * 
36      */
37     private static final long serialVersionUID = 1L;
38     
39     private Vector<String> chnList = new Vector<String>(); 
40     
41     public FindFaceEventRecordDialog(){
42         setTitle("查找人脸事件的信息记录");
43         setLayout(new BorderLayout());
44         setModal(true);   
45         pack();
46         setSize(750, 430);
47         setResizable(false);
48         setLocationRelativeTo(null); 
49         setDefaultCloseOperation(DISPOSE_ON_CLOSE);   // 释放窗体    
50         
51         FaceEventRecordPanel faceRecordPanel = new FaceEventRecordPanel();
52         add(faceRecordPanel, BorderLayout.CENTER);
53         addWindowListener(new WindowAdapter() {
54             public void windowClosing(WindowEvent e){
55                 dispose();
56             }
57         });
58     }
59     
60     public class FaceEventRecordPanel extends JPanel{
61         /**
62          * 
63          */
64         private static final long serialVersionUID = 1L;
65
66         public FaceEventRecordPanel() {
67             BorderEx.set(this, "", 4);
68             setLayout(new BorderLayout());
69             
70             JPanel panel1 = new JPanel();    
71             JPanel panel2 = new JPanel();    
72             add(panel1, BorderLayout.NORTH);
73             add(panel2, BorderLayout.CENTER);
74             
75             //
76             JLabel chnlabel = new JLabel(Res.string().getChannel());
77             chnComboBox = new JComboBox(); 
78             for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) {
79                 chnList.add(Res.string().getChannel() + " " + String.valueOf(i));
80             }
81             
82             // 登陆成功,将通道添加到控件
83             chnComboBox.setModel(new DefaultComboBoxModel(chnList));
84             chnComboBox.setPreferredSize(new Dimension(80, 20));
85             
86             JLabel startLabel = new JLabel(Res.string().getStartTime());
87             startTimeBtn = new DateChooserJButton("2018-10-30 11:11:11");
88             
89             JLabel endLabel = new JLabel(Res.string().getEndTime());
90             endTimeBtn = new DateChooserJButton();
91             
92             searchBtn = new JButton(Res.string().getSearch());
93             searchBtn.setPreferredSize(new Dimension(70, 20));
94             
95             JButton downloadBth = new JButton("下载查询到的图片");
96             downloadBth.setPreferredSize(new Dimension(140, 20));
97             
98             msgTextArea = new JTextArea();
99             
100             Dimension dimension1 = new Dimension();
101             dimension1.width = 130;
102             dimension1.height = 20;
103             startTimeBtn.setPreferredSize(dimension1);
104             endTimeBtn.setPreferredSize(dimension1);
105             
106             panel1.setLayout(new FlowLayout());
107             panel1.add(chnlabel);
108             panel1.add(chnComboBox);
109             panel1.add(startLabel);
110             panel1.add(startTimeBtn);
111             panel1.add(endLabel);
112             panel1.add(endTimeBtn);
113             panel1.add(searchBtn);
114             panel1.add(downloadBth);
115             
116             panel2.setLayout(new BorderLayout());
117             panel2.add(new JScrollPane(msgTextArea), BorderLayout.CENTER);
118
119             searchBtn.addActionListener(new ActionListener() {            
120                 @Override
121                 public void actionPerformed(ActionEvent arg0) {
122                     SwingUtilities.invokeLater(new Runnable() {                    
123                         @Override
124                         public void run() {
125                             searchBtn.setEnabled(false);
126                         }
127                     });
128                     findEventInfo();
129                 }
130             });
131             
132             downloadBth.addActionListener(new ActionListener() {            
133                 @Override
134                 public void actionPerformed(ActionEvent arg0) {
135                     DownloadPictureDialog dialog = new DownloadPictureDialog();
136                     dialog.setVisible(true);
137                 }
138             });
139         }    
140     }
141     
142     
143     private JComboBox chnComboBox;
144     private DateChooserJButton startTimeBtn;
145     private DateChooserJButton endTimeBtn;
146     private JTextArea msgTextArea;
147     private JButton searchBtn;
148     
149     public void findEventInfo() {
150         new SwingWorker<Boolean, StringBuffer>() {                    
151             @Override
152             protected Boolean doInBackground() {
153                 int count = 0;        // 循环查询了几次    
154                 int index = 0;           // index + 1 为查询到的总个数    
155                 int nFindCount = 10;  // 每次查询的个数
156                 StringBuffer message = null;
157                 msgTextArea.setText("");
158         
159                 // 获取查询句柄
160                 if(!TargetRecognitionModule.findFile(chnComboBox.getSelectedIndex(), startTimeBtn.getText(), endTimeBtn.getText())) {
161                     message = new StringBuffer();
162                     message.append("未查询到相关信息");
163                     publish(message);
164                     return false;
165                 }            
166         
167                 // 查询具体信息, 循环查询, nFindCount为每次查询的个数
168                 while(true) {
169                     MEDIAFILE_FACERECOGNITION_INFO[] msg = TargetRecognitionModule.findNextFile(nFindCount);
170                     if(msg == null) {
171                         message = new StringBuffer();
172                         message.append("查询结束!");
173                         publish(message);
174                         break;
175                     }
176                     
177                     for(int i = 0; i < msg.length; i++) {
178                         index = i + count * nFindCount + 1;        
179     
180                         // 清空
181                         message = new StringBuffer();
182                             
183                         message.append("[" + index + "]通道号 :" + msg[i].nChannelId + "\n");
184                         message.append("[" + index + "]报警发生时间 :" + msg[i].stTime.toStringTime() + "\n");
185                         message.append("[" + index + "]全景图 :" + new String(msg[i].stGlobalScenePic.szFilePath).trim() + "\n");
186                         message.append("[" + index + "]人脸图路径 :" + new String(msg[i].stObjectPic.szFilePath).trim() + "\n");
187                         message.append("[" + index + "]匹配到的候选对象数量 :" + msg[i].nCandidateNum + "\n");        
188                         
189                         for(int j = 0; j < msg[i].nCandidateNum; j++) {  
190                             for(int k = 0; k < msg[i].stuCandidatesPic[j].nFileCount; k++) {
191                                 message.append("[" + index + "]对比图路径 :" + new String(msg[i].stuCandidatesPic[j].stFiles[k].szFilePath).trim() + "\n");
192                             }    
193                         }    
194
195                         message.append("[" + index + "]匹配到的候选对象数量 :" + msg[i].nCandidateExNum + "\n");
196                         
197                         // 对比信息   
198                         for(int j = 0; j < msg[i].nCandidateExNum; j++) {  
199                             message.append("[" + index + "]人员唯一标识符 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szUID).trim() + "\n");
200                             
201                             // 以下参数,设备有些功能没有解析,如果想要知道   对比图的人员信息,可以根据上面获取的 szUID,来查询人员信息。
202                             // findFaceRecognitionDB() 此示例的方法是根据 GroupId来查询的,这里的查询,GroupId不填,根据 szUID 来查询
203                             message.append("[" + index + "]姓名 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szPersonName).trim() + "\n");
204                             message.append("[" + index + "]相似度 :" + msg[i].stuCandidatesEx[j].bySimilarity + "\n");
205                             message.append("[" + index + "]年龄 :" + msg[i].stuCandidatesEx[j].stPersonInfo.byAge + "\n");
206                             message.append("[" + index + "]人脸库名称 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szGroupName).trim() + "\n");
207                             message.append("[" + index + "]人脸库ID :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szGroupID).trim() + "\n");
208                         }
209                         message.append("\n");
210                         publish(message);
211                     }
212         
213                     if (msg.length < nFindCount) {
214                         message = new StringBuffer();
215                         message.append("查询结束!");
216                         publish(message);
217                         break;
218                     } else {
219                         count ++;
220                     }
221                 }
222                 
223                 // 关闭查询接口
224                 TargetRecognitionModule.findCloseFile();
225
226                 return true;
227             }
228             
229             @Override
230             protected void process(java.util.List<StringBuffer> chunks) {
231                 for(StringBuffer data : chunks) {
232                     msgTextArea.append(data.toString());
233                     msgTextArea.updateUI();
234                 }
235                 
236                 super.process(chunks);
237             }
238             
239             @Override
240             protected void done() {    
241                 searchBtn.setEnabled(true);
242             }
243         }.execute();
244     }
245 }