-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ examples & roundtrip tests for image/segmentation-image/depth-ima…
…ge/tensor (#3899) ### What * Fixes #3380 * Part of #2919 commit history is a bit messy because this was based on the annotation context example pr. Speaking off, I made those a bit nicer on the way ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3899) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/3899) - [Docs preview](https://rerun.io/preview/c324163602dfdde33684cae0f9365fd72b177ad3/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/c324163602dfdde33684cae0f9365fd72b177ad3/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
- Loading branch information
Showing
34 changed files
with
893 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Create and log a depth image. | ||
|
||
#include <rerun.hpp> | ||
|
||
#include <algorithm> | ||
|
||
int main() { | ||
auto rec = rerun::RecordingStream("rerun_example_depth_image"); | ||
rec.connect("127.0.0.1:9876").throw_on_failure(); | ||
|
||
// Create a synthetic depth image. | ||
const int HEIGHT = 8; | ||
const int WIDTH = 12; | ||
std::vector<uint16_t> data(WIDTH * HEIGHT, 65535); | ||
for (auto y = 0; y < 4; ++y) { // top half | ||
std::fill_n(data.begin() + y * WIDTH, 6, 20000); // left half | ||
} | ||
for (auto y = 4; y < 8; ++y) { // bottom half | ||
std::fill_n(data.begin() + y * WIDTH + 6, 6, 45000); // right half | ||
} | ||
|
||
// If we log a pinhole camera model, the depth gets automatically back-projected to 3D | ||
rec.log( | ||
"world/camera", | ||
rerun::Pinhole::focal_length_and_resolution( | ||
{20.0f, 20.0f}, | ||
{static_cast<float>(WIDTH), static_cast<float>(HEIGHT)} | ||
) | ||
); | ||
|
||
rec.log( | ||
"world/camera/depth", | ||
rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Create and log a depth image. | ||
|
||
#include <rerun.hpp> | ||
|
||
#include <algorithm> | ||
|
||
int main() { | ||
auto rec = rerun::RecordingStream("rerun_example_depth_image"); | ||
rec.connect("127.0.0.1:9876").throw_on_failure(); | ||
|
||
// create a synthetic depth image. | ||
const int HEIGHT = 8; | ||
const int WIDTH = 12; | ||
std::vector<uint16_t> data(WIDTH * HEIGHT, 65535); | ||
for (auto y = 0; y < 4; ++y) { // top half | ||
std::fill_n(data.begin() + y * WIDTH, 6, 20000); // left half | ||
} | ||
for (auto y = 4; y < 8; ++y) { // bottom half | ||
std::fill_n(data.begin() + y * WIDTH + 6, 6, 45000); // right half | ||
} | ||
|
||
rec.log("depth", rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Create and log a image. | ||
|
||
#include <rerun.hpp> | ||
|
||
int main() { | ||
auto rec = rerun::RecordingStream("rerun_example_image_simple"); | ||
rec.connect("127.0.0.1:9876").throw_on_failure(); | ||
|
||
// Create a synthetic image. | ||
const int HEIGHT = 8; | ||
const int WIDTH = 12; | ||
std::vector<uint8_t> data(WIDTH * HEIGHT * 3, 0); | ||
for (size_t i = 0; i < data.size(); i += 3) { | ||
data[i] = 255; | ||
} | ||
for (auto y = 0; y < 4; ++y) { // top half | ||
auto row = data.begin() + y * WIDTH * 3; | ||
for (auto i = 0; i < 6 * 3; i += 3) { // left half | ||
row[i] = 0; | ||
row[i + 1] = 255; | ||
} | ||
} | ||
|
||
rec.log("image", rerun::Image({HEIGHT, WIDTH, 3}, std::move(data))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Create and log a segmentation image. | ||
|
||
#include <rerun.hpp> | ||
|
||
#include <algorithm> | ||
|
||
int main() { | ||
auto rec = rerun::RecordingStream("rerun_example_annotation_context_connections"); | ||
rec.connect("127.0.0.1:9876").throw_on_failure(); | ||
|
||
// Create a segmentation image | ||
const int HEIGHT = 8; | ||
const int WIDTH = 12; | ||
std::vector<uint8_t> data(WIDTH * HEIGHT, 0); | ||
for (auto y = 0; y < 4; ++y) { // top half | ||
std::fill_n(data.begin() + y * WIDTH, 6, 1); // left half | ||
} | ||
for (auto y = 4; y < 8; ++y) { // bottom half | ||
std::fill_n(data.begin() + y * WIDTH + 6, 6, 2); // right half | ||
} | ||
|
||
// create an annotation context to describe the classes | ||
rec.log_timeless( | ||
"/", | ||
rerun::AnnotationContext({ | ||
rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)), | ||
rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)), | ||
}) | ||
); | ||
|
||
rec.log("image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Create and log a tensor. | ||
|
||
#include <rerun.hpp> | ||
|
||
#include <random> | ||
|
||
int main() { | ||
auto rec = rerun::RecordingStream("rerun_example_tensor_simple"); | ||
rec.connect("127.0.0.1:9876").throw_on_failure(); | ||
|
||
std::default_random_engine gen; | ||
std::uniform_int_distribution<uint8_t> dist(0, 255); | ||
|
||
std::vector<uint8_t> data(8 * 6 * 3 * 5); | ||
std::generate(data.begin(), data.end(), [&] { return dist(gen); }); | ||
|
||
rec.log( | ||
"tensor", | ||
rerun::Tensor({8, 6, 3, 5}, data).with_dim_names({"batch", "channel", "height", "width"}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
582f2fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.25
.arrow/serialize/elem_count=1/arrow2
405
ns/iter (± 0
)320
ns/iter (± 1
)1.27
This comment was automatically generated by workflow using github-action-benchmark.