SIMA_COLORCONVERT

Description

This graph is responsible for color converting available frame/image from one color space to other color space. Options available for this color space conversion are mentioned below.

Graph Info

Overview

SIMA_COLORCONVERT

Graph Name

SIMA_COLORCONVERT

Graph ID

0

Operations Supported

SIMA_COLOR_BGR2RGB(0)

SIMA_COLOR_RGB2BGR(1)

SIMA_COLOR_BGR2GRAY(2)

SIMA_COLOR_RGB2GRAY(3)

SIMA_COLOR_IYUV2BGR(4)

SIMA_COLOR_IYUV2NV12(5)

SIMA_COLOR_NV12TOBGR (6)

SIMA_COLOR_BGR2NV12 (7)

SIMA_COLOR_RGB2NV12 (8)

SIMA_COLOR_NV12TORGB (9)

Available Since Yocto Build

B668

BGR2NV12 available from build → B758

RGB2NV12 available from build → B760

Example Config

Below is the example config json for this graph. We need to use such config for configuring the EV74 graph first. For this purpose, we need a CVU Configuration Application developed in C++.

{
"version": 0.1,
"node_name": "cvu-color-convert",
"simaai__params": {
   "params": 15,
   "index": 0,
   "cpu": 1,
   "next_cpu": 2,
   "graph_id": 0,
   "input_width": 1920,
   "input_height": 1080,
   "output_width": 1920,
   "output_height": 1080,
   "batch_size": 1,
   "conv_type": 0,
   "format": 1,
   "in_type": 0,
   "no_of_outbuf": 1,
   "out_type": 2,
   "out_sz": 6220800,
   "ibufname": "in-img-source",
   "debug": 0,
   "dump_data": 1
   }
}

Parameters

SIMA_COLORCONVERT Params

Parameter Name

Parameter Description

Data Type

Default

Min

Max

input_width

Width of the input image

int32_t

1920

1

4096

input_height

Height of the input image

int32_t

1080

1

4096

output_width

Width of the output image (needs to be same as the input_width)

int32_t

1920

1

4096

output_height

Height of the output image (needs to be same as the input_height)

int32_t

1080

1

4096

batch_size

Number of input images to be preprocessed at once

int32_t

1

1

50

conv_type

Color conversion type:

SIMA_COLOR_BGR2RGB(0)

SIMA_COLOR_RGB2BGR(1)

SIMA_COLOR_BGR2GRAY(2)

SIMA_COLOR_RGB2GRAY(3)

SIMA_COLOR_IYUV2BGR(4)

SIMA_COLOR_IYUV2NV12(5)

SIMA_COLOR_NV12TOBGR (6)

SIMA_COLOR_BGR2NV12 (7)

SIMA_COLOR_RGB2NV12 (8)

SIMA_COLOR_NV12TORGB (9)

int32_t

0

0

9

Note

Please note that, the out_sz in above json needs to be calculated based on your output format. Ex. If the output format is RGB, then the out_sz will be output_height * output_width * 3. Here, 3 is the number of channels

CVU Configuration Application

Note

  • The need to write, build and execute a dependent application for the CVU will be removed in an upcoming release.

To configure any CVU graph, a C++ CVU Configuration Application must be cross-compiled and executed on the board before using the CVU. Multiple graphs can be pre-programmed into the CVU before running any application. This guide provides a pre-written C++ application for download for each graph that can be cross-compiled on Palette, and executed on the board prior to running the simaaiprocesscvu GStreamer plugin. An pre-compiled version is also included for direct use. If you encounter issues, please re-compile the application from the sources provided.

How to compile using the files below

Please refer to How to compile CVU Configuration Application? for more info.

Directory structure

.
├── CMakeLists.txt
├── cvu_cfg_graph.cpp
└── cvu_cfg_main.cpp

Code files

cvu_cfg_graph.cpp
 1#define SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT (0)
 2#define INPUT_WIDTH   (1)
 3#define INPUT_HEIGHT  (2)
 4#define OUTPUT_WIDTH  (3)
 5#define OUTPUT_HEIGHT (4)
 6#define BATCH_SIZE    (5)
 7#define CONV_TYPE     (6)
 8
 9void configure_colorconvert(const char *json_in)
10{
11   simaai_params_t *params = parser_node_struct_init();
12
13   uint8_t *buf = (uint8_t *)calloc(1, sizeof(uint8_t) * 16);
14
15   int val = *((int *)parser_get_int(params, "input_width"));
16   send_i32_param(2, SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT, INPUT_WIDTH, buf, val);
17
18   val = *((int *)parser_get_int(params, "input_height"));
19   send_i32_param(2, SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT, INPUT_HEIGHT, buf, val);
20
21   val = *((int *)parser_get_int(params, "output_width"));
22   send_i32_param(2, SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT, OUTPUT_WIDTH, buf, val);
23
24   val = *((int *)parser_get_int(params, "output_height"));
25   send_i32_param(2, SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT, OUTPUT_HEIGHT, buf, val);
26
27   val = *((int *)parser_get_int(params, "batch_size"));
28   send_i32_param(2, SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT, BATCH_SIZE, buf, val);
29
30   val = *((int *)parser_get_int(params, "conv_type"));
31   send_i32_param(2, SIMA_IPC_CODE_GRAPH_SIMA_COLORCONVERT, CONV_TYPE, buf, val);
32
33   std::cout << "Completed Colorconvert Graph Configure \n";
34   free(buf);
35}
cvu_cfg_main.cpp
 1 #include <getopt.h>
 2 #include <sys/stat.h>
 3 #include <unistd.h>
 4
 5 #include <cstring>
 6 #include <iostream>
 7
 8 extern void configure_graph(const char *json_fpath);
 9
10 bool is_valid_path(const char *path) {
11   struct stat buffer;
12   return (stat(path, &buffer) == 0);
13 }
14
15 int main(int argc, char **argv) {
16   const char *json_path = argv[1];
17
18   if(is_valid_path(json_path)) {
19     configure_graph(json_path);
20   } else {
21     std::cerr << "Invalid path: " << json_path << std::endl;
22     return 1;
23   }
24
25   return 0;
26 }
CMakeLists.txt
 1 cmake_minimum_required(VERSION 3.16)
 2
 3 # set the project name
 4 set(GRAPH_NAME "colorconvert_000")
 5 set(PROJECT_NAME "CVU Graph Cfg. App.")
 6
 7 project("${PROJECT_NAME}"
 8     VERSION 0.1
 9     DESCRIPTION "CVU Graph Configuration Application"
10     LANGUAGES C CXX)
11
12 set(PIPELINE_SOURCES
13     cvu_cfg_graph.cpp)
14
15 execute_process(
16     COMMAND git rev-parse --abbrev-ref HEAD
17     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
18     OUTPUT_VARIABLE GIT_BRANCH
19     OUTPUT_STRIP_TRAILING_WHITESPACE
20 )
21
22 # Get the latest abbreviated commit hash of the working branch
23 execute_process(
24     COMMAND git log -1 --format=%h
25     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
26     OUTPUT_VARIABLE GIT_COMMIT_HASH
27     OUTPUT_STRIP_TRAILING_WHITESPACE
28 )
29
30 link_directories(${CMAKE_INSTALL_DIR}/core
31     ${CMAKE_INSTALL_DIR}/gst
32 )
33
34 include(GNUInstallDirs)
35
36 # ev-configuration genertion executable
37 set(EV_EXEC_NAME "${GRAPH_NAME}_cvu_cfg_app")
38
39 add_executable(${EV_EXEC_NAME}
40     cvu_cfg_main.cpp
41     cvu_cfg_graph.cpp)
42
43 target_link_libraries(${EV_EXEC_NAME}
44     PUBLIC
45     simaaiparser
46     evhelpers)
47
48 INSTALL(TARGETS "${EV_EXEC_NAME}")