0

So in the Halide aot example https://halide-lang.org/tutorials/tutorial_lesson_10_aot_compilation_run.html, there's this line:

Halide::Runtime::Buffer<uint8_t> input(640, 480), output(640, 480);

My question is, how does one load an image into the input runtime buffer?

zengod
  • 1,114
  • 13
  • 26

2 Answers2

1

The same way the previous tutorials load images.

Add this include:

#include "halide_image_io.h" // for load_image and save_image

Then replace

Halide::Runtime::Buffer<uint8_t> input(640, 480), output(640, 480);

with

Halide::Runtime::Buffer<uint8_t> input = Halide::Tools::load_image("path/to/input.png");
Halide::Runtime::Buffer<uint8_t> output(input.width(), input.height());

If you're interested in saving the output, after the error check, add the line:

Halide::Tools::save_image(output, "path/to/output.png");

Note that the paths, if not absolute paths, will be in the following directories: the Halide/tutorial/ directory for input, and the Halide/bin/build/tmp/ directory for the output, after running:

make tutorial_lesson_10_aot_compilation_run

from the root directory of Halide.

AJR
  • 11
  • 1
1

The latest syntax is as follows:

Halide::Runtime::Buffer<float> in = Tools::load_image("image.png");
Halide::Runtime::Buffer<float> out(in.width(), in.height(),in.channels());

int error = halide_blur(in, out); //halide_blur is the function defined in aot compiled code
Tools::save_image(out, output.png");