Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tracking with OpenCV #1003

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ __pycache__
# Ignore development npm files
node_modules

# Ignore goturn model
goturn.caffemodel
goturn.prototxt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this model is very large. So placing it in source tree would lead to docker builds slowdown.

What is about .dockerignore? (if you want to add it where)
Or remove from both places.


.DS_Store
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ wget https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_co
export AUTO_SEGMENTATION_PATH="/path/to/dir" # dir must contain mask_rcnn_coco.h5 file
```

### Tracking
- Download the GOTURN model if the the OpenCV GOTURN tracker is to be used.
```sh
#This downloads it into the cvat folder
components/tracking/install.sh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

into the cvat folder

Root directory doesn't look as a right place.
I believe it make sense to download it into appropriate places, likecomponents/tracking/model.

Or take a look in a direction (investigate) of using docker volumes / mounted shares with large models.

```
- Add next lines to ``.env/bin/activate``:
```sh
export TRACKING="yes"
```

## JavaScript/Typescript coding style

We use the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) for JavaScript code with a
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ RUN if [ "$AUTO_SEGMENTATION" = "yes" ]; then \
bash -i /tmp/components/auto_segmentation/install.sh; \
fi

ARG TRACKING
ENV TRACKING=${TRACKING}
ENV TRACKING_PATH=${HOME}/tracking
RUN if [ "$TRACKING" = "yes" ]; then \
bash -i /tmp/components/tracking/install.sh; \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking may be used without GOTURN.
Consider making using of GOTURN model optional.

fi

ARG WITH_TESTS
RUN if [ "$WITH_TESTS" = "yes" ]; then \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
Expand Down
19 changes: 19 additions & 0 deletions components/tracking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Tracking
This components allows to track bounding boxes in consecutive images.

### Build docker image
```bash
# From project root directory
docker-compose -f docker-compose.yml -f components/tracking/docker-compose.tracking.yml build
```

### Run docker container
```bash
# From project root directory
docker-compose -f docker-compose.yml -f components/tracking/docker-compose.tracking.yml up -d
```

### TODO
* Make API consistent (one request per tracking job)
* Put jobs into queque
* Enable by default?
13 changes: 13 additions & 0 deletions components/tracking/docker-compose.tracking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
version: "2.3"

services:
cvat:
build:
context: .
args:
TRACKING: "yes"
15 changes: 15 additions & 0 deletions components/tracking/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

# Install GOTURN model for OpenCV; It is not in a package and has to be downloaded
cd "$(dirname "$0")"
echo "Downloading GOTURN model. This can take a while."
wget -q 'https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.prototxt'
wget -q 'https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.001'
wget -q 'https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.002'
wget -q 'https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.003'
wget -q 'https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.004'
cat goturn.caffemodel.zip* > goturn.caffemodel.zip
unzip goturn.caffemodel.zip
mv goturn.caffemodel goturn.prototxt ../..
rm goturn.caffemodel.zip*
22 changes: 13 additions & 9 deletions cvat/apps/engine/static/engine/js/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,22 @@ class ShapeModel extends Listener {
return interpolated;
}

_neighboringFrames(frame) {
_neighboringFrames(frame, predicate = () => true) {
if (!Number.isInteger(frame) || frame < 0) {
throw Error(`Got invalid frame: ${frame}`);
}

let leftFrame = null;
let rightFrame = null;

for (let frameKey in this._positions) {
frameKey = +frameKey;
if (frameKey < frame && (frameKey > leftFrame || leftFrame === null)) {
if (frameKey < frame && (frameKey > leftFrame || leftFrame === null)
&& predicate(this._positions[frameKey])) {
leftFrame = frameKey;
}

if (frameKey > frame && (frameKey < rightFrame || rightFrame === null)) {
if (frameKey > frame && (frameKey < rightFrame || rightFrame === null)
&& predicate(this._positions[frameKey])) {
rightFrame = frameKey;
}
}
Expand Down Expand Up @@ -435,12 +436,14 @@ class ShapeModel extends Listener {
this.notify('click');
}

prevKeyFrame() {
return this._neighboringFrames(window.cvat.player.frames.current)[0];
prevKeyFrame(predicate = () => true) {
return this._neighboringFrames(window.cvat.player.frames.current,
predicate)[0];
}

nextKeyFrame() {
return this._neighboringFrames(window.cvat.player.frames.current)[1];
nextKeyFrame(predicate = () => true) {
return this._neighboringFrames(window.cvat.player.frames.current,
predicate)[1];
}

initKeyFrame() {
Expand Down Expand Up @@ -678,7 +681,8 @@ class BoxModel extends ShapeModel {
ytl: Math.clamp(position.ytl, 0, window.cvat.player.geometry.frameHeight),
xbr: Math.clamp(position.xbr, 0, window.cvat.player.geometry.frameWidth),
ybr: Math.clamp(position.ybr, 0, window.cvat.player.geometry.frameHeight),
occluded: position.occluded,
byMachine: position.byMachine ? true : false,
occluded: position.occluded ? true : false,
z_order: position.z_order,
};

Expand Down
10 changes: 10 additions & 0 deletions cvat/apps/tracking/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Copyright (C) 2018-2019 Intel Corporation
#
# SPDX-License-Identifier: MIT

from cvat.settings.base import JS_3RDPARTY

# default_app_config = 'cvat.apps.tracking.apps.TrackingConfig'

JS_3RDPARTY['engine'] = JS_3RDPARTY.get('engine', []) + ['tracking/js/enginePlugin.js']
8 changes: 8 additions & 0 deletions cvat/apps/tracking/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT


# Register your models here.

11 changes: 11 additions & 0 deletions cvat/apps/tracking/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT

from django.apps import AppConfig


class TrackingConfig(AppConfig):
name = 'tracking'

5 changes: 5 additions & 0 deletions cvat/apps/tracking/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT

8 changes: 8 additions & 0 deletions cvat/apps/tracking/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT


# Create your models here.

Loading