Exemplo n.º 1
0
 def __init__(self, flush_pipe_on_read=False):
     self.__detector = None
     self.__face_size = 64
     self.__flush_pipe_on_read = flush_pipe_on_read
     self.__thread = None
     self.__in_pipe = Pipe(self.__in_pipe_process)
     self.__out_pipe = Pipe(self.__out_pipe_process)
Exemplo n.º 2
0
 def __init__(self, graph_prefix=None, flush_pipe_on_read=False):
     self.__dict__.update(self._defaults)  # set up default values
     # self.__dict__.update(kwargs) # and update with user overrides
     YOLOObjectDetectionAPI.class_names, self.__category_dict = self._get_class(
     )
     YOLOObjectDetectionAPI.anchors = self._get_anchors()
     self.__graph_prefix = graph_prefix
     self.__flush_pipe_on_read = flush_pipe_on_read
     self.__thread = None
     self.__in_pipe = Pipe(self.__in_pipe_process)
     self.__out_pipe = Pipe(self.__out_pipe_process)
Exemplo n.º 3
0
    def __init__(self, graph_prefix='', flush_pipe_on_read=False):
        self.__flush_pipe_on_read = flush_pipe_on_read

        self.__model_path = pretrained_path.get() + "/mars-small128.pb"

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        if not graph_prefix:
            self.__graph_prefix = ''
        else:
            self.__graph_prefix = graph_prefix + '/'
Exemplo n.º 4
0
    def __init__(self, graph_prefix='', flush_pipe_on_read=False):
        self.__flush_pipe_on_read = flush_pipe_on_read

        self.__model_path = "/home/developer/PycharmProjects/SecureIt/obj_tracking/sort_deep/resources/networks/mars-small128.pb"

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        if not graph_prefix:
            self.__graph_prefix = ''
        else:
            self.__graph_prefix = graph_prefix + '/'
Exemplo n.º 5
0
    def __init__(self, graph_prefix='', flush_pipe_on_read=False):
        self.__flush_pipe_on_read = flush_pipe_on_read
        self.__feature_dim = (2048)
        self.__image_shape = (224, 224, 3)

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        if not graph_prefix:
            self.__graph_prefix = ''
        else:
            self.__graph_prefix = graph_prefix + '/'
Exemplo n.º 6
0
    def __init__(self, max_age=120, min_hits=3, flush_pipe_on_read=False):
        """
        Sets key parameters for SORT
        """
        self.max_age = max_age
        self.min_hits = min_hits
        self.trackers = []
        self.frame_count = 0

        self.__flush_pipe_on_read = flush_pipe_on_read

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__outpass_pipe = Pipe(self.__out_pipe_process)
Exemplo n.º 7
0
def detect_objects(cap, pipe, detector, default):
    if not default:
        ret_pipe = Pipe()
    else:
        ret_pipe = None

    def start_cam():
        while True:
            ret, image = cap.read()
            if not ret:
                continue
            inference = Inference(image.copy(), return_pipe=ret_pipe)
            detector.get_in_pipe().push_wait()
            detector.get_in_pipe().push(inference)

    Thread(target=start_cam).start()
    while True:
        if not default:
            ret, inference = ret_pipe.pull(True)
            if not ret:
                ret_pipe.pull_wait()
            else:
                ret_pipe.flush()
        else:
            detector.getOutPipe().pull_wait()
            ret, inference = detector.getOutPipe().pull(True)
        if ret:
            i_dets = inference.get_result()
            pipe.push(i_dets.get_annotated())
    def __init__(self, max_age=10000, min_hits=5, flush_pipe_on_read=False):
        self.max_age = max_age
        self.min_hits = min_hits
        self.trackers = []
        self.frame_count = 0
        self.__bg_frame = None
        self.__bg_gray = None

        self.__flush_pipe_on_read = flush_pipe_on_read

        self.__feature_dim = (2048)
        self.__image_shape = (224, 224, 3)

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)
 def __init__(self):
     self.__self_dir_path = dirname(realpath(__file__))
     self.__thread = None
     self.__pause_resume = None
     self.__tf_sess = tf.Session(config=self.__config)
     self.__in_pipe = Pipe()
     self.__threading = threading
Exemplo n.º 10
0
    def __init__(self, index=None):
        if index is None:
            index = 0

        self.__system = PySpin.System.GetInstance()
        self.__cam_list = self.__system.GetCameras()
        self.__cam = self.__cam_list.GetByIndex(index)
        # self.__pixel_format = self.__cam.PixelFormat
        # print(self.__pixel_format.GetCurrentEntry())
        # self.__pixel_format = PySpin.PixelFormat_BGR8
        # print(self.__pixel_format)
        # self.__access_mode = self.__cam.PixelFormat.GetAccessMode
        self.__cam.Init()
        self.__nodemap = self.__cam.GetNodeMap()
        self.configure_custom_image_settings(self.__nodemap)
        # self.__cam.DeInit()
        # self.__cam.Init()
        self.__cam.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
        print(self.__cam.EncoderMode)

        self.__node_acquisition_framerate = PySpin.CFloatPtr(
            self.__nodemap.GetNode('AcquisitionFrameRate'))
        self.__framerate_to_set = self.__node_acquisition_framerate.GetValue()

        print(self.__framerate_to_set)

        self.__cam.BeginAcquisition()

        self.__out_pipe = Pipe(self.__out_pipe_process)
        self.__thread = None
    def __init__(self, model_name=PRETRAINED_ssd_mobilenet_v1_coco_2017_11_17, image_shape=None,
                 graph_prefix=None, flush_pipe_on_read=False):
        self.__category_index, self.__category_dict = self.__fetch_category_indices()
        self.__path_to_frozen_graph = self.__fetch_model_path(model_name)
        self.__flush_pipe_on_read = flush_pipe_on_read
        self.__image_shape = image_shape

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        self.__run_session_on_thread = False

        if not graph_prefix:
            self.__graph_prefix = ''
        else:
            self.__graph_prefix = graph_prefix + '/'
Exemplo n.º 12
0
    def __init__(self,
                 session_runner,
                 model_name=PRETRAINED_mars_small128,
                 graph_prefix=None):
        self.__path_to_frozen_graph = self.__fetch_model_path(model_name)

        if not graph_prefix:
            self.__graph_prefix = ''
        else:
            self.__graph_prefix = graph_prefix + '/'

        self.__session_runner = session_runner
        self.__tf_sess = session_runner.get_session()
        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        self.init_graph()
Exemplo n.º 13
0
    def __init__(self,
                 image_shape=None,
                 graph_prefix=None,
                 flush_pipe_on_read=False):
        self.__category_index, self.__category_dict = self.__fetch_category_indices(
        )
        self.__path_to_frozen_graph = self.__fetch_model_path()
        self.__flush_pipe_on_read = flush_pipe_on_read
        self.__image_shape = image_shape

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        if not graph_prefix:
            self.__graph_prefix = ''
        else:
            self.__graph_prefix = graph_prefix + '/'
Exemplo n.º 14
0
    def get_default(name):
        global fs
        if not fs:
            fs = FlaskMovieAPI()
            Thread(target=fs.get_app().run, args=("0.0.0.0", 9999)).start()

        if not name in fs.__routes_pipe:
            pipe = Pipe()
            fs.create(name, pipe)

        return fs.__routes_pipe[name]
    def __init__(self, max_age=10000, min_hits=5, flush_pipe_on_read=False, use_detection_mask=False, conf_path=None):
        self.max_age = max_age
        self.min_hits = min_hits
        self.trackers = []
        self.frame_count = 0
        self.__bg_frame = None
        self.__bg_gray = None
        self.__conf_path = conf_path
        self.__flush_pipe_on_read = flush_pipe_on_read

        # self.__feature_dim = (128)
        # self.__image_shape = (128, 64, 3)

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)

        self.__use_detection_mask = use_detection_mask
        self.__zones = None
        if self.__conf_path is not None:
            self.__zones = Zone.create_zones_from_conf(self.__conf_path)
Exemplo n.º 16
0
    def __init__(self,
                 input_size,
                 labels,
                 max_box_per_image,
                 anchors,
                 flush_pipe_on_read=False):
        self.__flush_pipe_on_read = flush_pipe_on_read
        self.__model_path = model_path.get()
        self.__model = None
        self.__input_size = input_size
        self.__labels = list(labels)
        self.__nb_class = len(self.__labels)
        self.__nb_box = len(anchors) // 2
        self.__class_wt = np.ones(self.__nb_class, dtype='float32')
        self.__anchors = anchors
        self.__max_box_per_image = max_box_per_image
        self.__session_runner = None
        self.__tf_sess = None

        self.__thread = None
        self.__in_pipe = Pipe(self.__in_pipe_process)
        self.__out_pipe = Pipe(self.__out_pipe_process)
        self.__run_session_on_thread = False
Exemplo n.º 17
0
    def __init__(self, model_name=PRETRAINED_ssd_mobilenet_v1_coco_2017_11_17):
        self.dir_path = dirname(realpath(__file__))

        self.model_path = self.dir_path + '/object_detection/pretrained/'
        self.model_file = model_name + '.tar.gz'
        self.download_base = 'http://download.tensorflow.org/models/object_detection/'
        self.path_to_frozen_graph = self.model_path + model_name + '/frozen_inference_graph.pb'
        path_to_labels = os.path.join(self.dir_path + '/object_detection/data',
                                      'mscoco_label_map.pbtxt')
        self.class_count = 90
        if not path.exists(self.path_to_frozen_graph):
            self.__download()

        self.__load()
        self.label_map = label_map_util.load_labelmap(path_to_labels)
        self.categories = label_map_util.convert_label_map_to_categories(
            self.label_map,
            max_num_classes=self.class_count,
            use_display_name=True)
        self.category_index = label_map_util.create_category_index(
            self.categories)

        self.inPipe = Pipe()
        self.outPipe = Pipe()
Exemplo n.º 18
0
               b'Content-Type: image/jpeg\r\n\r\n' +
               cv2.imencode('.jpg', image)[1].tostring() + b'\r\n')


def gen_age_api():
    while True:
        age_in_pipe.pull_wait()
        ret, image = age_in_pipe.pull()
        if not ret:
            continue
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' +
               cv2.imencode('.jpg', image)[1].tostring() + b'\r\n')


stock_in_pipe = Pipe()
tracking_in_pipe = Pipe()
age_in_pipe = Pipe()
point_set_pipe = Pipe()
zone_pipe = Pipe()
zone_image_update = Pipe()
dict = {
    'point_set_1': [[103, 13], [551, 14], [535, 341], [114, 343]],
    'point_set_2': [[99, 11], [552, 13], [542, 339], [108, 342]]
}


@app.route('/live_stock_feed')
def live_stock_feed():
    return Response(gen_analysis(),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 19
0
        # i-=1
        ret, image = cap.read()
        if not ret:
            try:
                cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
            except:
                pass
            continue
        if not pipe.push(image):
            pipe.push_wait()
        # sleep(0.05)


if __name__ == '__main__':
    # cap0 = cv2.VideoCapture(0)
    # cap1 = cv2.VideoCapture(1)
    cap0 = cv2.VideoCapture("rtsp://*****:*****@192.168.0.3")
    pipe0 = Pipe()
    # pipe1 = Pipe(limit=1)
    fs = FlaskMovieAPI()
    Thread(target=fs.get_app().run, args=("0.0.0.0", )).start()
    default = cv2.imread('/home/developer/Desktop/be-the-navigator.png')
    fs.create('feed_0', pipe0, default)
    # fs.create('shelf_feed', pipe1)

    Thread(target=gen, args=(
        cap0,
        pipe0,
    )).start()
    # Thread(target=gen, args=(cap1, pipe1,)).start()
Exemplo n.º 20
0
    session = tf.Session()

    image = cv2.resize(image, tuple(image_shape[:2][::-1]))
    image = np.expand_dims(image, axis=0)

    # K.set_session(session)

    extractor = ResNet50ExtractorAPI('rn50_api', True)
    ip = extractor.get_in_pipe()
    # op = extractor.get_out_pipe()
    extractor.use_session_runner(session_runner)

    session_runner.start()
    extractor.run()

    ret_pipe = Pipe()

    # for i in range(1000):
    i = 0
    while True:
        ret, image = cap.read()
        if not ret:
            continue
        ip.push(Inference(image, ret_pipe, {}))

        ret, feature_inference = ret_pipe.pull()
        if ret:
            print(feature_inference.get_result().shape)
        else:
            ret_pipe.wait()
Exemplo n.º 21
0
detector.use_threading()
detector.run()

config_path = input_path.get() + "/config.json"
with open(config_path) as config_buffer:
    config = json.load(config_buffer)
retail_yolo_detector = YOLO(
    input_size=config['model']['input_size'],
    labels=config['model']['labels'],
    max_box_per_image=config['model']['max_box_per_image'],
    anchors=config['model']['anchors'])
retail_yolo_detector.use_session_runner(session_runner)
retail_yolo_detector.use_threading()
yolo_ip = retail_yolo_detector.get_in_pipe()
yolo_op = retail_yolo_detector.get_out_pipe()
yolo_input = Pipe()
retail_yolo_detector.run()

Thread(target=mlt.run).start()
tracking_in_pipe = mlt.tracking_in_pipe
stock_in_pipe = mlt.stock_in_pipe
point_set = mlt.point_set_pipe
zone_pipe = mlt.zone_pipe
# age_in_pipe = mlt.age_in_pipe
zone_image_update = mlt.zone_image_update
#Camera Id For Age Detection
# age_api_runner.runner(age_in_pipe, session_runner, cam_id=0)

tracker = OFISTObjectTrackingAPI(flush_pipe_on_read=True,
                                 use_detection_mask=False,
                                 conf_path=input_path.get() +
Exemplo n.º 22
0

tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Socket created')

tcp_socket.bind((HOST, TCP_PORT))
print('Socket bind complete')
tcp_socket.listen(10)
print('Socket now listening')
conn, addr = tcp_socket.accept()

images = []
data = b''
payload_size = struct.calcsize("L")

pipe = Pipe()


def start_tcp_server():
    global data
    global pipe
    while True:
        while len(data) < payload_size:
            data += conn.recv(4096)
        packed_msg_size = data[:payload_size]

        data = data[payload_size:]
        msg_size = struct.unpack("L", packed_msg_size)[0]

        while len(data) < msg_size:
            data += conn.recv(4096)
Exemplo n.º 23
0
from threading import Thread

from tf_session.tf_session_utils import Pipe

pipe = Pipe(limit=None)

def writer():
    i = 0
    while True:
        if pipe.push(i):
            i+=1
        else:
            pipe.push_wait()

def reader():
    j=-1
    while True:
        ret, i = pipe.pull(True)
        if ret:
            print(i)
            j=i
        else:
            pipe.pull_wait()


Thread(target=writer).start()
Thread(target=reader).start()
            if not ret:
                continue
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + cv2.imencode('.jpg', image)[1].tostring() + b'\r\n')

    def gen_age_api(self):
        while True:
            age_in_pipe.wait()
            ret, image = age_in_pipe.pull()
            if not ret:
                continue
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + cv2.imencode('.jpg', image)[1].tostring() + b'\r\n')


image_in_pipe = Pipe()
tracking_in_pipe = Pipe()
age_in_pipe = Pipe()
flag_in_pipe = Pipe()
zone_detection_in_pipe = Pipe()
object_retail=Pipeline()
dict=None
@app.route('/live_stock_feed')
def live_stock_feed():
    return Response(object_retail.gen_analysis(),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

@app.route('/live_tracking_feed')
def live_tracking_feed():
    return Response(object_retail.gen_tracking(),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 25
0
    Thread(target=fs.get_app().run, args=("0.0.0.0", )).start()

    session_runner = {}
    detector = {}

    cap = {}
    pipe = {}
    video_inputs = {
        0: 0,
        1: 1,
        2: 2,
        3: 3,
        4: 4,
        6: 'rtsp://*****:*****@192.168.0.6'
    }

    for i in video_inputs.keys():
        session_runner[i] = SessionRunner(skip=True)
        session_runner[i].start()
        detector[i] = TFObjectDetectionAPI(
            PRETRAINED_faster_rcnn_inception_v2_coco_2018_01_28, None,
            'tf_api_' + str(i), True)
        detector[i].use_session_runner(session_runner[i])
        detector[i].run()

        cap[i] = cv2.VideoCapture(video_inputs[i])
        pipe[i] = Pipe()
        fs.create('feed_' + str(i), pipe[i])
        Thread(target=detect_objects,
               args=(cap[i], pipe[i], detector[i], False)).start()
Exemplo n.º 26
0
from flask import Response

import cv2

manager = multiprocessing.Manager()
return_dict = manager.dict()


@app_flask.route('/')
def index():
    """Video streaming home page."""
    # return render_template('index.html')


in_pipe = Pipe()

images = []

# cap = cv2.VideoCapture(-1)


def genVideoFeed():
    global inference
    """Video streaming generator function."""

    while True:
        sleep(0.1)
        try:
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' +