コード例 #1
0
 def run(self):
     self.start()
     analytic = analytic_pb2.AnalyticData()
     if self.analytic_addr:
         analytic.addr = self.analytic_addr
     window_names = ["Analytic Results"]
     classes = {}
     db = None
     curr_frame = 0
     while True:
         if self.buffer.empty():
             time.sleep(1)
         _, frame_obj = self.buffer.get()
         # print(frame_obj)
         if frame_obj[1] < curr_frame:
             time.sleep(0.1)
             continue
         curr_frame = frame_obj[1]
         frame = frame_obj[2]
         if self.analytic_addr:
             resp = self.client.process_frame(frame)
             resp.analytic.MergeFrom(analytic)
             if resp.frame.frame.ByteSize() > 0:
                 img_bytes = np.fromstring(resp.frame.frame.img, dtype=np.uint8)
                 frame = cv2.imdecode(img_bytes, 1)
             frame = annotate_frame(resp, frame, classes, db)
         cv2.imshow(window_names[0], frame)
         if cv2.waitKey(1) & 0xFF == ord('q'):
             break
コード例 #2
0
def camera(ctx, cam_id, analytic_addr, width, height):
    """Stream the live camera feed from "cam_id" to an analytic"""
    if not analytic_addr:
        analytic_addr = ["localhost:50051"]
    db = ctx.obj.db
    client = aceclient.AnalyticMultiClient()
    cap = cv2.VideoCapture(int(cam_id))
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, int(width))
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, int(height))
    classes = {}
    window_names = []
    f_req = analytic_pb2.FrameRequest()
    for a in analytic_addr:
        analytic = analytic_pb2.AnalyticData()
        analytic.addr = a
        f_req.analytics.append(analytic)
    try:
        while cap.isOpened():
            ret, frame = cap.read()
            if not ret:
                print("Stream unavailable. Exiting.")
                break
            resp = analytic_pb2.CompositeResults()
            resp = client.process_frame(frame, f_req, resp)
            print(len(window_names))
            render(resp, window_names, classes, frame, db)
    finally:
        cv2.destroyAllWindows()
        print("Shutting down")
コード例 #3
0
def video(ctx, video_file, analytic_addr):
    """Stream the contents of a video file to an analytic"""
    if not analytic_addr:
        analytic_addr = ["localhost:50051"]
    db = ctx.obj.db
    client = aceclient.AnalyticMultiClient()
    classes = {}
    cap = cv2.VideoCapture(video_file)
    window_names = []
    f_req = analytic_pb2.FrameRequest()
    for a in analytic_addr:
        analytic = analytic_pb2.AnalyticData()
        analytic.addr = a
        f_req.analytics.append(analytic)
    # Load all frames into a queue buffer
    buf = Queue()
    while (cap.isOpened()):
        ret, frame = cap.read()
        if not ret:
            break
        buf.put(frame)
    try:
        while not buf.empty():
            frame = buf.get(block=False)
            resp = analytic_pb2.CompositeResults()
            resp = client.process_frame(frame, f_req, resp)
            render(resp, window_names, classes, frame, db)
    finally:
        cv2.destroyAllWindows()
        print("Shutting down")
コード例 #4
0
ファイル: analytichandler.py プロジェクト: usnistgov/ACE
    def __init__(self, frame_batch_obj=None, stream_addr="", session_id=""):

        if not frame_batch_obj:
            return None

        self.input_frame = analytic_pb2.InputFrame()
        self.analytic = analytic_pb2.AnalyticData()
        self.resp = analytic_pb2.ProcessedFrame()
        self.resp.data.stream_addr = stream_addr
        self.resp.session_id = session_id

        self.frame = frame_batch_obj[0][2]
        self.input_frame.frame_num = frame_batch_obj[0][1]
        self.input_frame.timestamp = frame_batch_obj[0][0]
コード例 #5
0
ファイル: analytichandler.py プロジェクト: usnistgov/ACE
    def __init__(self, frame_batch_obj=None, stream_addr="", session_id=""):
        """Analytic Handler provides the necessary interface for processing batches of frames ranging in size from 1 to N """
        if not frame_batch_obj:
            return
        # For organizing output data
        self.input_frames = []  # analytic_pb2.InputFrame()
        self.analytic = analytic_pb2.AnalyticData()
        self.resp = analytic_pb2.ProcessedFrameBatch()

        self.frames = [obj[2] for obj in frame_batch_obj]
        self.frame_nums = [obj[1] for obj in frame_batch_obj]
        self.timestamps = [obj[0] for obj in frame_batch_obj]

        self.frame_index = 0

        self.initialize_response(stream_addr, session_id)
コード例 #6
0
def config(ctx, stream_source, msg_addr, db_addr, analytic_host, analytic_port,
           tags):
    """
    Command used to configure the specified analytic to connect to an RTSP stream, process the video, and publish 
    the results to the specified database and message brokers (if any).
    """
    tag_map = {}
    for tag_str in tags:
        tag_map.update(parse_tag(tag_str))
    a = analytic_pb2.AnalyticData(
        addr="{!s}:{!s}".format(analytic_host, analytic_port))
    client = aceclient.ConfigClient(host=analytic_host, port=analytic_port)
    client.config(src=stream_source,
                  analytic=a,
                  messenger_addr=msg_addr,
                  db_addr=db_addr,
                  stream_id=str(uuid.uuid4()),
                  tags=tag_map)
コード例 #7
0
 def __init__(self,
              name,
              port=3000,
              debug=False,
              stream_video=False,
              verbose=False,
              num_workers=1,
              messenger_type="NATS"):
     self.app = Flask(name)
     self._add_endpoint("/config", "config", self.config, methods=["PUT"])
     self._add_endpoint("/kill", "kill", self.kill, methods=["POST"])
     self.analytic = analytic_pb2.AnalyticData()
     self.port = port
     self.handler = None
     self.stream_video = stream_video
     self.num_workers = num_workers
     self.verbose = verbose
     self.loop = asyncio.new_event_loop()
     self.messenger_type = messenger_type
     self.return_frame = False