Skip to content

Commit

Permalink
Added script to render the video of detections as a point
Browse files Browse the repository at this point in the history
  • Loading branch information
d61h6k4 committed Feb 17, 2021
1 parent 5f8c643 commit d47dd7f
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 11 deletions.
38 changes: 38 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
#* @global-owner1 @global-owner2
* @d61h6k4

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
# *.js @js-owner

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
# *.go [email protected]

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
# /build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
# docs/* [email protected]

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
# apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository.
# /docs/ @doctocat
22 changes: 22 additions & 0 deletions .github/workflows/cpp_linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: C++ lint

on:
push:
branches-ignore:
- 'master'

jobs:
build:
name: C++ Linter by Clang-Format
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install clang-format
run: |
sudo apt install clang-format
- name: Run linter
run: |
CLANG_FORMAT_ROOT=. TEST=1 bash tools/clang_format_all_the_things.sh
41 changes: 41 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
## Project tests GitHub Actions
name: Lint

# Start the job on all push
on:
push:
branches-ignore:
- 'master'

# Set the Job
jobs:
build:
# Name the Job
name: Python linter
# Set the agent to run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

# Load all steps
steps:
# Checkout the code base #
- name: Checkout Code
uses: actions/checkout@v2

# Prepare python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools pylint
- name: Run linter
run: |
# bash tools/pylint_code.sh
41 changes: 41 additions & 0 deletions .github/workflows/types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
## Project tests GitHub Actions
name: Check types

# Start the job on all push
on:
push:
branches-ignore:
- 'master'

# Set the Job
jobs:
build:
# Name the Job
name: Python types :D
# Set the agent to run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

# Load all steps
steps:
# Checkout the code base #
- name: Checkout Code
uses: actions/checkout@v2

# Prepare python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools pytype
- name: Run pytype
run: |
# bash tools/check_pytype.sh
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
VIDEO_NAME = vfb_luebeck_012500_3min
VIDEO_NAME = ma8796bf4f_012300_15min

build:
bazel build --define MEDIAPIPE_DISABLE_GPU=1 //runner:ap_demo

debug: build
GLOG_logtostderr=1 bazel-bin/runner/ap_demo \
--calculator_graph_config_file runner/ap_demo_debug_graph.pbtxt \
--input_side_packets=input_video_path=test_videos/$(VIDEO_NAME).mp4,output_detections_file_path=$(VIDEO_NAME)_detections.csv
--input_side_packets=input_video_path=test_videos/$(VIDEO_NAME).mp4,output_detections_file_path=detection_csvs/$(VIDEO_NAME).csv

render: build
GLOG_logtostderr=1 bazel-bin/runner/ap_demo \
--calculator_graph_config_file runner/ap_demo_graph.pbtxt \
--input_side_packets=input_video_path=test_videos/$(VIDEO_NAME).mp4,output_video_path=processed_videos/$(VIDEO_NAME).mp4
--input_side_packets=input_video_path=test_videos/$(VIDEO_NAME).mp4,output_video_path=rendered_videos/$(VIDEO_NAME).mp4


render_schematic:
bazel run //runner:schematic_visualizer -- --detections `pwd`/detection_csvs/$(VIDEO_NAME).csv


all: debug render render_schematic
15 changes: 14 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ _MEDIAPIPE_VERSION = "0.8.0"

http_archive(
name = "mediapipe",
#sha256 = "0b129a28864fd2cd2822948621645efb9d62b6d043d1c4da3cf2d01886bfd901",
sha256 = "0b129a28864fd2cd2822948621645efb9d62b6d043d1c4da3cf2d01886bfd901",
strip_prefix = "mediapipe-{}".format(_MEDIAPIPE_VERSION),
url = "https://github.com/google/mediapipe/archive/{}.tar.gz".format(_MEDIAPIPE_VERSION),
)
Expand Down Expand Up @@ -104,6 +104,19 @@ git_repository(
remote = "[email protected]:d61h6k4/autoproduction.git",
)

http_archive(
name = "rules_python",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
)

load("@rules_python//python:pip.bzl", "pip_install")

pip_install(
name = "ap_demo_deps",
requirements = "//:requirements.txt",
)

_BAZEL_TOOLCHAINS_VERSION = "4.0.0"

http_archive(
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tqdm
numpy
pandas
matplotlib
13 changes: 13 additions & 0 deletions runner/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_python//python:defs.bzl", "py_binary")
load("@ap_demo_deps//:requirements.bzl", "requirement")

cc_binary(
name = "ap_demo",
Expand All @@ -12,3 +14,14 @@ cc_binary(
"@mediapipe//mediapipe/examples/desktop:simple_run_graph_main",
],
)

py_binary(
name = "schematic_visualizer",
srcs = ["schematic_visualizer.py"],
deps = [
requirement("tqdm"),
requirement("numpy"),
requirement("pandas"),
requirement("matplotlib"),
],
)
14 changes: 7 additions & 7 deletions runner/calculators/autoproduction_dump_calculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace mediapipe {
class AutoproductionDumpCalculator : public CalculatorBase {
public:
static ::mediapipe::Status GetContract(CalculatorContract* cc);
::mediapipe::Status Open(CalculatorContext* cc) override;
::mediapipe::Status Process(CalculatorContext* cc) override;
::mediapipe::Status Close(CalculatorContext* cc) override;
public:
static ::mediapipe::Status GetContract(CalculatorContract *cc);
::mediapipe::Status Open(CalculatorContext *cc) override;
::mediapipe::Status Process(CalculatorContext *cc) override;
::mediapipe::Status Close(CalculatorContext *cc) override;

private:
private:
std::fstream dumper_;
std::fstream detections_;
};
} // namespace mediapipe
} // namespace mediapipe
64 changes: 64 additions & 0 deletions runner/schematic_visualizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import argparse
import pathlib
import tqdm

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


def parse_args():
parser = argparse.ArgumentParser()

parser.add_argument("--detections",
required=True,
help="Path to the CSV file with detections",
type=pathlib.Path)
return parser.parse_args()


def label_to_color(arr):
return np.array(
list(map(lambda x: '#1f77b4' if x == 'person' else '#ff7f0e', arr)))


def main():
args = parse_args()

df = pd.read_csv(args.detections)

df['y_center'] = 800. * (df['ymin'] + df['height'] / 2.)
df['x_center'] = 3840. * (df['xmin'] + df['width'] / 2.)

start = 0
end = df.iloc[df.shape[0] - 1].frame_num
total = end - start

fig, ax = plt.subplots(figsize=(12, 4))
pbar = tqdm.tqdm(total=total)

def frame(w):
pbar.update(1)
ax.clear()

ax.set_ylim(-900.0, 100.0)
ax.set_xlim(0.0, 3840.0)

return ax.scatter(df[df.frame_num == (start + w)].x_center.values,
1 - df[df.frame_num == (start + w)].y_center.values,
c=label_to_color(
df[df.frame_num == (start + w)].label.values))

anim = animation.FuncAnimation(fig,
frame,
frames=total,
interval=40,
blit=False,
repeat=False)

anim.save(args.detections.with_suffix(".mp4"))


if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions tools/bazel_style.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[style]
based_on_style = google
allow_split_before_dict_value = False
spaces_around_default_or_named_assign = True
8 changes: 8 additions & 0 deletions tools/check_pytype.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/env bash

set -ex;

JOBS=$(nproc) || JOBS=4
python3 -m pip install pytype

python3 -m pytype --python-version 3.8 --keep-going -j "$JOBS" --strict-import --config "setup.cfg"
42 changes: 42 additions & 0 deletions tools/clang_format_all_the_things.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -ex

# change to root directory
cd "$(dirname "$0")/.."

# directories to run against
DIRS="."

# file matching patterns to check
GLOB="*.h *.cc"

# clang format command
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}

files=
for dir in $DIRS
do
for glob in $GLOB
do
files="$files `find $dir -name $glob`"
done
done

if [ "$TEST" == "" ]
then
echo $files | xargs $CLANG_FORMAT -i
else
ok=yes
for file in $files
do
tmp=`mktemp`
$CLANG_FORMAT $file > $tmp
diff -u $file $tmp || ok=no
rm $tmp
done
if [ $ok == no ]
then
false
fi
fi
Loading

0 comments on commit d47dd7f

Please sign in to comment.