Skip to content

Commit

Permalink
Add objectron app that logs objectron dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed May 2, 2022
1 parent 7560621 commit 005ad1a
Show file tree
Hide file tree
Showing 17 changed files with 2,348 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
**/target
/.vscode
/media
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[workspace]
resolver = "2"
members = ["comms", "log_types", "viewer", "web_server"]
members = [
"comms",
"log_types",
"objectron",
"viewer",
"web_server",
]


[profile.dev]
Expand Down
1 change: 1 addition & 0 deletions objectron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dataset/
24 changes: 24 additions & 0 deletions objectron/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "objectron"
version = "0.1.0"
edition = "2021"
rust-version = "1.60"
license = "MIT OR Apache-2.0"
publish = false


[dependencies]
log_types = { path = "../log_types" }
viewer = { path = "../viewer" }

anyhow = "1"
clap = "3.1"
glam = "0.20" # to convert rotation matrices to quaternions
image = { version = "0.23", default-features = false, features = ["jpeg"] }
itertools = "0.10"
prost = "0.10"
tracing = "0.1"
tracing-subscriber = "0.3"

[build-dependencies]
prost-build = "0.10"
4 changes: 4 additions & 0 deletions objectron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```sh
./download_dataset.py
cargo run --release -p objectron -- objectron/dataset/camera/batch-5/31
```
14 changes: 14 additions & 0 deletions objectron/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main() -> std::io::Result<()> {
// for filename in [
// // "a_r_capture_metadata.proto",
// "annotation_data.proto",
// // "object.proto",
// ] {
// println!("cargo:rerun-if-changed=src/protos/{filename}");
// prost_build::Config::new()
// .out_dir("src/generated/")
// .compile_protos(&[&format!("src/protos/{filename}")], &["src/protos/"])?;
// }

Ok(())
}
71 changes: 71 additions & 0 deletions objectron/download_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3

# TODO: translate to build.rs instead?

import requests
import os


def download(url, path):
if not os.path.exists(path):
print(f"downloading {url}…")
response = requests.get(url)
with open(path, "wb") as file:
file.write(response.content)


def split_video_into_frames(video_path, frames_path):
if not os.path.exists(frames_path):
print("Splitting video into frames…")
os.makedirs(frames_path, exist_ok=True)

import cv2
vidcap = cv2.VideoCapture(video_path)
success, image = vidcap.read()
count = 0
while success:
cv2.imwrite(f"{frames_path}/{count}.jpg", image)
success, image = vidcap.read()
count += 1


public_url = "https://storage.googleapis.com/objectron"


def download_data(video_id):
print(f"downloading {video_id}…")

dir = f"dataset/{video_id}"
os.makedirs(dir, exist_ok=True)

download(f"{public_url}/videos/{video_id}/video.MOV",
f"{dir}/video.MOV")

# use object.proto
download(f"{public_url}/videos/{video_id}/geometry.pbdata",
f"{dir}/geometry.pbdata")

# Please refer to Parse Annotation tutorial to see how to parse the annotation files.
download(f"{public_url}/annotations/{video_id}.pbdata",
f"{dir}/annotation.pbdata")

split_video_into_frames(f"{dir}/video.MOV", f"{dir}/video")


def download_dataset(name):
video_ids = requests.get(
f"{public_url}/v1/index/{name}_annotations_test").text
video_ids = video_ids.split('\n')
for i in range(10):
download_data(video_ids[i])


download_dataset("bike")
download_dataset("book")
download_dataset("bottle")
download_dataset("camera")
download_dataset("cereal_box")
download_dataset("chair")
download_dataset("cup")
download_dataset("laptop")
download_dataset("shoe")
1 change: 1 addition & 0 deletions objectron/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew install protobuf-c
Loading

0 comments on commit 005ad1a

Please sign in to comment.