Skip to content

Commit

Permalink
Remove motmetrics (which adds pandas) and opencv as dependencies
Browse files Browse the repository at this point in the history
Add them as extra dependencies, adjust code to return pretty error
messages when imports fail, and update documentation.
  • Loading branch information
joaqo committed Feb 12, 2021
1 parent 46ceefe commit e7c014d
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 21 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ Norfair is built, used and maintained by [Tryolabs](https://tryolabs.com).

## Installation

Norfair currently supports Python 3.6+.
Norfair currently supports Python 3.7+.

For pure python version that works anywhere install as:
```bash
pip install norfair
```

For more features install as:
```bash
pip install norfair[metrics] # Supports running MOT metrics evaluation
pip install norfair[video] # Adds several video helper features running on OpenCV
pip install norfair[metrics,video] # Everything included
```

## How it works

Norfair 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.
Expand Down
5 changes: 3 additions & 2 deletions demos/alphapose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ An example of how to integrate Norfair into the video inference loop of a pre ex

## Instructions

1. [Follow the instructions](https://github.com/MVIG-SJTU/AlphaPose/tree/pytorch#installation) to install the Pytorch version of AlphaPose.
2. Apply this diff to this [commit](https://github.com/MVIG-SJTU/AlphaPose/commit/ded84d450faf56227680f0527ff7e24ab7268754) on AlphaPose and use their [video_demo.py](https://github.com/MVIG-SJTU/AlphaPose/blob/ded84d450faf56227680f0527ff7e24ab7268754/video_demo.py) to process your video.
1. Install norfair with `pip install norfair[video]`.
2. [Follow the instructions](https://github.com/MVIG-SJTU/AlphaPose/tree/pytorch#installation) to install the Pytorch version of AlphaPose.
3. Apply this diff to this [commit](https://github.com/MVIG-SJTU/AlphaPose/commit/ded84d450faf56227680f0527ff7e24ab7268754) on AlphaPose and use their [video_demo.py](https://github.com/MVIG-SJTU/AlphaPose/blob/ded84d450faf56227680f0527ff7e24ab7268754/video_demo.py) to process your video.

```diff
diff --git a/dataloader.py b/dataloader.py
Expand Down
5 changes: 3 additions & 2 deletions demos/detectron2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Simplest possible example of tracking. Based on [Detectron2](https://github.com/

Assuming Norfair is installed:

1. [Follow the instructions](https://detectron2.readthedocs.io/tutorials/install.html) to install Detectron2.
2. Run `python detectron2_cars.py`. For the demo, we are using [this traffic footage](https://www.youtube.com/watch?v=aio9g9_xVio).
1. Install norfair with `pip install norfair[video]`.
2. [Follow the instructions](https://detectron2.readthedocs.io/tutorials/install.html) to install Detectron2.
3. Run `python detectron2_cars.py`. For the demo, we are using [this traffic footage](https://www.youtube.com/watch?v=aio9g9_xVio).

## Explanation

Expand Down
7 changes: 4 additions & 3 deletions demos/motmetrics4norfair/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Demo on how to evaluate a Norfair tracker on the [MOTChallenge](https://motchall

## Instructions

1. Download the [MOT17](https://motchallenge.net/data/MOT17/) dataset running
1. Install norfair with `pip install norfair[metrics,video]`.
2. Download the [MOT17](https://motchallenge.net/data/MOT17/) dataset running

```bash
curl -O https://motchallenge.net/data/MOT17.zip # To download Detections + Ground Truth + Images (5.5GB)
Expand All @@ -18,7 +19,7 @@ unzip MOT17Labels.zip

Given that the ground truth files for the testing set are not publicly available, you will only be able to use motmetrics4norfair with the training set.

2. Display the motmetrics4norfair instructions:
3. Display the motmetrics4norfair instructions:
```bash
python motmetrics4norfair.py --help
```
```
5 changes: 3 additions & 2 deletions demos/openpose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Demo for extrapolating detections through skipped frames. Based on [OpenPose](ht

## Instructions

1. Install [OpenPose version 1.4](https://github.com/CMU-Perceptual-Computing-Lab/openpose/releases/tag/v1.4.0).
2. Run `python openpose_extrapolation.py`.
1. Install norfair with `pip install norfair[video]`.
2. Install [OpenPose version 1.4](https://github.com/CMU-Perceptual-Computing-Lab/openpose/releases/tag/v1.4.0).
3. Run `python openpose_extrapolation.py`.

## Explanation

Expand Down
5 changes: 3 additions & 2 deletions demos/yolov4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Simplest possible example of tracking. Based on [pytorch YOLOv4](https://github.

## Instructions

1. Clone [pytorch YOLOv4](https://github.com/Tianxiaomo/pytorch-YOLOv4/tree/master) and download the [weights](https://drive.google.com/open?id=1wv_LiFeCRYwtpkqREPeI13-gPELBDwuJ) published on the repo into your local clone of the repo.
2. Copy `yolov4demo.py` into your local clone of the repo and run `python yolov4demo.py <video file>`.
1. Install norfair with `pip install norfair[video]`.
2. Clone [pytorch YOLOv4](https://github.com/Tianxiaomo/pytorch-YOLOv4/tree/master) and download the [weights](https://drive.google.com/open?id=1wv_LiFeCRYwtpkqREPeI13-gPELBDwuJ) published on the repo into your local clone of the repo.
3. Copy `yolov4demo.py` into your local clone of the repo and run `python yolov4demo.py <video file>`.

## Explanation

Expand Down
7 changes: 5 additions & 2 deletions norfair/drawing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Optional, Tuple, Sequence

import cv2
try:
import cv2
except:
from utils import DummyOpenCVImport
cv2 = DummyOpenCVImport()
import numpy as np
import random

Expand Down
6 changes: 5 additions & 1 deletion norfair/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from rich import print
from rich.progress import track
from norfair import Detection
import motmetrics as mm
try:
import motmetrics as mm
except:
from utils import DummyMOTMetricsImport
mm = DummyMOTMetricsImport()
from collections import OrderedDict
import pandas as pd

Expand Down
11 changes: 11 additions & 0 deletions norfair/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,14 @@ def get_cutout(points, image):
max_y = int(max(points[:, 1]))
min_y = int(min(points[:, 1]))
return image[min_y:max_y, min_x:max_x]


class DummyOpenCVImport:
def __getattribute__(self, name):
print("You are trying to use Norfair's video features. Install with `pip install norfair\[video]`, or install opencv-python manually.")
exit()

class DummyMOTMetricsImport:
def __getattribute__(self, name):
print("You are trying to use Norfair's metrics features. Install with `pip install norfair\[metrics]`, or install motmetrics manually.")
exit()
7 changes: 5 additions & 2 deletions norfair/video.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import time
from typing import Optional, List, Union

import cv2
try:
import cv2
except ImportError:
from utils import DummyOpenCVImport
cv2 = DummyOpenCVImport()
import numpy as np
from rich import print
from rich.progress import BarColumn, Progress, TimeRemainingColumn, ProgressColumn
Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
[tool.poetry]
name = "norfair"
version = "0.1.8"
version = "0.2.0"
description = "Lightweight Python library for real-time 2D object tracking."
license = "BSD-3-Clause"
authors = ["Tryolabs <[email protected]>"]
repository = "https://github.com/tryolabs/norfair"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.6"
python = "^3.7"
filterpy = "^1.4.5"
rich = "^6.1.1"
opencv-python = ">= 3.2.0, < 5.0.0"
motmetrics = "1.2.0"
opencv-python = {version = ">= 3.2.0, < 5.0.0", optional = true}
motmetrics = {version = "1.2.0", optional = true}

[tool.poetry.extras]
metrics = ["motmetrics"]
video = ["opencv-python"]

[tool.poetry.dev-dependencies]
pytest = "^6.0.1"
Expand Down

0 comments on commit e7c014d

Please sign in to comment.