1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
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
package com.netsdk.demo.customize;
 
import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.enumeration.*;
import com.netsdk.lib.structure.*;
import com.netsdk.lib.utils.Initialization;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
 
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Objects;
import java.util.Scanner;
 
import static com.netsdk.lib.NetSDKLib.NET_MAX_DETECT_REGION_NUM;
 
public class VideoAnalyseAnalyseProcDemo extends Initialization {
 
    int channel = 0;
 
    public void setChannel(int channel) {
        this.channel = channel;
    }
 
    NetSDKLib.LLong attachHandle = new NetSDKLib.LLong(0);
 
    /**
     * 订阅智能任务
     */
 
    public NetSDKLib.LLong AttachVideoAnalyseAnalyseProc() {
        // 先退订,设备不会对重复订阅作校验,重复订阅后会有重复的事件返回
        if (attachHandle.longValue() != 0) {
            this.DetachVideoAnalyseAnalyseProc();
        }
 
        NET_IN_ATTACH_VIDEO_ANALYSE_ANALYSE_PROC stIn = new NET_IN_ATTACH_VIDEO_ANALYSE_ANALYSE_PROC();
        stIn.nChannelId = channel;
        NET_OUT_ATTACH_VIDEO_ANALYSE_ANALYSE_PROC stOut = new NET_OUT_ATTACH_VIDEO_ANALYSE_ANALYSE_PROC();
        stIn.cbVideoAnalyseAnalyseProc = new VideoAnalyseAnalyseCB();
 
        stIn.write();
        stOut.write();
 
        System.out.println("stIn.dwSize = " + stIn.dwSize);
        System.out.println("stOut.dwSize = " + stOut.dwSize);
 
        attachHandle = netSdk.CLIENT_AttachVideoAnalyseAnalyseProc(loginHandle, stIn.getPointer(), stOut.getPointer(),
                5000);
        if (attachHandle.longValue() != 0) {
            System.out.printf("Chn[%d] CLIENT_AttachVideoAnalyseAnalyseProc Success\n", channel);
        } else {
            System.out.printf("Chn[%d] CLIENT_AttachVideoAnalyseAnalyseProc Failed!LastError = %s\n", channel,
                    ToolKits.getErrorCode());
        }
 
        return attachHandle;
    }
 
    /**
     * 报警事件(智能)回调
     */
    private static class VideoAnalyseAnalyseCB implements NetSDKLib.fVideoAnalyseAnalyseProc {
        private static VideoAnalyseAnalyseProcDemo.VideoAnalyseAnalyseCB instance;
 
        private VideoAnalyseAnalyseCB() {
        }
 
        public static VideoAnalyseAnalyseProcDemo.VideoAnalyseAnalyseCB getInstance() {
            if (instance == null) {
                synchronized (VideoAnalyseAnalyseProcDemo.VideoAnalyseAnalyseCB.class) {
                    if (instance == null) {
                        instance = new VideoAnalyseAnalyseProcDemo.VideoAnalyseAnalyseCB();
                    }
                }
            }
            return instance;
        }
 
        @Override
        public void invoke(NetSDKLib.LLong lAttachHandle, Pointer pstuVideoAnalyseTrackProc, Pointer dwUser) {
            System.out.println("========================Enter invoke========================");
            NET_VIDEO_ANALYSE_ANALYSE_PROC msg = new NET_VIDEO_ANALYSE_ANALYSE_PROC();
            ToolKits.GetPointerData(pstuVideoAnalyseTrackProc, msg);
            System.out.println("msg.nChannelId = " + msg.nChannelId);
            System.out.println("msg.stuUTC = " + msg.stuUTC.toStringTime());
 
            System.out.println("msg.nObjectListNum = " + msg.nObjectListNum);
            NET_VEHICLE_FUSED_OBJECT[] tmpObjectList = new NET_VEHICLE_FUSED_OBJECT[msg.nObjectListNum];
            for (int i = 0; i < msg.nObjectListNum; i++) {
                tmpObjectList[i] = new NET_VEHICLE_FUSED_OBJECT();
            }
//            msg.pstuObjectList = new Memory(tmpObjectList[0].size() * msg.nObjectListNum);
            ToolKits.GetPointerDataToStructArr(msg.pstuObjectList, tmpObjectList);
            for (int i = 0; i < msg.nObjectListNum; i++) {
                System.out.println("ObjectList[" + i + "].nObjectID = " + tmpObjectList[i].nObjectID);
                System.out.println("ObjectList[" + i + "].emObjectType = " + tmpObjectList[i].emObjectType);
                System.out.println("ObjectList[" + i + "].fSpeed = " + tmpObjectList[i].fSpeed);
                System.out.println("ObjectList[" + i + "].fAcceleration = " + tmpObjectList[i].fAcceleration);
                System.out.println("ObjectList[" + i + "].nLaneID = " + tmpObjectList[i].nLaneID);
                System.out.println("ObjectList[" + i + "].nLocatedAreasNum = " + tmpObjectList[i].nLocatedAreasNum);
                for(int j = 0; j < tmpObjectList[i].nLocatedAreasNum; j ++){
                    System.out.println("ObjectList[" + i + "].stuLocatedAreas["+j+"].nType = " + tmpObjectList[i].stuLocatedAreas[j].nType);
                    System.out.println("ObjectList[" + i + "].stuLocatedAreas["+j+"].szIDStr = " + new String(tmpObjectList[i].stuLocatedAreas[j].szIDStr).trim());
                }
            }
 
            System.out.println("msg.nEventListCount = " + msg.nEventListCount);
            int[] dwEventCode = msg.dwEventCode;
            for (int i = 0; i < msg.nEventListCount; i++) {
                if (dwEventCode[i] != NetSDKLib.EVENT_IVS_COLLISION_CONFLICT) {
                    return;
                }
                ;
                NET_DEV_EVENT_COLLISION_CONFLICT_INFO tmpEvent = new NET_DEV_EVENT_COLLISION_CONFLICT_INFO();
                ToolKits.GetPointerDataToStruct(msg.pstuEventList[i], 0, tmpEvent);
 
                System.out.println("EventList[" + i + "].nChannelID = " + tmpEvent.nChannelID);
                System.out.println("EventList[" + i + "].nAction = " + tmpEvent.nAction);
                System.out.println("EventList[" + i + "].szName = " + new String(tmpEvent.szName).trim());
                System.out.println("EventList[" + i + "].nEventID = " + tmpEvent.nEventID);
                System.out.println("EventList[" + i + "].nType = " + tmpEvent.nType);
                System.out.println("EventList[" + i + "].nLeftTime = " + tmpEvent.nLeftTime);
                System.out.println("EventList[" + i + "].fConflictLevel = " + tmpEvent.fConflictLevel);
                System.out.println("EventList[" + i + "].fConfidence = " + tmpEvent.fConfidence);
                System.out.println("EventList[" + i + "].nObjectsCount = " + tmpEvent.nObjectsCount);
                for (int j = 0; j < tmpEvent.nObjectsCount; j++) {
                    System.out.println("EventList[" + i + "].stuObjects[" + j + "].nObjectID = "+ tmpEvent.stuObjects[j].nObjectID);
                    System.out.println("EventList[" + i + "].stuObjects[" + j + "].emObjectType = "+ tmpEvent.stuObjects[j].emObjectType);
                    System.out.println("EventList[" + i + "].stuObjects[" + j + "].fSpeed = " + tmpEvent.stuObjects[j].fSpeed);
                    System.out.println("EventList[" + i + "].stuObjects[" + j + "].fAcceleration = "+ tmpEvent.stuObjects[j].fAcceleration);
                    System.out.println("EventList[" + i + "].stuObjects[" + j + "].nLaneID = " + tmpEvent.stuObjects[j].nLaneID);
                }
            }
 
        }
    }
 
    /**
     * 停止侦听智能事件
     */
    public void DetachVideoAnalyseAnalyseProc() {
        if (this.attachHandle.longValue() != 0) {
            netSdk.CLIENT_DetachVideoAnalyseAnalyseProc(this.attachHandle);
        }
    }
 
    public void RunTest() {
        System.out.println("Run Test");
        CaseMenu menu = new CaseMenu();
        ;
        menu.addItem((new CaseMenu.Item(this, "AttachVideoAnalyseAnalyseProc", "AttachVideoAnalyseAnalyseProc")));
        menu.addItem((new CaseMenu.Item(this, "DetachVideoAnalyseAnalyseProc", "DetachVideoAnalyseAnalyseProc")));
 
        menu.run();
    }
 
    public static void main(String[] args) {
        VideoAnalyseAnalyseProcDemo RealLoadPicExDemo = new VideoAnalyseAnalyseProcDemo();
        Scanner sc = new Scanner(System.in);
//        System.out.print("ip:");
//        String ip = sc.nextLine();
//        System.out.print("port:");
//        String tmp = sc.nextLine();
//        int port = Integer.parseInt(tmp);
//        System.out.print("username:");
//        String username = sc.nextLine();
//        System.out.print("password:");
//        String pwd = sc.nextLine();
        String ip = "10.33.121.89";
        int port = 32200;
        String username = "admin";
        String pwd = "admin123";
        InitTest(ip, port, username, pwd);
 
//        System.out.print("channel:");
//        String tmp2 = sc.nextLine();
//        int channel = Integer.parseInt(tmp2);
        int channel = 0;
        RealLoadPicExDemo.setChannel(channel);
 
        RealLoadPicExDemo.RunTest();
        LoginOut();
 
    }
}