Examples
-
Example implementation of loading an image, passing it through a model, and receiving the resulting image
-
The constants at the top should be modified by the user:
- IMG_FILE : Path to the input image
- ENGINE_FILE : Path to the ONNX file
- OUTPUT_PATH : Path to the output image
- GPU_ID : GPU ID to be used
#include "dllengine.h"
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
using namespace cv;
const std::string IMG_FILE = "path/to/image.png";
const std::string ENGINE_FILE = "path/to/onnxfile.onnx";
const std::string OUTPUT_PATH = "example.png";
const int GPU_ID = 0;
int main()
{
Inferencer* inferencer = get_inferencer(ENGINE_FILE, GPU_ID);
Mat img_input = imread(IMG_FILE, IMREAD_GRAYSCALE);
int input_height = img_input.rows;
int input_width = img_input.cols;
auto* output_buffer = new unsigned char[img_input.rows * img_input.cols * 1]; // grayscale model
if (inferencer != nullptr)
{
if (do_inference(inferencer, img_input.data, output_buffer, img_input.cols, img_input.rows) != 0)
{
std::cout << "Error is occurred while inferencing.";
}
else
{
Mat img_pp = Mat(input_height, input_width, CV_8U, output_buffer);
imwrite(OUTPUT_PATH, img_pp);
std::cout << "Inference is done. " << std::endl;
}
remove_inferencer(inferencer);
}
}
-
explanation: