Beispiel #1
0
    def restart_cam(self):

        print("[INFO] Restarting Cam", flush=True)

        # cam = cv2.VideoCapture(normalize_rtsp(self.cam_source))

        # Protected by Mutex
        # self.mutex.acquire()
        self.scenario = PartCounter()
        self.scenario_type = self.model.detection_mode
Beispiel #2
0
    def update_cam(self, cam_type, cam_source, frameRate, cam_id, has_aoi, aoi_info, scenario_type=None, line_info=None, zone_info=None):
        print('[INFO] Updating Cam ...', flush=True)

        # if self.cam_type == cam_type and self.cam_source == cam_source:
        #    return
        if self.cam_source != cam_source or round(self.frameRate) != round(frameRate):
            self.cam_source = cam_source
            self.frameRate = frameRate
            self._update_instance(normalize_rtsp(cam_source), str(frameRate))

        self.has_aoi = has_aoi
        self.aoi_info = aoi_info

        detection_mode = self.model.get_detection_mode()
        if detection_mode == 'PC':
            print('[INFO] Line INFO', line_info, flush=True)
            self.scenario = PartCounter()
            self.scenario_type = self.model.detection_mode
            try:
                line_info = json.loads(line_info)
                self.use_line = line_info['useCountingLine']
                lines = line_info['countingLines']
                if len(lines) > 0:
                    x1 = int(lines[0]['label'][0]['x'])
                    y1 = int(lines[0]['label'][0]['y'])
                    x2 = int(lines[0]['label'][1]['x'])
                    y2 = int(lines[0]['label'][1]['y'])
                    self.scenario.set_line(x1, y1, x2, y2)
                    print('Upading Line:', flush=True)
                    print('    use_line:', self.use_line, flush=True)
                    print('        line:', x1, y1, x2, y2, flush=True)
                else:
                    print('Upading Line:', flush=True)
                    print('    use_line:', self.use_line, flush=True)

            except:
                self.use_line = False
                print('Upading Line[*]:', flush=True)
                print('    use_line   :', False, flush=True)

        elif detection_mode == 'ES':
            print('[INFO] Zone INFO', zone_info, flush=True)
            self.scenario = DangerZone()
            self.scenario_type = self.model.detection_mode
            # FIXME
            self.scenario.set_targets(['Person'])
            try:
                zone_info = json.loads(zone_info)
                self.use_zone = zone_info['useDangerZone']
                zones = zone_info['dangerZones']
                _zones = []
                print('Upading Line:', flush=True)
                print('    use_zone:', self.use_zone, flush=True)
                for zone in zones:
                    x1 = int(zone['label']['x1'])
                    y1 = int(zone['label']['y1'])
                    x2 = int(zone['label']['x2'])
                    y2 = int(zone['label']['y2'])
                    _zones.append([x1, y1, x2, y2])
                    print('     zone:', x1, y1, x2, y2, flush=True)
                self.scenario.set_zones(_zones)

            except:
                self.use_zone = False
                print('Upading Zone[*]:', flush=True)
                print('    use_zone   :', False, flush=True)

        elif detection_mode == 'DD':
            print('[INFO] Line INFO', line_info, flush=True)
            self.scenario = DefeatDetection()
            self.scenario_type = self.model.detection_mode
            # FIXME
            self.scenario.set_ok('Bottle - OK')
            self.scenario.set_ng('Bottle - NG')
            try:
                line_info = json.loads(line_info)
                self.use_line = line_info['useCountingLine']
                lines = line_info['countingLines']
                if len(lines) > 0:
                    x1 = int(lines[0]['label'][0]['x'])
                    y1 = int(lines[0]['label'][0]['y'])
                    x2 = int(lines[0]['label'][1]['x'])
                    y2 = int(lines[0]['label'][1]['y'])
                    self.scenario.set_line(x1, y1, x2, y2)
                    print('Upading Line:', flush=True)
                    print('    use_line:', self.use_line, flush=True)
                    print('        line:', x1, y1, x2, y2, flush=True)
                else:
                    print('Upading Line:', flush=True)
                    print('    use_line:', self.use_line, flush=True)

            except:
                self.use_line = False
                print('Upading Line[*]:', flush=True)
                print('    use_line   :', False, flush=True)
        else:
            self.scenario = None
            self.scenario_type = self.model.detection_mode
    def update_cam(
        self,
        cam_type,
        cam_source,
        frameRate,
        lva_mode,
        cam_id,
        has_aoi,
        aoi_info,
        scenario_type=None,
        line_info=None,
        zone_info=None,
    ):
        logger.info("Updating Cam ...")

        # if self.cam_type == cam_type and self.cam_source == cam_source:
        #    return
        if (self.cam_source != cam_source
                or round(self.frameRate) != round(frameRate)
                or self.lva_mode != lva_mode):
            self.cam_source = cam_source
            self.frameRate = frameRate
            self.lva_mode = lva_mode
            if IS_OPENCV == "true":
                logger.info("post to CVModule")
                data = {
                    "stream_id": self.cam_id,
                    "rtsp": self.cam_source,
                    "fps": self.frameRate,
                    "endpoint": "http://InferenceModule:5000",
                }
                res = requests.post("http://CVCaptureModule:9000/streams",
                                    json=data)
            else:
                self._update_instance(normalize_rtsp(cam_source),
                                      str(frameRate))

        self.has_aoi = has_aoi
        self.aoi_info = aoi_info

        detection_mode = self.model.get_detection_mode()
        if detection_mode == "PC":
            print("[INFO] Line INFO", line_info, flush=True)
            self.scenario = PartCounter()
            self.scenario_type = self.model.detection_mode
            try:
                line_info = json.loads(line_info)
                self.use_line = line_info["useCountingLine"]
                lines = line_info["countingLines"]
                if len(lines) > 0:
                    x1 = int(lines[0]["label"][0]["x"])
                    y1 = int(lines[0]["label"][0]["y"])
                    x2 = int(lines[0]["label"][1]["x"])
                    y2 = int(lines[0]["label"][1]["y"])
                    self.scenario.set_line(x1, y1, x2, y2)
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)
                    print("        line:", x1, y1, x2, y2, flush=True)
                else:
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)

            except:
                self.use_line = False
                print("Upading Line[*]:", flush=True)
                print("    use_line   :", False, flush=True)

        elif detection_mode == "ES":
            print("[INFO] Zone INFO", zone_info, flush=True)
            self.scenario = DangerZone()
            self.scenario_type = self.model.detection_mode
            # FIXME
            self.scenario.set_targets(["Person"])
            try:
                zone_info = json.loads(zone_info)
                self.use_zone = zone_info["useDangerZone"]
                zones = zone_info["dangerZones"]
                _zones = []
                print("Upading Line:", flush=True)
                print("    use_zone:", self.use_zone, flush=True)
                for zone in zones:
                    x1 = int(zone["label"]["x1"])
                    y1 = int(zone["label"]["y1"])
                    x2 = int(zone["label"]["x2"])
                    y2 = int(zone["label"]["y2"])
                    _zones.append([x1, y1, x2, y2])
                    print("     zone:", x1, y1, x2, y2, flush=True)
                self.scenario.set_zones(_zones)

            except:
                self.use_zone = False
                print("Upading Zone[*]:", flush=True)
                print("    use_zone   :", False, flush=True)

        elif detection_mode == "DD":
            print("[INFO] Line INFO", line_info, flush=True)
            self.scenario = DefeatDetection()
            self.scenario_type = self.model.detection_mode
            # FIXME
            self.scenario.set_ok("Bottle - OK")
            self.scenario.set_ng("Bottle - NG")
            try:
                line_info = json.loads(line_info)
                self.use_line = line_info["useCountingLine"]
                lines = line_info["countingLines"]
                if len(lines) > 0:
                    x1 = int(lines[0]["label"][0]["x"])
                    y1 = int(lines[0]["label"][0]["y"])
                    x2 = int(lines[0]["label"][1]["x"])
                    y2 = int(lines[0]["label"][1]["y"])
                    self.scenario.set_line(x1, y1, x2, y2)
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)
                    print("        line:", x1, y1, x2, y2, flush=True)
                else:
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)

            except:
                self.use_line = False
                print("Upading Line[*]:", flush=True)
                print("    use_line   :", False, flush=True)
        else:
            self.scenario = None
            self.scenario_type = self.model.detection_mode
    def update_cam(
        self,
        cam_type,
        cam_source,
        frameRate,
        recording_duration,
        lva_mode,
        cam_id,
        cam_name,
        has_aoi,
        aoi_info,
        scenario_type=None,
        line_info=None,
        zone_info=None,
    ):
        logger.info("Updating Cam ...")

        # if self.cam_type == cam_type and self.cam_source == cam_source:
        #    return
        if (self.cam_source != cam_source
                or round(self.frameRate) != round(frameRate)
                or self.lva_mode != lva_mode
                or self.recording_duration != recording_duration):
            self.cam_source = cam_source
            self.frameRate = frameRate
            self.lva_mode = lva_mode
            self.recording_duration = recording_duration
            if IS_OPENCV == "true":
                logger.info("post to CVModule")
                data = {
                    "stream_id": self.cam_id,
                    "rtsp": self.cam_source,
                    "fps": self.frameRate,
                    "endpoint": "http://inferencemodule:5000",
                }
                res = requests.post("http://cvcapturemodule:9000/streams",
                                    json=data)
            else:
                self._update_instance(normalize_rtsp(cam_source),
                                      str(frameRate), str(recording_duration))

        self.name = cam_name
        self.has_aoi = has_aoi
        self.aoi_info = aoi_info

        detection_mode = self.model.get_detection_mode()
        if detection_mode == "PD":
            self.scenario = PartDetection()
            self.scenario.set_parts(self.model.parts)
            self.scenario_type = self.model.detection_mode

        elif detection_mode == "PC":
            print("[INFO] Line INFO", line_info, flush=True)
            self.scenario = PartCounter()
            self.scenario_type = self.model.detection_mode
            try:
                line_info = json.loads(line_info)
                self.use_line = line_info["useCountingLine"]
                lines = line_info["countingLines"]
                lines_to_set = []
                if len(lines) > 0:
                    for i in range(len(lines)):
                        x1 = int(lines[i]["label"][0]["x"])
                        y1 = int(lines[i]["label"][0]["y"])
                        x2 = int(lines[i]["label"][1]["x"])
                        y2 = int(lines[i]["label"][1]["y"])
                        line_id = str(lines[i]['order'])
                        print("        line:",
                              x1,
                              y1,
                              x2,
                              y2,
                              line_id,
                              flush=True)
                        lines_to_set.append([x1, y1, x2, y2, line_id])
                    self.scenario.set_line(lines_to_set)
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)
                else:
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)

            except:
                self.use_line = False
                print("Upading Line[*]:", flush=True)
                print("    use_line   :", False, flush=True)

        elif detection_mode in ["ES", "ESA", "TCC", "CQA"]:
            class_obj = [DangerZone, ShelfZone, CountingZone, QueueZone]
            print("[INFO] Zone INFO", zone_info, flush=True)
            self.scenario = class_obj[["ES", "ESA", "TCC",
                                       "CQA"].index(detection_mode)]()
            self.scenario_type = self.model.detection_mode
            # FIXME
            self.scenario.set_targets(self.model.parts)
            try:
                zone_info = json.loads(zone_info)
                self.use_zone = zone_info["useDangerZone"]
                zones = zone_info["dangerZones"]
                _zones = []
                print("Upading Line:", flush=True)
                print("    use_zone:", self.use_zone, flush=True)
                # for zone in zones:
                #     x1 = int(zone["label"]["x1"])
                #     y1 = int(zone["label"]["y1"])
                #     x2 = int(zone["label"]["x2"])
                #     y2 = int(zone["label"]["y2"])
                #     zone_id = str(zone['order'])
                #     _zones.append([x1, y1, x2, y2, zone_id])
                #     print("     zone:", x1, y1, x2, y2, flush=True)
                # self.scenario.set_zones(_zones)
                self.scenario.set_zones(zones)

            except:
                self.use_zone = False
                print("Upading Zone[*]:", flush=True)
                print("    use_zone   :", False, flush=True)

        elif detection_mode == "DD":
            print("[INFO] Line INFO", line_info, flush=True)
            self.scenario = DefeatDetection()
            self.scenario_type = self.model.detection_mode
            # FIXME
            self.scenario.set_ok("Bottle - OK")
            self.scenario.set_ng("Bottle - NG")
            try:
                line_info = json.loads(line_info)
                self.use_line = line_info["useCountingLine"]
                lines = line_info["countingLines"]
                if len(lines) > 0:
                    x1 = int(lines[0]["label"][0]["x"])
                    y1 = int(lines[0]["label"][0]["y"])
                    x2 = int(lines[0]["label"][1]["x"])
                    y2 = int(lines[0]["label"][1]["y"])
                    self.scenario.set_line(x1, y1, x2, y2)
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)
                    print("        line:", x1, y1, x2, y2, flush=True)
                else:
                    print("Upading Line:", flush=True)
                    print("    use_line:", self.use_line, flush=True)

            except:
                self.use_line = False
                print("Upading Line[*]:", flush=True)
                print("    use_line   :", False, flush=True)

        else:
            self.scenario = None
            self.scenario_type = self.model.detection_mode