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

Support NV12-encoded images #3541

Merged
merged 25 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ed71fe1
Merge latest main and old nv12 support
zrezke Sep 28, 2023
a95e190
Cleanup and fix nv12 image support
zrezke Sep 29, 2023
7f299b3
clean shader
zrezke Sep 29, 2023
a3495b7
Update crates/re_types/src/datatypes/tensor_data_ext.rs
zrezke Oct 2, 2023
54e32c8
Update crates/re_renderer/src/renderer/rectangles.rs
zrezke Oct 2, 2023
ae1da4e
Rename texture encoding to shader_decoding, fix sizing multipliers, f…
zrezke Oct 8, 2023
8340261
Merge branch 'main' of github.com:rerun-io/rerun into nv12-support
zrezke Oct 8, 2023
b39e405
Addressed some more change requests
zrezke Oct 9, 2023
4e786a6
Replace width, height parameters of ImageFormat.NV12 with a single si…
zrezke Oct 14, 2023
e542a4e
Merge remote-tracking branch 'origin/main' into nv12-support
Wumpf Oct 16, 2023
5e877d9
Fix lacking ndarray conversion, fix compile warnings
Wumpf Oct 16, 2023
4ee7523
python formatting
Wumpf Oct 16, 2023
276ce92
nv12 image test
Wumpf Oct 16, 2023
ce23bee
Added python example for logging nv12 encoded images.
zrezke Oct 16, 2023
21aa188
Fill in example readme
zrezke Oct 16, 2023
1ddef73
Added nv12 requirements file to examples/python/requirements.txt
zrezke Oct 16, 2023
4378bb7
in order
zrezke Oct 16, 2023
e98c19b
Removed the link to example
zrezke Oct 16, 2023
910292f
python lints
zrezke Oct 16, 2023
bb69c1e
fix missing nv12 case in tensor_buffer_ext
Wumpf Oct 16, 2023
2ad6ecd
Merge remote-tracking branch 'origin/main' into nv12-support
Wumpf Oct 16, 2023
d7de4ee
fix missing nv12 case in tensor_buffer_ext
Wumpf Oct 16, 2023
e5a77ce
Merge commit '2ad6ecd' into nv12-support
zrezke Oct 16, 2023
d7bb552
rerun codegen after main merge
Wumpf Oct 16, 2023
fc13dd7
Merge branch 'main' into nv12-support
zrezke Oct 16, 2023
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
19 changes: 19 additions & 0 deletions examples/python/nv12/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Template
tags: [kebab-case, comma, separated]
description: "Short ~100-sign description of the example. No longer than 130 signs!"
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/template/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/template/src/main.rs
---
Wumpf marked this conversation as resolved.
Show resolved Hide resolved

<!--
Place a screenshot in place of this comment
Use `just upload --help` for instructions
-->

This example displays an NV12 encoded video stream from a webcam in rerun.

```bash
pip install -r examples/python/nv12/requirements.txt
python examples/python/nv12/main.py
```
65 changes: 65 additions & 0 deletions examples/python/nv12/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""
Stream NV12 images from a webcam.

Run:
```sh
pip install -r examples/python/nv12/requirements.txt
python examples/python/nv12/main.py
```
"""
from __future__ import annotations

import argparse

import rerun as rr # pip install rerun-sdk
import cv2
import numpy as np
import time


def bgr2nv12(bgr: np.ndarray) -> np.ndarray:
yuv = cv2.cvtColor(bgr, cv2.COLOR_RGB2YUV_I420)
uv_row_cnt = yuv.shape[0] // 3
uv_plane = np.transpose(yuv[uv_row_cnt * 2 :].reshape(2, -1), [1, 0])
yuv[uv_row_cnt * 2 :] = uv_plane.reshape(uv_row_cnt, -1)
return yuv


def main() -> None:
parser = argparse.ArgumentParser(description="Example of using the Rerun visualizer to display NV12 images.")
rr.script_add_args(parser)
parser.add_argument(
"-t",
"--timeout",
type=float,
default=5,
help="Timeout in seconds, after which the script will stop streaming frames.",
)
args = parser.parse_args()

rr.script_setup(args, "NV12 image example")

cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise RuntimeError("This example requires a webcam.")
start_time = time.time()
print(f"Started streaming NV12 images for {args.timeout} seconds.")
while start_time + args.timeout > time.time():
ret, frame = cap.read()
if not ret:
time.sleep(0.01)
continue
rr.log(
"NV12",
rr.ImageEncoded(
contents=bytes(bgr2nv12(frame)),
format=rr.ImageFormat.NV12((frame.shape[0], frame.shape[1])),
),
)
time.sleep(0.01)
rr.script_teardown(args)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions examples/python/nv12/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rerun-sdk>=0.10
opencv-python
numpy
Loading