# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['norfair']

package_data = \
{'': ['*']}

install_requires = \
['filterpy>=1.4.5,<2.0.0', 'opencv-python>=3.2.0,<5.0.0', 'rich>=6.1.1,<7.0.0']

setup_kwargs = {
    'name': 'norfair',
    'version': '0.1.8',
    'description': 'Lightweight Python library for real-time 2D object tracking.',
    'long_description': '![Norfair by Tryolabs logo](docs/logo.png)\n\n![Build status](https://github.com/tryolabs/norfair/workflows/CI/badge.svg?branch=master)\n\nNorfair is a customizable lightweight Python library for real-time 2D object tracking.\n\nUsing Norfair, you can add tracking capabilities to any detector with just a few lines of code.\n\n## Features\n\n- Any detector expressing its detections as a series of `(x, y)` coordinates can be used with Norfair. This includes detectors performing object detection, pose estimation, and instance segmentation.\n\n- The function used to calculate the distance between tracked objects and detections is defined by the user, making the tracker extremely customizable. This function can make use of any extra information, such as appearance embeddings, which can heavily improve tracking performance.\n\n- Modular. It can easily be inserted into complex video processing pipelines to add tracking to existing projects. At the same time it is possible to build a video inference loop from scratch using just Norfair and a detector.\n\n- Fast. The only thing bounding inference speed will be the detection network feeding detections to Norfair.\n\nNorfair is built, used and maintained by [Tryolabs](https://tryolabs.com).\n\n## Installation\n\nNorfair currently supports Python 3.6+.\n\n```bash\npip install norfair\n```\n\n## How it works\n\nNorfair works by estimating the future position of each point based on its past positions. It then tries to match these estimated positions with newly detected points provided by the detector. For this matching to occur, Norfair can rely on any distance function specified by the user of the library. Therefore, each object tracker can be made as simple or as complex as needed.\n\nThe following is an example of a particularly simple distance function calculating the Euclidean distance between tracked objects and detections. This is possibly the simplest distance function you could use in Norfair, as it uses just one single point per detection/object.\n\n```python\n def euclidean_distance(detection, tracked_object):\n     return np.linalg.norm(detection.points - tracked_object.estimate)\n```\n\nAs an example we use [Detectron2](https://github.com/facebookresearch/detectron2) to get the single point detections to use with this distance function. We just use the centroids of the bounding boxes it produces around cars as our detections, and get the following results.\n\n![Tracking cars with Norfair](docs/traffic.gif)\n\nOn the left you can see the points we get from Detectron2, and on the right how Norfair tracks them assigning a unique identifier through time. Even a straightforward distance function like this one can work when the tracking needed is simple.\n\nNorfair also provides several useful tools for creating a video inference loop. Here is what the full code for creating the previous example looks like, including the code needed to set up Detectron2:\n\n```python\nimport cv2\nimport numpy as np\nfrom detectron2.config import get_cfg\nfrom detectron2.engine import DefaultPredictor\n\nfrom norfair import Detection, Tracker, Video, draw_tracked_objects\n\n# Set up Detectron2 object detector\ncfg = get_cfg()\ncfg.merge_from_file("demos/faster_rcnn_R_50_FPN_3x.yaml")\ncfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5\ncfg.MODEL.WEIGHTS = "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl"\ndetector = DefaultPredictor(cfg)\n\n# Norfair\nvideo = Video(input_path="video.mp4")\ntracker = Tracker(distance_function=euclidean_distance, distance_threshold=20)\n\nfor frame in video:\n    detections = detector(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))\n    detections = [Detection(p) for p in detections[\'instances\'].pred_boxes.get_centers().cpu().numpy()]\n    tracked_objects = tracker.update(detections=detections)\n    draw_tracked_objects(frame, tracked_objects)\n    video.write(frame)\n```\n\nThe video and drawing tools use OpenCV frames, so they are compatible with most Python video code available online. The point tracking is based on [SORT](https://arxiv.org/pdf/1602.00763.pdf) generalized to detections consisting of a dynamically changing amount of points per detection.\n\n## Motivation\n\nTrying out the latest state of the art detectors normally requires running repositories which weren\'t intended to be easy to use. These tend to be repositories associated with a research paper describing a novel new way of doing detection, and they are therefore intended to be run as a one-off evaluation script to get some result metric to publish on a particular research paper. This explains why they tend to not be easy to run as inference scripts, or why extracting the core model to use in another standalone script isn\'t always trivial.\n\nNorfair was born out of the need to quickly add a simple layer of tracking over a wide range of newly released SOTA detectors. It was designed to seamlessly be plugged into a complex, highly coupled code base, with minimum effort. Norfair provides a series of modular but compatible tools, which you can pick and chose to use in your project.\n\n## Documentation\n\nYou can find the documentation for Norfair\'s API [here](docs/README.md).\n\n## Examples\n\nWe provide several examples of how Norfair can be used to add tracking capabilities to several different detectors.\n\n1. [Simple tracking of cars](demos/detectron2) using [Detectron2](https://github.com/facebookresearch/detectron2).\n2. [Faster tracking of cars](demos/yolov4) using [YOLOv4](https://github.com/Tianxiaomo/pytorch-YOLOv4/tree/master). Try it on any youtube video on this [Google Colab notebook](https://colab.research.google.com/github/tryolabs/norfair/blob/master/demos/yolov4/yolov4_demo.ipynb).\n3. Inserting Norfair into an existing project: [Simple tracking of pedestrians](demos/alphapose) using [AlphaPose](https://github.com/MVIG-SJTU/AlphaPose).\n4. [Speed up pose estimation by extrapolating detections](demos/openpose) using [OpenPose](https://github.com/CMU-Perceptual-Computing-Lab/openpose).\n\n![Norfair OpenPose Demo](docs/openpose_skip_3_frames.gif)\n\n## Comparison to other trackers\n\nNorfair\'s contribution to Python\'s object tracker library repertoire is its ability to work with any object detector by being able to work with a variable number of points per detection, and the ability for the user to heavily customize the tracker by creating their own distance function.\n\nIf you are looking for a tracker, here are some other projects worth noting:\n\n- [**OpenCV**](https://opencv.org) includes several tracking solutions like [KCF Tracker](https://docs.opencv.org/3.4/d2/dff/classcv_1_1TrackerKCF.html) and [MedianFlow Tracker](https://docs.opencv.org/3.4/d7/d86/classcv_1_1TrackerMedianFlow.html) which are run by making the user select a part of the frame to track, and then letting the tracker follow that area. They tend not to be run on top of a detector and are not very robust.\n- [**dlib**](http://dlib.net) includes a correlation single object tracker. You have to create your own multiple object tracker on top of it yourself if you want to track multiple objects with it.\n- [**AlphaPose**](https://github.com/MVIG-SJTU/AlphaPose) just released a new version of their human pose tracker. This tracker is tightly integrated into their code base, and to the task of tracking human poses.\n- [**SORT**](https://github.com/abewley/sort) and [**Deep SORT**](https://github.com/nwojke/deep_sort) are similar to this repo in that they use Kalman filters (and a deep embedding for Deep SORT), but they are hardcoded to a fixed distance function and to tracking boxes. Norfair also adds some filtering when matching tracked objects with detections, and changes the Hungarian Algorithm for its own distance minimizer. Both these repos are also released under the GPL license, which might be an issue for some individuals or companies because the source code of derivative works needs to be published.\n\n## Commercial support\n\nTryolabs can provide commercial support, implement new features in Norfair or build video analytics tools for solving your challenging problems. Norfair powers several video analytics applications, such as the [face mask detection](https://tryolabs.com/blog/2020/07/09/face-mask-detection-in-street-camera-video-streams-using-ai-behind-the-curtain/) tool.\n\nIf you are interested, please [contact us](https://tryolabs.com/#contact).\n\n## License\n\nCopyright © 2020, [Tryolabs](https://tryolabs.com). Released under the [BSD 3-Clause](LICENSE).\n',
    'author': 'Tryolabs',
    'author_email': 'hello@tryolabs.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/tryolabs/norfair',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
