exImage.cpp

Convert and save a grayscale image. Load the Vision cover, convert its GPU-resident RGB pixels to Rec.709 grayscale, save the semantic Gray image, and optionally inspect it in Viewer.

ExSDK source-ownedC++Vision

Source

Example

1#include <oa/oa.h>
2
3OA_MAIN_PREVIEW("ExampleVisionImage") {
4 auto sourceResult = oa::FnImage::decodeFile(
5 oa::Paths::asset("image/coverVision.jpg"), oa::ImageFormat::Rgb);
6 if (not sourceResult.isOk()) return 1;
7 auto source = oa::move(sourceResult).getValue();
8
9 auto grayscale = oa::FnImage::grayscale(source);
10
11 const oa::Path output = oa::Paths::var("example/vision/coverVisionGrayscale.jpg");
12 if (not oa::Filesystem::createDirectories(output.parentPath()).isOk()) return 1;
13 if (not oa::FnImage::saveFile(output, grayscale, 92U).isOk()) return 1;
14
15 if (not grayscale.validate()) return 1;
16 if (grayscale.width() != 1672 or grayscale.height() != 941) return 1;
17 if (grayscale.format() != oa::ImageFormat::Gray) return 1;
18 if (not oa::Filesystem::isFile(output)) return 1;
19
20 oa::print("Saved grayscale image: {}", output.cStr());
21
22 if (argc > 1 and oa::StringView(argv[1]) == "--preview") {
23 oa::ViewerConfig previewConfig;
24 previewConfig.mode = oa::ViewerMode::Image;
25 previewConfig.title = "OA vision · grayscale cover";
26 previewConfig.width = 1280U;
27 previewConfig.height = 646U;
28 if (not oa::Viewer::preview(engine, oa::Paths::var("example/vision/coverVisionGrayscale.jpg").string(),
29 previewConfig).isOk()) {
30 return 1;
31 }
32 }
33 return 0;
34}
35

Output

Before / after. Compare the checked RGB source with the exact grayscale JPEG written by this example.

OA Vision cover showing a glitched figure in a modern room

source

Vision cover

Download image

The full-resolution RGB source decoded through oa::FnImage.

1672×941 · image/webpSHA-256 5271445056df76a1f38b47e7b5d3000e6cbb07bd2a038537c081b296fe5916ceOA-authored Vision module cover
OA Vision cover converted from RGB to grayscale

processed

Grayscale output

Download image

The full-resolution Rec.709 grayscale image converted on the GPU and saved by the source-owned example.

1672×941 · image/webpSHA-256 4dce1fb04dc03ac5cb65df3a82d34fbfa077f3016049863f956baf7076053849sdk/py/examples/vision/image.py

Present

The Output section above remains the exact artifact evidence. These captures document the current interactive Viewer surface used by the presentation path.

Current OA Viewer presenting the grayscale Vision cover edge to edge

OA Viewer · Presented state

Grayscale preview

The exact grayscale output above recaptured edge to edge in the current Viewer through this example's optional --preview path.

Download capture
1146×646 · WEBPSHA-256 f19a9f74f35eb7ddSDL_VIDEODRIVER=x11 bin/release/sdk/examples/vision/exampleVisionImage --preview · 2026-08-31