Ejemplo n.º 1
0
 def __init__(self):
     ObjectTracker.__init__(self)
     self.logger = LogManager.get_instance().get_logger(
         self.__class__.__name__)
     self.framework_id_dict = {}
     self.finished_framework_id_deque = deque(
         [], FrameworkTracker.MAX_NUMBER_OF_FINISHED_FRAMEWORKS)
     self.finished_framework_dict = {}
Ejemplo n.º 2
0
 def remove(self, id):
     framework = ObjectTracker.remove(self, id)
     if framework is not None:
         self.finished_framework_dict[id] = framework
         if len(self.finished_framework_id_deque
                ) == FrameworkTracker.MAX_NUMBER_OF_FINISHED_FRAMEWORKS:
             clear_framework_id = self.finished_framework_id_deque.popleft()
             del self.finished_framework_dict[clear_framework_id]
         self.finished_framework_id_deque.append(id)
     return framework
Ejemplo n.º 3
0
def main(_argv):

    object_tracker = ObjectTracker()
    frame = None

    while True:

        frame = footage_socket.recv_string()
        img = base64.b64decode(frame)
        npimg = np.fromstring(img, dtype=np.uint8)
        source = cv2.imdecode(npimg, 1)

        message = socket.recv()

        object_tracker.run(source)

        send_array(socket, np.array(object_tracker.get_last_tracked()))

        object_tracker.clear_last_tracked()
Ejemplo n.º 4
0
def main():
    # Parse CLI args
    args = ObjectTracker.cli_args()

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    tracker = ObjectTracker(width=args[WIDTH],
                            middle_percent=args[MIDDLE_PERCENT],
                            display=args[DISPLAY],
                            flip_x=args[FLIP_X],
                            flip_y=args[FLIP_Y],
                            mask_x=args[MASK_X],
                            mask_y=args[MASK_Y],
                            usb_camera=args[USB_CAMERA],
                            usb_port=args[USB_PORT],
                            camera_name=args[CAMERA_NAME],
                            http_host=args[HTTP_HOST],
                            http_file=args[HTTP_FILE],
                            http_delay_secs=args[HTTP_DELAY_SECS],
                            http_verbose=args[HTTP_VERBOSE])

    obj_filter = DualObjectFilter(tracker,
                                  bgr_color=args[BGR_COLOR],
                                  hsv_range=args[HSV_RANGE],
                                  minimum_pixels=args[MINIMUM_PIXELS],
                                  grpc_port=args[GRPC_PORT],
                                  leds=args[LEDS],
                                  display_text=True,
                                  draw_contour=args[DRAW_CONTOUR],
                                  draw_box=args[DRAW_BOX],
                                  vertical_lines=args[VERTICAL_LINES],
                                  horizontal_lines=args[HORIZONTAL_LINES])
    try:
        tracker.start(obj_filter)
    except KeyboardInterrupt:
        pass
    finally:
        tracker.stop()

    logger.info("Exiting...")
Ejemplo n.º 5
0
    if _filter.contour is None:
        _filter.reset_data()
        return

    slope, degrees = contour_slope_degrees(_filter.contour)

    # logger.info("Slope: {0}".format(slope))
    # logger.info("Degrees: {0}".format(degrees))

    if abs(degrees) < 80 or (slope is not None and abs(slope) < 20):
        _filter.reset_data()


if __name__ == "__main__":
    # Parse CLI args
    args = ObjectTracker.cli_args()

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    tracker = ObjectTracker(width=args[WIDTH],
                            middle_percent=args[MIDDLE_PERCENT],
                            display=args[DISPLAY],
                            flip_x=args[FLIP_X],
                            flip_y=args[FLIP_Y],
                            mask_x=args[MASK_X],
                            mask_y=args[MASK_Y],
                            usb_camera=args[USB_CAMERA],
                            usb_port=args[USB_PORT],
                            camera_name=args[CAMERA_NAME],
                            http_host=args[HTTP_HOST],
Ejemplo n.º 6
0
import cv2
import matplotlib.pyplot as plot

from object_tracker import ObjectTracker
from camera import Camera
from vector import Vector
from position_plot import PositionPlot


if __name__ == '__main__':
    done = False

    lower = [98, 80, 128]
    upper = [120, 146, 255]

    tracker1 = ObjectTracker('Left', (711, 400), lower, upper, 1)
    tracker2 = ObjectTracker('Right', (711, 400), lower, upper, 0)
    camera1 = Camera(Vector(0, 0, 1), ((80 * numpy.pi) / 180, 0), ((60 * numpy.pi) / 180, (47 * numpy.pi) / 180),
                     tracker1)
    camera2 = Camera(Vector(1, 0, 1), ((100 * numpy.pi) / 180, 0), ((60 * numpy.pi) / 180, (47 * numpy.pi) / 180),
                     tracker2)

    plotter = PositionPlot((camera1, camera2), ((-1, 2), (-1, 2), (1, 2)))
    plotter.start()
    plot.show()

    while not done:
        tracker1.run()
        tracker2.run()
        key = cv2.waitKey(1)
Ejemplo n.º 7
0
 def __init__(self):
     ObjectTracker.__init__(self)
     self.framework_id_dict = {}
     self.finished_framework_id_deque = deque(
         [], FrameworkTracker.MAX_NUMBER_OF_FINISHED_FRAMEWORKS)
     self.finished_framework_dict = {}
Ejemplo n.º 8
0
    '''处理message回调'''
    global COLOR_BLOCK_TOPIC_ID

    # print('topic: {}'.format(msg.topic))
    # print('message: {}'.format(str(msg.payload)))

    if msg.topic == COLOR_BLOCK_TOPIC_ID:
        message = msg.payload.decode('utf-8')
        print('color_block_info: {}'.format(message))
        update_object_tracker(message)


# 建立一个MQTT的客户端
client = mqtt.Client()
# 绑定数据接收回调函数
client.on_message = on_message

HOST_IP = 'localhost'  # Server的IP地址
HOST_PORT = 1883  # mosquitto 默认打开端口
COLOR_BLOCK_TOPIC_ID = 'color_block_info'  # TOPIC的ID

# 连接MQTT服务器
client.connect(HOST_IP, HOST_PORT, 60)
# 订阅主题
client.subscribe(COLOR_BLOCK_TOPIC_ID)

sdk = PyCarSDK(client, is_debug=True)
tracker = ObjectTracker(sdk)

# 阻塞式, 循环往复,一直处理网络数据,断开重连
client.loop_forever()
def main():
    # Parse CLI args
    p = argparse.ArgumentParser()
    cli.usb_camera(p),
    cli.width(p),
    cli.middle_percent(p),
    cli.minimum_pixels(p),
    cli.hsv_range(p),
    cli.leds(p),
    cli.flip_x(p),
    cli.flip_y(p),
    cli.mask_x(p),
    cli.mask_y(p),
    cli.vertical_lines(p),
    cli.horizontal_lines(p),
    cli.camera_name_optional(p),
    cli.display(p),
    cli.draw_contour(p),
    cli.draw_box(p),
    cli.http_host(p),
    cli.http_delay_secs(p),
    cli.http_file(p),
    cli.http_verbose(p),
    p.add_argument("--dualbgr", dest=DUAL_BGR, required=True, help="Dual color BGR value")
    p.add_argument("--singlebgr", dest=SINGLE_BGR, required=True, help="Single color BGR value")
    p.add_argument("--dualport", dest=DUAL_PORT, default=GRPC_PORT_DEFAULT, type=int,
                   help="Dual gRPC port [{0}]".format(GRPC_PORT_DEFAULT))
    p.add_argument("--singleport", dest=SINGLE_PORT, default=GRPC_PORT_DEFAULT + 1, type=int,
                   help="Dual gRPC port [{0}]".format(GRPC_PORT_DEFAULT + 1))
    cli.log_level(p)
    args = vars(p.parse_args())

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    tracker = ObjectTracker(width=args[WIDTH],
                            middle_percent=args[MIDDLE_PERCENT],
                            display=args[DISPLAY],
                            flip_x=args[FLIP_X],
                            flip_y=args[FLIP_Y],
                            mask_x=args[MASK_X],
                            mask_y=args[MASK_Y],
                            usb_camera=args[USB_CAMERA],
                            usb_port=args[USB_PORT],
                            camera_name=args[CAMERA_NAME],
                            http_host=args[HTTP_HOST],
                            http_file=args[HTTP_FILE],
                            http_delay_secs=args[HTTP_DELAY_SECS],
                            http_verbose=args[HTTP_VERBOSE])

    dual_filter = DualObjectFilter(tracker,
                                   bgr_color=args[DUAL_BGR],
                                   hsv_range=args[HSV_RANGE],
                                   minimum_pixels=args[MINIMUM_PIXELS],
                                   grpc_port=args[DUAL_PORT],
                                   leds=False,
                                   display_text=False,
                                   draw_contour=args[DRAW_CONTOUR],
                                   draw_box=args[DRAW_BOX],
                                   vertical_lines=args[VERTICAL_LINES],
                                   horizontal_lines=args[HORIZONTAL_LINES])

    single_filter = SingleObjectFilter(tracker,
                                       bgr_color=args[SINGLE_BGR],
                                       hsv_range=args[HSV_RANGE],
                                       minimum_pixels=args[MINIMUM_PIXELS],
                                       grpc_port=args[SINGLE_PORT],
                                       leds=False,
                                       display_text=True,
                                       draw_contour=args[DRAW_CONTOUR],
                                       draw_box=args[DRAW_BOX],
                                       vertical_lines=False,
                                       horizontal_lines=False)

    try:
        tracker.start(single_filter, dual_filter)
    except KeyboardInterrupt:
        pass
    finally:
        tracker.stop()

    logger.info("Exiting...")