Beispiel #1
0
 def __init__(self, conf, plugin, idm=False):
     self._conf = conf
     self._plugin = plugin
     self.rules = []  # list of RuleMatch objects
     Detector.__init__(self, conf, plugin)
     self.__myDataBaseCursor = None
     self.__objDBConn = None
     self.__tries = 0
     self.stop_processing = False
     self._databasetype = self._plugin.get("config", "source_type")
     self._canrun = True
     self.__idm = idm
     if self._databasetype == "db2" and db2notloaded:
         logger.info(
             "You need python ibm_db module installed. This is not an error if you aren't using an IBM plugin"
         )
         self._canrun = False
     elif self._databasetype == "mysql" and mysqlnotloaded:
         logger.info("You need python mysqldb module installed")
         self._canrun = False
         self.stop()
     elif self._databasetype == "oracle" and oraclenotloaded:
         logger.info(
             "You need python cx_Oracle module installed. This is not an error if you aren't using an Oracle plugin"
         )
         self._canrun = False
     elif self._databasetype == "mssql" and mssqlnotloaded:
         logger.info("You need python pymssql module installed")
         self._canrun = False
    def __init__(self, image_shape=(720, 1280), step_sizes=[-40, -20, 0, 20, 40], max_guided_eps=1000):
        self.current_episode = 0
        self.max_guided_eps  = max_guided_eps

        self.im_width  = image_shape[1]
        self.im_height = image_shape[0]

        self.step_sizes = step_sizes

        self.fig        = None
        self.max_dist   = np.linalg.norm([self.im_width, self.im_height])
        self.SCALE_IOU  = 8.0
        self.SCALE_DIST = 1.0
        self.min_reward = 0.08

        self.current_frame    = None
        self.current_output   = None

        self._detector      = Detector()
        self._connector     = MultiRotorConnector()
        self._car_connector = CarConnector()

        self.old_x = None
        self.old_y = None

        self.TEST  = False
Beispiel #3
0
 def __init__(self, conf, plugin, conn):
     self._conf = conf  # config.cfg info
     self._plugin = plugin  # plugins/X.cfg info
     self.rules = []  # list of RuleMatch objects
     self.conn = conn
     self.stop_processing = False
     Detector.__init__(self, conf, plugin, conn)
    def start(self):
        self.client_socket, addr = self.server_socket.accept()
        print("[INFO] connection received from: %s\n" % (addr[0])),

        data = self.receive_data()
        frame = self.vf.convert_to_frame(data)
        self.detector = Detector(frame,
                                 EYE_AR_THRESH=0.24,
                                 ROLL_THRESH=15,
                                 TIME_THRESH=3)

        while self.client_socket:
            try:
                data = self.receive_data()
                frame = self.vf.convert_to_frame(data)

                if sys.getsizeof(data) < 40:
                    print("[INFO] Client stopped sending messages")
                    break

                self.ALARM_ON = self.detector.detect_drowsiness(frame)
                self.send_alarm_status()

                if self.vf.show_frame(frame): break

            except Exception as e:
                print("[EXCEPTION] ", e)
                break

        self.stop()
    def find_target(self, frame, following, color=None, type_obj="object"):
        self.update(frame)
        if color is None:  # se non gli passo nessun colore da cercare, li cerco tutti
            for detector in self.detectors:
                mask, rect = detector.find_obj(self.frame)
                if rect is not None:
                    detector.find_type(self.frame, following)
                if detector.bounding_box and detector.obj.type == type_obj:  # se ho rilevato qualcosa
                    self.target = detector
                    break
        else:  # altrimenti cerco solo quel colore
            detector = Detector(Object(color))
            try:
                mask, rect = detector.find_obj(self.frame)
            except TypeError:
                mask = None
                rect = None
            detector.obj.type = "area"
            if rect is not None and type_obj == "object":
                detector.find_type(self.frame, following)

            if detector.bounding_box and detector.obj.type == type_obj:  # se ho rilevato qualcosa
                self.target = detector
                self.mask = mask
        if self.target:
            print "my target is " + self.target.obj.name + " " + self.target.obj.type
Beispiel #6
0
    def __init__(self, conf, plugin, hostname, username, password):
        self.__conf = conf
        self.__plugin = plugin
        self.__rules = []  # list of RuleMatch objects
        self.__hostname = hostname
        self.__username = username
        self.__password = password.strip()
        self.__section = self.__plugin.get("config", "section")
        self.__last_record_time = ""
        if self.__section == "":
            #search into the command to find the section
            rules = self.__plugin.rules()
            cmd_str = rules['cmd']['cmd']
            for sec in ParserWMI.VALID_SECTIONS:
                if cmd_str.find(sec) >= 0:
                    self.__section = sec
                    logger.warning(
                        "section doesn't found in [config].Section deduced: %s "
                        % self.__section)
                    break
            if self.__section == "":
                self.__section = "Security"
                logger.warning(
                    "section doesn't found in [config].It can't be deduced: Setting it to default value: %s"
                    % self.__section)

        self.__pluginID = self.__plugin.get("DEFAULT", "plugin_id")
        self.__stop_processing = False
        self.__sectionExists = False
        Detector.__init__(self, conf, plugin)
    def __init__(self):
        Detector.__init__(self)
        self.state = self.init

        self.object_contour = None
        self.object_gripper_expanse = None
        self.object_center = None
    def __init__(self, conf, plugin, conn,idm=False):
        Detector.__init__(self, conf, plugin, conn)
        self._conf = conf
        self._plugin = plugin
        self.rules = [] # list of RuleMatch objects
        self.conn = conn
        self.__myDataBaseCursor = None
        self.__objDBConn = None        
        self.__tries = 0
        self.stop_processing = False
        self._databasetype = self._plugin.get("config", "source_type")
        self._canrun = True
        self.__idm = True if self._plugin.get("config", "idm") == "true" else False
        self.loginfo(Lazyformat("IDM is {}", "enabled" if self.__idm else "disabled"))

        if self._databasetype == "db2" and db2notloaded:
            self.loginfo("You need python ibm_db module installed")
            self._canrun = False
        elif self._databasetype == "mysql" and mysqlnotloaded:
            self.loginfo("You need python mysqldb module installed")
            self._canrun = False
            self.stop()
        elif self._databasetype == "oracle" and oraclenotloaded:
            self.loginfo("You need python cx_Oracle module installed")
            self._canrun = False
        elif self._databasetype == "mssql" and mssqlnotloaded:
            self.loginfo("You need python pymssql module installed")
            self._canrun = False
Beispiel #9
0
 def __init__(self, conf, plugin, conn):
     self._conf = conf        # config.cfg info
     self._plugin = plugin    # plugins/X.cfg info
     self.rules = []          # list of RuleMatch objects
     self.conn = conn
     self.stop_processing = False
     Detector.__init__(self, conf, plugin, conn)
def main():
    input_file_name, model_name, show_video = check_args()

    print(f"Input Video: {input_file_name}")
    print(f"Model Name: {model_name}")

    detector = Detector()
    detector.initialize(model_name, input_file_name)

    can_read_frames = True
    current_frame = 0

    start_time = time.time()
    while can_read_frames:
        current_frame += 1
        can_read_frames, frame = detector.analyze_frame(current_frame)

        print(f"\rAnalyzing Frame {current_frame}", end='')
        if current_frame % 3 == 0:
            print(" \\", end='')
        elif current_frame % 3 == 1:
            print(" |", end='')
        elif current_frame % 3 == 2:
            print(" /", end='')
        if show_video and frame is not None:
            cv2.imshow("Frame", frame)
            cv2.waitKey(1)

    analyze_time = int(time.time() - start_time)

    print()
    print(f"Total Frames: {current_frame}")
    print(f"Analyze Time: {analyze_time}s")
    print(f"Average Frames Per Second: {current_frame // analyze_time}")
def main():
    if not os.path.isfile(fname):
        print("Please train the data first")
        exit(0)
    videoGetter = Capturer(vSource).start()
    faceDetector = Detector(dname, cname, fname, videoGetter.frame, relayPin).start()
    #videoShower = Show(videoGetter.frame).start()
    
    # Setup GPIO for door lock
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(relayPin, GPIO.OUT)
    GPIO.output(relayPin, 0)
    
    while True:
        # Stop the thread when its other worker stopped
        if videoGetter.stopped or faceDetector.stopped: #videoShower.stopped:
            if not videoGetter.stopped: videoGetter.stop()
            if not faceDetector.stopped: faceDetector.stop()
            #if not videoShower.stopped: videoShower.stop()
            break
        
        frame = videoGetter.frame # Capture a video frame
        faceDetector.frame = frame # Submit the video frame to detector for process
        #videoShower.frame = frame
    
    GPIO.cleanup()
    print("END")
Beispiel #12
0
 def __init__(
     self, device
 ):  # тут бы по хорошему проинициализировать все что у нас написано
     self.CarCon = CarControl.CarControl(
         device)  # кар контролу передаем девайс которым пользуемся
     self.Detector = Detector()
     self.Road = 0
     self.map = Map.MyMap(
         open('graph.txt'))  # нам нужна карта для построения маршрута
     self.Path = []
     self.prev = 0
     self.startDot = 1
     self.finishDot = 18
     self.bluesigns = 0
     self.walls = [10000, 10000, 10000]
     self.lines = [10000, 10000]
     self.frame = np.array([])
     self.RedIsON = 0
     self.brick = 0
     #self.camera = PiCamera()
     self.camera = cv2.VideoCapture(0)
     #self.camera.resolution = (CarSettings.PiCameraResW, CarSettings.PiCameraResH)
     #self.camera.framerate = CarSettings.PiCameraFrameRate
     #self.camera.vflip = True
     #self.camera.hflip = True
     #self.rawCapture = PiRGBArray(self.camera, size=(CarSettings.PiCameraResW, CarSettings.PiCameraResH))
     self.crossroad = False
     self.fullcross = False
     self.CarCon.turn(CarSettings.DefaultAngle)
     self.CarCon.move(0, CarSettings.Stop)
Beispiel #13
0
def gen(camera):
    """Video streaming generator function"""
    while True:
        global referenceFrame
        frame = camera.get_frame()

        data = np.fromstring(frame, dtype=np.uint8)
        image = cv2.imdecode(data, 1)

        if referenceFrame is None:
            _, _, referenceFrame = Detector.generateReferenceImageItem(image)
            referenceFrameDeque = Detector.generateReferenceImageDeque(
                referenceFrame, REFERENCE_FRAME_AVERAGE_FRAME_COUNT)
            referenceFrameLastUpdate = TimeService.getTimestamp()

        if TimeService.getTimestamp(
        ) > referenceFrameLastUpdate + REFERENCE_FRAME_UPDATE_INTERVAL_MS:
            _, _, referenceFrameItem = Detector.generateReferenceImageItem(
                image)
            referenceFrameDeque.append(referenceFrameItem)
            referenceFrame = Detector.generateReferenceImage(
                referenceFrameDeque)
            referenceFrameLastUpdate = TimeService.getTimestamp()

        detectedRegionRectangles, processedImage, deltaImage, thresholdImage = Detector.detect(
            MIN_HEIGHT, MIN_WIDTH, referenceFrame, image)

        if DRAW_DETECTED_REGIONS and len(detectedRegionRectangles):
            for rectangle in detectedRegionRectangles:
                ImageManipulator.drawRectangleMutable(processedImage,
                                                      rectangle)

        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' +
               cv2.imencode(".jpeg", processedImage)[1].tostring() + b'\r\n')
Beispiel #14
0
 def __init__(self, conf, plugin, conn, hostname, username, password):
     self.__conf = conf
     self.__plugin = plugin
     self.__rules = []          # list of RuleMatch objects
     self.__conn = conn
     self.__hostname = hostname
     self.__username = username
     self.__password = password.strip()
     self.__section = self.__plugin.get("config", "section")
     self.__last_record_time = ""
     if self.__section == "":
         #search into the command to find the section
         rules = self.__plugin.rules()
         cmd_str = rules['cmd']['cmd']
         for sec in ParserWMI.VALID_SECTIONS:
             if cmd_str.find(sec)>=0:
                 self.__section = sec
                 logger.warning("section doesn't found in [config].Section deduced: %s " % self.__section)
                 break
         if self.__section == "":
             self.__section = "Security"
             logger.warning("section doesn't found in [config].It can't be deduced: Setting it to default value: %s" % self.__section)
         
     self.__pluginID = self.__plugin.get("DEFAULT", "plugin_id")
     self.__stop_processing = False
     self.__sectionExists = False
     Detector.__init__(self, conf, plugin, conn)
Beispiel #15
0
 def __init__(self, conf, plugin, conn):
     Detector.__init__(self, conf, plugin, conn)
     self.__conf = conf
     self.__plugin_id = plugin.get("DEFAULT", "plugin_id")
     self.__shutdown_event = threading.Event()
     self.__location = self._plugin.get("config", "location")
     self.__plugin_configuration = plugin
Beispiel #16
0
    def __get_video__(self):
        file_dir = filedialog.askopenfilename()
        filetype = os.path.splitext(file_dir)[1]

        if len(file_dir) > 0:
            if filetype in ['.mov']:
                model = load_model("ModelandPickle/AlexnetRP.model")
                # Open the computer web cam.
                cap = cv2.VideoCapture(file_dir)

                while True:
                    # Capture the frame from the web camera.
                    ret, frame = cap.read()

                    facedector = Detector()
                    face = facedector.detect_face(frame)
                    for (x, y, w, h) in face:

                        color = (0, 0, 255)
                        stroke = 2
                        cv2.rectangle(frame, (x, y), (x + w, y + h), color, stroke)
                        # Capture the  face from the frame and then test it
                        Capture_face = frame[y: y + h, x + 10: x + w - 10]
                        Capture_face = cv2.resize(Capture_face, (Image_size, Image_size))
                        Capture_face = Capture_face.astype("float")
                        Capture_face = img_to_array(Capture_face)
                        face = np.expand_dims(Capture_face, axis=0)
                        preds = model.predict(face)[0]
                        j = np.argmax(preds)
                        result = int(j)
                        label = image_label[result]
                        if (label == 'real'):
                            label = "{}".format(label)
                            cv2.putText(frame, label, (x, y - 10),
                                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
                            cv2.rectangle(frame, (x, y), (x + w, y + h),
                                          (0, 255, 0), 2)
                        elif (label == 'fake'):
                            label = "{}".format(label)
                            cv2.putText(frame, label, (x, y - 10),
                                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
                            cv2.rectangle(frame, (x, y), (x + w, y + h),
                                          (0, 0, 255), 2)

                    frame = cv2.putText(frame, 'Press Q to exit', (0, 10), cv2.FONT_HERSHEY_COMPLEX, 1.2,
                                        (255, 255, 255), 1)
                    # Display the real time frame.
                    cv2.imshow('Face Detection', frame)

                    # If user type Q from the keyboard the loop could be break.
                    if cv2.waitKey(20) & 0xFF == ord('q'):
                        break

                # Release the resource and destroy all windows.
                cap.release()
                cv2.destroyAllWindows()

            else:
                messagebox.showerror('error',
                                     message='The file type is wrong, please upload .mov file')
Beispiel #17
0
 def __init__(self, conf, plugin, conn):
     Detector.__init__(self, conf, plugin, conn)
     self.__conf = conf
     self.__plugin_id = plugin.get("DEFAULT", "plugin_id")
     self.__shutdown_event = threading.Event()
     self.__location = self._plugin.get("config", "location")
     self.__plugin_configuration = plugin
Beispiel #18
0
class Model(object):
    def __init__(self, detector_window, classifier_window):
        self.detector_window = detector_window
        self.classifier_window = classifier_window
        self.detector = Detector()
        self.detector.load()
        self.classifier = Classifier()
        self.classifier.load()
        self.gesture_sequence = Gesture()

    def __call__(self, hand_landmarks):
        self.gesture_sequence.push(hand_landmarks)
        if len(self.gesture_sequence) > self.classifier_window:
            self.gesture_sequence.drop_first()
        tail_detect_vector = self.gesture_sequence.data(-self.detector_window)
        detector_predict = self.detector.predict(tail_detect_vector)
        if detector_predict:
            tail_classify_vector = self.gesture_sequence.data(
                -self.classifier_window)
            classifier_predict = self.classifier.predict(tail_classify_vector)
            if classifier_predict != 'No gesture':
                return classifier_predict
            else:
                return None
        else:
            return None
Beispiel #19
0
    class SignThread(Thread
                     ):  # поток для детектирования знаков и ситуаций на дороге
        def __init__(self):
            Thread.__init__(self)
            self.Detector = Detector()
            self.bluesigns = 0
            self.RedIsON = False
            self.mark = False
            self.frame = np.array([])
            self.brick = 0

        def run(
            self
        ):  # по задумке 0-прямая дорога, 1-перекресток, 2-знак,3-препятствие
            self.mark = True
            while self.mark:
                if len(self.frame) > 0:
                    self.brick = self.Detector.DetectRedSign(self.frame, False)
                    self.bluesigns = self.Detector.DetectBlueSign(
                        self.frame, False)
                    self.RedIsON = self.Detector.DetectTrLight(
                        self.frame, False)
                    # 3 - движение вперед 4 - направо 5 - налево 6 - прямо или направо 7 - прямо или налево
                    time.sleep(0.01)

        def off(self):
            self.mark = False
Beispiel #20
0
 def __init__(self, conf, plugin, conn,idm=False):
     self._conf = conf
     self._plugin = plugin
     self.rules = []      # list of RuleMatch objects
     self.conn = conn
     Detector.__init__(self, conf, plugin, conn)
     self.__myDataBaseCursor = None
     self.__objDBConn = None        
     self.__tries = 0
     self.stop_processing = False
     self._databasetype = self._plugin.get("config", "source_type")
     self._canrun = True
     self.__idm = idm
     if self._databasetype == "db2" and db2notloaded:
         logger.info("You need python ibm_db module installed. This is not an error if you aren't using an IBM plugin")
         self._canrun = False
     elif self._databasetype == "mysql" and mysqlnotloaded:
         logger.info("You need python mysqldb module installed")
         self._canrun = False
         self.stop()
     elif self._databasetype == "oracle" and oraclenotloaded:
         logger.info("You need python cx_Oracle module installed. This is not an error if you aren't using an Oracle plugin")
         self._canrun = False
     elif self._databasetype == "mssql" and mssqlnotloaded:
         logger.info("You need python pymssql module installed")
         self._canrun = False
    def recoverServiceFail(self, cluster_id, fail_node_name):
        cluster = ClusterManager.getCluster(cluster_id)
        if not cluster:
            logging.error("RecoverManager : cluster not found")
            return
        fail_node = cluster.getNodeByName(fail_node_name)

        port = int(self.config.get("detection", "polling_port"))
        version = int(self.config.get("version", "version"))
        detector = Detector(fail_node, port)
        fail_services = detector.getFailServices()

        status = True
        if "agents" in fail_services:
            status = self.restartDetectionService(fail_node, version)
        else:
            status = self.restartServices(fail_node, fail_services, version)

        if not status:  # restart service fail
            print "start recovery"
            print "fail node is %s" % fail_node.name
            print "start recovery vm"
            self.recoverVM(cluster, fail_node)
            print "end recovery vm"
            return self.recoverNodeByReboot(fail_node)
        else:
            return status  # restart service success
Beispiel #22
0
    def __init__(self, conf, plugin, conn, idm=False):
        Detector.__init__(self, conf, plugin, conn)
        self._conf = conf
        self._plugin = plugin
        self.rules = []  # list of RuleMatch objects
        self.conn = conn
        self.__myDataBaseCursor = None
        self.__objDBConn = None
        self.__tries = 0
        self.stop_processing = False
        self._databasetype = self._plugin.get("config", "source_type")
        self._canrun = True
        self.__idm = True if self._plugin.get("config",
                                              "idm") == "true" else False
        logger.info("IDM is %s for plugin %s" %
                    ("enabled" if self.__idm else "disabled",
                     self._plugin.get("DEFAULT", "plugin_id")))

        if self._databasetype == "db2" and db2notloaded:
            logger.info(
                "You need python ibm_db module installed. This is not an error if you aren't using an IBM plugin"
            )
            self._canrun = False
        elif self._databasetype == "mysql" and mysqlnotloaded:
            logger.info("You need python mysqldb module installed")
            self._canrun = False
            self.stop()
        elif self._databasetype == "oracle" and oraclenotloaded:
            logger.info(
                "You need python cx_Oracle module installed. This is not an error if you aren't using an Oracle plugin"
            )
            self._canrun = False
        elif self._databasetype == "mssql" and mssqlnotloaded:
            logger.info("You need python pymssql module installed")
            self._canrun = False
Beispiel #23
0
    def __init__(self, conf, plugin, conn, idm=False):
        Detector.__init__(self, conf, plugin, conn)
        self._conf = conf
        self._plugin = plugin
        self.rules = []  # list of RuleMatch objects
        self.conn = conn
        self.__myDataBaseCursor = None
        self.__objDBConn = None
        self.__tries = 0
        self.stop_processing = False
        self._databasetype = self._plugin.get("config", "source_type")
        self._canrun = True
        self.__idm = True if self._plugin.get("config",
                                              "idm") == "true" else False
        self.loginfo(
            Lazyformat("IDM is {}", "enabled" if self.__idm else "disabled"))

        if self._databasetype == "db2" and db2notloaded:
            self.loginfo("You need python ibm_db module installed")
            self._canrun = False
        elif self._databasetype == "mysql" and mysqlnotloaded:
            self.loginfo("You need python mysqldb module installed")
            self._canrun = False
            self.stop()
        elif self._databasetype == "oracle" and oraclenotloaded:
            self.loginfo("You need python cx_Oracle module installed")
            self._canrun = False
        elif self._databasetype == "mssql" and mssqlnotloaded:
            self.loginfo("You need python pymssql module installed")
            self._canrun = False
Beispiel #24
0
def test_package_calibration():
    detector = Detector()
    handrail_filter = calibrate_from_package_return_handrail_filter()

    test_img = cv2.imread("Calibration_Images/cal_80cm_45degrees.jpg")
    detection = detector.get_rects_from_bgr(test_img)[0]
    print(handrail_filter.get_distance_from_detection(detection))
Beispiel #25
0
def main():
    r = redis.Redis(host=config.redis.hostname, port=config.redis.port, db=config.redis.db)
    detector = Detector("/models/hent-AI model 268/weights.h5")
    detector.load_weights()

    # Test the connection to Redis.
    r.get("connection-test")

    while True:
        print("ready to receive censored image")
        key, uuid = r.blpop(["mask-requests:bar", "mask-requests:mosaic"], 0)
        print("received censored image")

        censored_img_data = r.get("censored-images:%s" % uuid.decode())

        is_mosaic = key.decode() == "mask-requests:mosaic"

        try:
            prepared_img = detector.detect_and_mask(ImageProcessor.bytes_to_image(censored_img_data), is_mosaic, 3)

            print("processed image, saving to redis")
            r.set("masked-images:%s" % uuid.decode(), ImageProcessor.image_to_bytes(prepared_img))
            r.rpush("decensor-requests:%s" % ("mosaic" if is_mosaic else "bar"), "%s" % uuid.decode())
        except NoCensoredRegionsFoundError as e:
            print(e.description)
            r.set("errors:%s" % uuid.decode(), e.json)
Beispiel #26
0
 def __init__(self):
     Detector.__init__(self)
     self.STATE_COMPONENT_TRAIN = "COMPONENT_TRAIN"
     self.tag = "keras-"
     self.exampleBuilder = KerasExampleBuilder
     self.matrices = None
     self.arrays = None
 def __init__(self, cluster_id, node, detection_list, port,
              polling_interval):
     threading.Thread.__init__(self)
     self.node = node
     self.cluster_id = cluster_id
     self.detection_list = detection_list
     self.clean_detection_list = self.clean_detection()
     self.ipmi_status = node.ipmi_status
     self.polling_interval = polling_interval
     self.loop_exit = False
     self.config = ConfigParser.RawConfigParser()
     self.config.read('hass.conf')
     self.detector = Detector(node, port)
     self.custom_function_map = self.set_function_map()
     self.function_map = [
         self.detector.checkPowerStatus, self.detector.checkOSStatus,
         self.detector.checkNetworkStatus, self.detector.checkServiceStatus
     ]
     self.active_layer = self.set_active_layer()
     self.disable_layer = self.set_disable_layer()
     self.authUrl = "http://" + self.config.get("rpc", "rpc_username") + ":" + self.config.get("rpc",
                                                                                               "rpc_password") + \
                    "@127.0.0.1:" + self.config.get(
         "rpc", "rpc_bind_port")
     self.server = xmlrpclib.ServerProxy(self.authUrl)
Beispiel #28
0
 def __init__(self, conf, plugin, conn):
     self._conf = conf
     self._plugin = plugin
     self.rules = []
     self.conn = conn
     self.sIdFile = '/etc/ossim/agent/sdee_sid.data'
     Detector.__init__(self, conf, plugin, conn)
Beispiel #29
0
 def __init__(self):
     self.known_height = 3.50266  # cm
     self.known_width = 25.5  # cm
     self.focal_length_width = -1
     self.focal_length_height = -1
     self.image_width = 0
     self.image_height = 0
     self.detector = Detector()
Beispiel #30
0
 def __init__(self):
     Detector.__init__(self)
     # Settings
     self.STATE_TOOLCHAIN = "PROCESS"
     self.steps = []
     self.intermediateFilesAtSource = False
     self.compressIntermediateFiles = False
     self.intermediateFileTag = "temp"
Beispiel #31
0
 def __init__(self):
     Detector.__init__(self)
     # Settings
     self.STATE_TOOLCHAIN = "PROCESS"
     self.steps = []
     self.intermediateFilesAtSource = False
     self.compressIntermediateFiles = False
     self.intermediateFileTag = "temp"
Beispiel #32
0
 def __init__(self, conf, plugin, queue=None):
     self._conf = conf  # config.cfg info
     self._plugin = plugin  # plugins/X.cfg info
     self.rules = []  # list of RuleMatch objects
     self.stop_processing = False
     self.queue = queue
     self.idmConnected = False
     Detector.__init__(self, conf, plugin)
Beispiel #33
0
 def __init__(self, detector_window, classifier_window):
     self.detector_window = detector_window
     self.classifier_window = classifier_window
     self.detector = Detector()
     self.detector.load()
     self.classifier = Classifier()
     self.classifier.load()
     self.gesture_sequence = Gesture()
Beispiel #34
0
 def __init__(self, conf, plugin,queue = None):
     self._conf = conf        # config.cfg info
     self._plugin = plugin    # plugins/X.cfg info
     self.rules = []          # list of RuleMatch objects
     self.stop_processing = False
     self.queue = queue
     self.idmConnected = False
     Detector.__init__(self, conf, plugin)
Beispiel #35
0
 def __init__(self):
     Thread.__init__(self)
     self.Detector = Detector()
     self.bluesigns = 0
     self.RedIsON = False
     self.mark = False
     self.frame = np.array([])
     self.brick = 0
    def __init__(self, conf, plugin, conn):

        self._conf = conf  # main agent config file
        self._plugin = plugin  # plugin config file
        self.conn = conn
        self._prefix = ""

        Detector.__init__(self, conf, plugin, self.conn)
    def __init__(self, conf, plugin, conn):

        self._conf = conf       # main agent config file
        self._plugin = plugin   # plugin config file
        self.conn = conn
        self._prefix = ""

        Detector.__init__(self, conf, plugin, self.conn)
Beispiel #38
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--camera", help="using camera feed", action='store_true')
    parser.add_argument("-p", "--path", help="path to images")
    parser.add_argument("-o", "--option", help="options : both, eyes, smile",required=True)
    parser.add_argument("-d", "--display", help="do you want to display",action='store_true')
    args = parser.parse_args()

    if args.camera:
        images = VideoList('Camera')
    elif args.path:
        images = FrameList(args.path)
    else:
        raise Exception('must pass either feed or images') 
    
    source = images.get_source()
    folder = source.split('/')[-1]

    save = '../data/Results'

    if not os.path.exists(save):
        os.makedirs(save)

    detector = Detector(option=args.option, debugging=False, save=False)

    row = 0
    workbook = xlsxwriter.Workbook(save + '/' + folder + '.xlsx')
    worksheet = workbook.add_worksheet()
    worksheet.write(row, 0, "Image Name")
    worksheet.write(row, 1, "Results")

    t = 0
    f = 0
    #ITERATE OVER ALL IMAGES
    while not images.is_finished():
        name, frame = images.get_frame()
        value = detector.perfectPhoto(frame)
        if args.display:
            frame = cv2.resize(frame,(400,400), interpolation=cv2.INTER_AREA)
            cv2.imshow("Feed", frame)
            k = cv2.waitKey(1000)
            if k & 0xFF == ord('q'):
                images.stop()
        row+=1
        worksheet.write(row, 0, name)
        worksheet.write(row,1, value*1)
        if value:
            t+=1
        else:
            f+=1
    
    last_row = row + 1
    worksheet.write(last_row+1,0, "Predicted Yes")
    worksheet.write(last_row+1,1, "=COUNTIF(B2:B{},1)".format(last_row) )
    worksheet.write(last_row+2 ,0, "Predicted No")
    worksheet.write(last_row+2,1, "=COUNTIF(B2:B{},0)".format(last_row) )
    workbook.close()
    print("Predicted Yes: {}, Predicted No: {}".format(t,f))
Beispiel #39
0
 def setWorkDir(self, workDir):
     Detector.setWorkDir(self, workDir)  # for EventDetector
     # setup components
     for detector in [
             self.triggerDetector, self.edgeDetector,
             self.unmergingDetector, self.modifierDetector
     ]:
         if detector != None:
             detector.setWorkDir(workDir)
Beispiel #40
0
 def process(self,root):
     se = StructureExtractor()
     se.drawFeature(root)
     self.extractor = Extractor(root)
     self.extractor.process()
     #self.crossP = self.extractor.string2sparse(self.htmlnode.attrib['crossP'],self.extractor.totalheight+1)
     Config.init()
     detector = Detector()#Config.nbTLstr)
     detector.detect(root)
     self.toolbox.setDetector(detector)
Beispiel #41
0
 def performAnalyse(self, htmlnode):
     se = StructureExtractor()
     se.drawFeature(htmlnode)
     extractor = Extractor(htmlnode)
     extractor.process()
     detector = Detector()
     detector.detect(htmlnode)
     (tp, fp, fn) = self.calcAccTitleLine(htmlnode)
     cerr = self.calcAccColumn(htmlnode)
     return (tp, fp, fn, cerr)
Beispiel #42
0
 def __init__(self):
     Detector.__init__(self)
     self.triggerDetector = EntityDetector()
     self.edgeDetector = EdgeDetector()
     self.unmergingDetector = UnmergingDetector()
     self.doUnmergingSelfTraining = True #False
     self.modifierDetector = ModifierDetector()
     #self.stEvaluator = Evaluators.BioNLP11GeniaTools
     #self.stWriteScores = False
     self.STATE_COMPONENT_TRAIN = "COMPONENT_TRAIN"
     self.tag = "event-"
Beispiel #43
0
 def __init__(self):
     Detector.__init__(self)
     # Settings
     self.STATE_TOOLCHAIN = "PROCESS"
     self.steps = []
     for step in self.getDefaultSteps():
         self.addStep(*step)
     self.intermediateFilesAtSource = False
     self.compressIntermediateFiles = True
     self.intermediateFileTag = "temp"
     self.modelParameterStringName = None
Beispiel #44
0
 def __init__(self, conf, plugin, conn, hostname=None, username=None, password=None):
     self._conf = conf
     self._plugin = plugin
     self.rules = []
     self.conn = conn
     self.__hostname = hostname
     self.__username = username
     self.__password = password
     if hostname:
         self.sIdFile = '/etc/ossim/agent/sdee_sid_%s.data' % hostname
     else:
         self.sIdFile = '/etc/ossim/agent/sdee_sid.data'
     Detector.__init__(self, conf, plugin, conn)
Beispiel #45
0
 def __init__(self, conf, plugin):
     self._conf = conf        # config.cfg info
     self._plugin = plugin    # plugins/X.cfg info
     self.rules = []          # list of RuleMatch objects
     Detector.__init__(self, conf, plugin)
     self.__tailLock = Lock()
     self.stop_processing = False
     self.__locations = []
     self.__watchdog = pyinotify.WatchManager()
     self.__notifier = None#pyinotify.ThreadedNotifier(self.__watchdog, FileEventHandler())
     self.__startNotifier = False
     self.__tails = []
     self.__monitorLocations = []
     self.__bookmark_dir = ""
 def __init__(self, config, plugin_config):
     '''
     config: Agent configuration object
     plugin_config: Plugin configuration
     '''
     Detector.__init__(self, config, plugin_config, None)
     
     self.__keepWorking = False
     self.__pluginConfig = plugin_config
     self.__keep_working_v_lock = threading.RLock()
     self.__logDirectory = ""
     self.__filePrefix = ""
     self.__currentOpenedLogFile_fd = None
     self.__currentOpenedLogFile_name = ""
     self.__currentOpenedLogFile_size = 0
     self.__timestamp = 0
     self.__logfiles = []
     self.__skipOldEvents = True
Beispiel #47
0
 def __init__(self, steps=None):
     Detector.__init__(self)
     # Settings
     self.STATE_TOOLCHAIN = "PROCESS"
     self.group = None
     self.definedSteps = []
     self.definedStepDict = {}
     self.defineSteps()
     self.steps = self.getSteps(steps)
     #self.allSteps = {}
     #self.allStepsList = []
     #self.groups = []
     #self.presets = {}
     #for step in self.getDefaultSteps():
     #    self.addStep(*step)
     self.intermediateFilesAtSource = False
     self.compressIntermediateFiles = True
     self.intermediateFileTag = "temp"
     self.modelParameterStringName = None
 def get(self):
     link_open = urllib2.build_opener( urllib2.HTTPCookieProcessor() )
     urllib2.install_opener( link_open )
     
     login_params = "data={\"username\":\"Spring\", \"password\":\"[email protected]\", \"mechanism\":\"plain\"}"
     login_result = link_open.open( config.base_url + config.login_url, login_params )
     login_data = login_result.read()
     logging.info("Receive data " + login_data)
     print login_data
     login_json = json.loads(login_data)
     login_result.close()
     self.response.headers['Content-Type'] = 'text/plain'
     #save sessionid for this connection
     sessionid = login_json["sessionid"]
     
     fetchor = Detector( 5, sessionid, login_json['deviceid'] )
     fetchor.start()
     fetchor.run()
     fetchor.join()
    login_json = json.loads(login_data)
    login_result.close()

    #save sessionid for this connection
    sessionid = login_json["sessionid"]
    print sessionid

    '''
    # get devices
    device_params = "data={\"sessionid\":\"" + login_json["sessionid"] + "\"}"
    device_result = link_open.open( base_url + device_url, device_params );
    device_data = device_result.read()
    device_result.close()
    device_json = json.loads(device_data)
    '''

    # save deviceids
    boundbox = (100, 100, 150, 150)
    fetchor = Detector( 5, sessionid, content['deviceid'], boundbox )
    fetchor.start()
    fetchor.join()
    #fetchor.run()
    #threadone = myTimer(1,1)
    #threadtow = myTimer(2,3)
    #threadone.start()
    #threadtow.start()

    print 'OK'
finally:
    print 'Finished'
def DetectorThunk(conn,dir='C:/PAPA Control/',datacount=1000):
    """An infinite loop for controlling the detector

    Keyword arguments:
    conn -- a connection stream for communicating with the main process
    dir -- the directory in which to save data
    datacount -- the number of data points to attempts to read at a time

    The function loops through, either sleeping or recording data.  It polls
    its communication stream and expects a two element tuple.  The first
    element is an event code and the second is a tuple with the arguments for
    the event.

    """
    det = Detector() #detector object
    running = False
    paused = False
    runnumber = -1
    stream = None
    count = 0
    while True:
        if (not running) and (not conn.poll()):
            sleep(0.01)
            continue
        if conn.poll():
            cmd,args=conn.recv()
            if cmd==QUIT:
                break
            elif cmd==START:
                if runnumber<=0:
                    logging.error("Error: Invalid Run #")
                    continue
                if not running:
                    stream = open(dir+("%04d"%runnumber)+'.pel','wb')
                    stream.write(det.makeHeader())
                    det.start()
                    running = True
                    count=0
            elif cmd==STOP:
                if running:
                    det.stop()
                    det.clear()
                    running = False
                    stream.close()
                    stream=None
                    continue
            elif cmd==PAUSE:
                logging.info("Pausing Detector")
                det.stop()#Do NOT clear
                running = False
                paused = True
            elif cmd==RESUME:
                if paused:
                    logging.info("Resuming")
                    det.start()
                    running = True
                else:
                    logging.warning("Cannot resume: detector not paused")
            elif cmd==RUNNUMBER:
                runnumber = args[0]
                conn.send("Run # set to %d"%runnumber)
            elif cmd==DIRECTORY:
                dir = args[0]
            elif cmd == N_COUNT:
                conn.send(count/2)#Correction Needed for 64 Bit Mode
            elif cmd==PARAM:
                opt,val=args
                det.setParam(opt,val)
            elif cmd == QUERY:
                conn.send(det.status[args[0]])
                #print det.status[args[0]]

            else:
                logging.warning("Did not recognize command %d"%cmd)
        if running:
            if stream is None: continue
            try:
                #Get the number of data points and the data
                #note that num is the number of 32 bit data
                #points given by the detector, which may or
                #may not be the actual  number of neutrons,
                #depending on  if the  detector is in 32 or
                #64 bit mode
                (num,data)=det.read(datacount)
            except RuntimeError,(err):
                logging.error(err)
                break
            count += num
            #Pull only the actual data from the buffer
            if num < datacount:
                data=data[:num]
            stream.write(data.tostring())
            if num < datacount:
                stream.flush()
                sleep(0.01)
Beispiel #51
0
from pprint import pprint

from Detector import Detector

__author__ = 'Rik Smit ([email protected])'

projectDirectory = '/home/rik-target/owncloud-rixmit/Studie/Droneproject/dataset/cows/'
datasetIds = [
    'DJI_0005_cut_233-244',
    'DJI_0007_cut_22-65',
    'DJI_0081'
]

detector = Detector(projectDirectory, datasetIds)
detector.featureType = 'HSV-HIST'
detector.classifierType = 'SVM-RBF'

runs = 20
for active in [True, False]:
    print("Testing (active=%s)" % active)
    results = None
    for run in range(runs):
        result = detector.activeLearningTest(active, datasetIdx=1) # use dataset DJI_0007_cut_22-65 as it is big enough
        if not results:
            results = result
        else:
            results = [x + y for x, y in zip(results, result)]

    pprint([x / runs for x in results])

Beispiel #52
0
class Analyser:
    def __init__(self):
        Config.init()
        self.detector = Detector()#Config.nbTLstr)

    def analyse(self, xmlfilelist):
        parser = etree.XMLParser(recover=True)
        total_tp = 0
        total_fp = 0
        total_fn = 0
        fnfid = {}
        fpfid = {}
        cerrs = dict.fromkeys(['AUTHOR', 'COUNT_READ', 'COUNT_REPLY', 'TITLE', 'TM_POST', 'TM_REPLY'],0)
        cerrfiles = {}
        num = 0
        for xmlfile in xmlfilelist:
            #print(xmlfile)
            if num % 200 == 0 :
                print(num/len(xmlfilelist))
                print('REV.150')
                print('total_tp:', total_tp)
                print('total_fp:', total_fp)
                print('total_fn:', total_fn)
                print('fnfid:', fnfid)
                print('fpfid:', fpfid)

                print('cerrs:',cerrs)
                print('cerrfiles:', cerrfiles)
            num += 1
            root = etree.parse(xmlfile,parser).getroot()
            htmlnode = root[0]
            se = StructureExtractor()
            se.drawFeature(htmlnode)
            extractor = Extractor(htmlnode)
            extractor.process()
            self.detector.detect(htmlnode)
            (tp, fp, fn) = self.calcAccTitleLine(htmlnode)
            total_tp += tp
            total_fp += fp
            total_fn += fn
            if fn == 0:
                cerr = self.calcAccColumn(htmlnode)
                for k in cerr:
                    cerrs[k] += 1
                if len(cerr)>0:
                    cerrfiles[path.basename(xmlfile)] = (cerr, root.attrib['fid'])
            if fp > 0:
                #print(xmlfile)
                fpfid[root.attrib['fid']] = fpfid.get(root.attrib['fid'],0) + 1
            if fn > 0:
                print(xmlfile)
                fnfid[root.attrib['fid']] = fnfid.get(root.attrib['fid'],0) + 1
        print('REV.150')
        print('total_tp:', total_tp)
        print('total_fp:', total_fp)
        print('total_fn:', total_fn)
        print('fnfid:', fnfid)
        print('fpfid:', fpfid)

        print('cerrs:',cerrs)
        print('cerrfiles:', cerrfiles)

    def analyseOnce(self, xmlfile):
        parser = etree.XMLParser(recover=True)
        root = etree.parse(xmlfile,parser).getroot()
        htmlnode = root[0]
        return self.performAnalyse(htmlnode)

    def performAnalyse(self, htmlnode):
        se = StructureExtractor()
        se.drawFeature(htmlnode)
        extractor = Extractor(htmlnode)
        extractor.process()
        detector = Detector()
        detector.detect(htmlnode)
        (tp, fp, fn) = self.calcAccTitleLine(htmlnode)
        cerr = self.calcAccColumn(htmlnode)
        return (tp, fp, fn, cerr)

    def calcAccTitleLine(self, root):
        ptls = set(root.findall('.//*[@predict="{}"]'.format(LABEL['TITLE_LINE'])))
        ttls = set(root.findall('.//*[@label="{}"]'.format(LABEL['TITLE_LINE'])))
        tp = len(ptls & ttls)
        fp = len(ptls) - tp
        fn = len(ttls) - tp
        return (tp, fp, fn)
    def calcAccColumn(self, root):
        k = 1
        columns = {}
        while True:
            cs = root.findall('.//*[@column="{}"]'.format(k))
            if len(cs) == 0:
                break
            columns[k] = set(cs)
            k += 1
        dls = ['AUTHOR', 'COUNT_READ', 'COUNT_REPLY', 'TITLE', 'TM_POST', 'TM_REPLY']
        err = set()
        for key in dls:
            ts = set(root.findall('.//*[@predict="{}"]//*[@label="{}"]'.format(LABEL['TITLE_LINE'],LABEL[key])))
            cs = set()
            for tmpnode in ts:
                if tmpnode.tag == 'text':
                    cs.add(tmpnode.getparent())
                else:
                    cs.add(tmpnode)
            if len(cs) == 0:
                continue
            for k in columns:
                if len(columns[k] - cs)/len(columns[k]) < 0.03 or len(cs - columns[k])/len(cs) < 0.03:
                    break
            else:
                err.add(key)
        return err
from pprint import pprint

from Detector import Detector

__author__ = 'Rik Smit ([email protected])'

projectDirectory = '/home/rik-target/owncloud-rixmit/Studie/Droneproject/dataset/cows/'
datasetIds = [
    'DJI_0005_cut_233-244',
    'DJI_0007_cut_22-65',
    'DJI_0081'
]

detector = Detector(projectDirectory, datasetIds)
detector.featureType = 'HSV-HIST'
detector.classifierType = 'SVM-RBF'


testtype = 'interset'  # or crossset
parameterOptions = { # lists of different parameter values that should be tested for the feature descriptors
    'channelsSet': [[0, 1, 2], [1], [0, 1]],
    'histSizeSet': [32, 8],
    'orientationsSet': [1, 2, 4, 8],
    'ppcSet': [8, 16, 32],
    'cpbSet': [2, 4, 8]
}
datasetIdx = 0  # used for interset (which set is tested on

classifierParameters = { # single paramters that are used for the classifier
    'C': [1],
    'gamma': [0.1],
Beispiel #54
0
 def setWorkDir(self, workDir):
     Detector.setWorkDir(self, workDir) # for EventDetector
     # setup components
     for detector in [self.triggerDetector, self.edgeDetector, self.unmergingDetector, self.modifierDetector]:
         if detector != None:
             detector.setWorkDir(workDir)
Beispiel #55
0
 def __init__(self):
     Config.init()
     self.detector = Detector()#Config.nbTLstr)
Beispiel #56
0
 def __init__(self, hosts, user=None, password=None, timeout_sec=3, translator=None):
     Detector.__init__(self, hosts, user=user, password=password, timeout_sec=timeout_sec,
                       translator=translator)
     self.__lock = Lock()
Beispiel #57
0
from pprint import pprint

from Detector import Detector

__author__ = 'Rik Smit ([email protected])'

projectDirectory = '/home/rik-target/owncloud-rixmit/Studie/Droneproject/dataset/cows/'
datasetIds = [
    'DJI_0005_cut_233-244',
    'DJI_0007_cut_22-65',
    'DJI_0081'
]

detector = Detector(projectDirectory, datasetIds)
detector.featureType = 'HSV-HIST'
detector.classifierType = 'SVM-RBF'

datasetIdx = 0  # used for interset (which set is tested on

parameterOptions = { # lists of different classifier parameters values that should be tested
    'C': [1, 2, 3, 4, 5, 8, 16, 32, 64, 128, 256],
    'gamma': [0.1, 1, 10, 100, 1000],
    'n_neighbors': [1, 2, 3, 4, 5, 10]
}


# singleset test
detector.gridSearchSingleSet(parameters=parameterOptions, datasetIdx=datasetIdx)

# crossset test
detector.gridSearch(parameters=parameterOptions)
Beispiel #58
0
from pprint import pprint

from Detector import Detector

__author__ = 'Rik Smit ([email protected])'

projectDirectory = '/home/rik-target/owncloud-rixmit/Studie/Droneproject/dataset/cows/'
datasetIds = [
    'DJI_0005_cut_233-244',
    'DJI_0007_cut_22-65',
    'DJI_0081'
]

detector = Detector(projectDirectory, datasetIds)
detector.featureType = 'HSV-HIST'
detector.classifierType = 'SVM-RBF'

trainsetIdxs = [0, 1, 2]
testsetIdx = 1
displayOptions = {
    'enabled': True,  # display anything at all
    'frame': True,  # video frame image
    'detections': False,  # detected objects
    'suppressed_detections': True,
    'sliding_window': False,
    'ground_truth': False
}

detector.test_detect(trainsetIdxs, testsetIdx, harvest=True, autoAnnotate=True, displayOptions=displayOptions)
Beispiel #59
0
 def __init__(self):
     Detector.__init__(self)
     self.deleteCombinedExamples = True