libcudaisp  0.1.4
cudashift_example.cpp

This illustrates the shift usage. To run the example, please, pass the following arguments:

1: the input image (bayer {10, 12, 14, 16})

2: the output image (bayer 8)

3: width

4: height

5: number of shifts (shift right)

/*
* Copyright (C) 2023 RidgeRun, LLC (http://www.ridgerun.com)
* All Rights Reserved.
*
* The contents of this software are proprietary and confidential to RidgeRun,
* LLC. No part of this program may be photocopied, reproduced or translated
* into another programming language without prior written consent of
* RidgeRun, LLC. The user is free to modify the source code after obtaining
* a software license from RidgeRun. All source code changes must be provided
* back to RidgeRun without any encumbrance.
*/
#include "framereader.hpp" /* NOLINT */
#include <iostream>
#include <libcudaisp/cudabufferparams.hpp>
#include <libcudaisp/ibackend.hpp>
#include <libcudaisp/shiftparams.hpp>
#include <memory>
#include <string>
int main(int argc, char **argv) {
int ret = 0;
if (argc != 6) {
std::cerr << "Error: requires 5 arguments"
<< "\tinput_path output_path width height shift" << std::endl;
return -1;
}
/* Configuring the image */
const int input_buffer_width = atoi(argv[3]);
const int input_buffer_height = atoi(argv[4]);
const int shift_value = atoi(argv[5]);
const size_t input_buffer_size = input_buffer_width * input_buffer_height * 2;
const int input_buffer_planes = 1;
const rr::Format input_buffer_format = rr::Format::kBayer10;
const std::array<int, rr::Buffer::kMaxPlanes> input_buffer_strides = {
input_buffer_width * 2, 0, 0, 0};
const int output_buffer_width = input_buffer_width;
const int output_buffer_height = input_buffer_height;
const size_t output_buffer_size = output_buffer_width * output_buffer_height;
const rr::Format output_buffer_format = rr::Format::kBayer8;
const int output_buffer_planes = 1;
const std::array<int, rr::Buffer::kMaxPlanes> output_buffer_strides = {
output_buffer_width, 0, 0, 0};
/* Create backend, algorithms and params */
auto isp_backend = rr::IBackend::Build(rr::Backends::kCUDA, nullptr);
auto isp_shift =
isp_backend->CreateAlgorithm(rr::Algorithms::kShift, nullptr);
auto memory_params = std::make_shared<rr::CudaBufferParams>();
memory_params->type = rr::CudaType::kUnified;
/* Create buffers */
auto input_buffer =
isp_backend->CreateBuffer(input_buffer_size, memory_params);
auto output_buffer =
isp_backend->CreateBuffer(output_buffer_size, memory_params);
/* Format buffers */
rrerr = input_buffer->SetBufferInfo(input_buffer_format, input_buffer_planes,
input_buffer_strides, input_buffer_width,
input_buffer_height);
if (rrerr.IsError()) {
std::cerr << "Error allocating the input buffer: " << rrerr.GetDescription()
<< std::endl;
return -1;
}
rrerr = output_buffer->SetBufferInfo(
output_buffer_format, output_buffer_planes, output_buffer_strides,
output_buffer_width, output_buffer_height);
if (rrerr.IsError()) {
std::cerr << "Error allocating the output buffer: "
<< rrerr.GetDescription() << std::endl;
return -1;
}
ret = ReadFrame(argv[1], input_buffer->data(), input_buffer_size);
if (!ret) {
std::cerr << "Cannot read frame" << std::endl;
return -1;
}
/* Apply the Shifting */
auto params = std::make_shared<rr::ShiftParams>();
params->shift = shift_value;
rrerr =
isp_shift->Apply(input_buffer.get(), output_buffer.get(), params, false);
if (rrerr.IsError()) {
std::cerr << "Error while applying debayering: " + rrerr.GetDescription()
<< std::endl;
return -1;
}
/* Synchronize the execution */
rrerr = isp_backend->Synchronize();
if (rrerr.IsError()) {
std::cerr << "Error while synchronizing: " + rrerr.GetDescription()
<< std::endl;
return -1;
}
/* Write result to file */
ret = WriteFrame(argv[2], output_buffer->data(), output_buffer_size);
if (!ret) {
std::cerr << "Cannot write frame" << std::endl;
return -1;
}
return 0;
}
rr::Backends::kCUDA
@ kCUDA
CUDA backend.
rr::Algorithms::kShift
@ kShift
Shift algorithm.
rr::RuntimeError
Implements the error handling class.
Definition: runtimeerror.hpp:27
rr::Format::kBayer10
@ kBayer10
Bayer10 image format.
rr::RuntimeError::GetDescription
const std::string GetDescription() const
Returns a human readable description of the error.
Definition: runtimeerror.cpp:31
rr::CudaType::kUnified
@ kUnified
Unified memory.
rr::Format::kBayer8
@ kBayer8
Bayer8 image format.
rr::IBackend::Build
static std::shared_ptr< IBackend > Build(const Backends backend, const std::shared_ptr< IParams > params)
This method construct the backend objects.
Definition: ibackend.cpp:24
rr::RuntimeError::IsError
bool IsError() const
Checks if the RuntimeError is in an error state.
Definition: runtimeerror.cpp:37
rr::Format
Format
This class contains different image formats.
Definition: format.hpp:24