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/jpegSHA-256 1a0739698875a91967f262254d08c660bf46fe5404a74a8e0d161a4ed72463bfOA-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/jpegSHA-256 163864805a449c278e1abd26b921e502cde9deacfa4dbf5179eef6b44b9b6ed9sdk/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 · JPEGSHA-256 0f38f31ec6eba846SDL_VIDEODRIVER=x11 bin/release/sdk/examples/vision/exampleVisionImage --preview · 2026-08-31