コード例 #1
0
 def run_as_client(self, camList, sock, type):
     eventList = []
     if type == "s":
         self.args["SMOKE"] = 1
         self.args["PERSONS"] = 8
     while True:
         list_of_strings = sock.handle_massage()
         for string in list_of_strings:
             str_list = string.split(" ")
             if str_list[0] == 'Non':
                 tempEvent = Event(self.args, -1, -1)
                 eventList = tempEvent.handle_no_detction(
                     camList, eventList)
             else:
                 currDetection = Detection(self.args)
                 currDetection.encode(str_list)
                 #print(currDetection)
                 try:
                     currDetection.cameraId = camList[int(
                         currDetection.originalCameraId)].id
                 except IndexError:
                     continue
                 if currDetection.eventType == "PERSONS":
                     if camList[currDetection.
                                originalCameraId].personEventsList.full():
                         camList[currDetection.
                                 originalCameraId].personEventsList.get()
                     camList[currDetection.
                             originalCameraId].personEventsList.put(
                                 currDetection)
                 currChecker = Checker(self.args, currDetection.eventType,
                                       currDetection.cameraId)
                 currChecker.is_time_passed_from_last_event(
                     camList[currDetection.originalCameraId])
                 currChecker.check_boundaries(
                     camList[currDetection.originalCameraId], currDetection)
                 currChecker.is_event_in_camera(
                     currDetection.eventType,
                     camList[currDetection.originalCameraId].eventTypes)
                 checkList = [
                     currChecker.boundaries, currChecker.timeFromLastClosed,
                     currChecker.eventInCamera
                 ]
                 if not all(checkList):
                     #print(f"fail: boundaries: {currChecker.boundaries} timeFromLastClosed: {currChecker.timeFromLastClosed} eventInCamera: {currChecker.eventInCamera}")
                     continue
                 currDetection.x, currDetection.y = currChecker.x, currChecker.y
                 camList[
                     currDetection.
                     originalCameraId].lastDetectionInCamera = time.time()
                 if currDetection.eventType != "PERSONS":
                     currEvent = Event(self.args, currDetection.cameraId,
                                       currDetection.eventType)
                     eventList = currEvent.handle_detection(
                         currEvent, currDetection, camList, eventList)
                 else:
                     currEvent = Event(self.args, currDetection.cameraId,
                                       "NO_CROSS_ZONE")
                     eventList = currEvent.handle_detection(
                         currEvent, currDetection, camList, eventList)
                     if "PPE_HELMET" in camList[
                             currDetection.
                             originalCameraId].eventTypes and currChecker.is_time_passed_from_last_helmet_event(
                                 camList[currDetection.originalCameraId]):
                         currEvent = Event(self.args,
                                           currDetection.cameraId,
                                           "PPE_HELMET")
                         eventList = currEvent.handle_detection(
                             currEvent, currDetection, camList, eventList)
コード例 #2
0
 def run_as_server(self, camList):
     server = OpenSocket(self.args)
     server.server()
     eventList = []
     anomalyFrameCounter = 0
     massageCounter = 0
     lastFrame = -1
     while True:
         str_list = server.currMassage
         lastMassageTime = time.time()
         massageCounter += 1
         if not server.currMassage or time.time() - lastMassageTime > 0.5:
             tempEvent = Event(self.args, -1, -1)
             eventList = tempEvent.handle_no_detction(camList, eventList)
         else:
             if massageCounter % 10:
                 tempEvent = Event(self.args, -1, -1)
                 eventList = tempEvent.handle_no_detction(
                     camList, eventList)
             currDetection = Detection(self.args)
             currDetection.encode(str_list)
             # Handle each frame once:
             if lastFrame == (currDetection.serialId,
                              currDetection.cameraId):
                 continue
             lastFrame = (currDetection.serialId, currDetection.cameraId)
             try:
                 currDetection.cameraId = camList[int(
                     currDetection.originalCameraId)].id
             except IndexError:
                 continue
             # Handle one of 100 anomaly detections:
             # if currDetection.netName == "Anomaly":
             #     anomalyFrameCounter += 1
             #     if anomalyFrameCounter % self.args["anomaly_reduce"]:
             #         continue
             currChecker = Checker(self.args, currDetection.eventType,
                                   currDetection.cameraId)
             currChecker.is_time_passed_from_last_event(
                 camList[currDetection.originalCameraId])
             currChecker.check_boundaries(
                 camList[currDetection.originalCameraId], currDetection)
             currChecker.is_event_in_camera(
                 currDetection.eventType,
                 camList[currDetection.originalCameraId].eventTypes)
             checkList = [
                 currChecker.boundaries, currChecker.timeFromLastClosed,
                 currChecker.eventInCamera
             ]
             if self.args["DEBUG"] and currDetection.eventType != "ANOMALY":
                 print(currDetection)
             self.add_detection_to_list(currDetection, camList)
             if not all(checkList):
                 #if self.args["DEBUG"]:
                 # print(f"fail: boundaries: {currChecker.boundaries} timeFromLastClosed: {currChecker.timeFromLastClosed} eventInCamera: {currChecker.eventInCamera}")
                 continue
             currDetection.x, currDetection.y = currChecker.x, currChecker.y
             camList[currDetection.
                     originalCameraId].lastDetectionInCamera = time.time()
             if currDetection.eventType != "PERSONS":
                 currEvent = Event(self.args, currDetection.cameraId,
                                   currDetection.eventType)
                 eventList = currEvent.handle_detection(
                     currEvent, currDetection, camList, eventList)
             else:
                 currEvent = Event(self.args, currDetection.cameraId,
                                   "NO_CROSS_ZONE")
                 eventList = currEvent.handle_detection(
                     currEvent, currDetection, camList, eventList)
                 if "PPE_HELMET" in camList[
                         currDetection.
                         originalCameraId].eventTypes and currChecker.is_time_passed_from_last_helmet_event(
                             camList[currDetection.originalCameraId]):
                     currEvent = Event(self.args, currDetection.cameraId,
                                       "PPE_HELMET")
                     eventList = currEvent.handle_detection(
                         currEvent, currDetection, camList, eventList)