Skip to content

Commit

Permalink
modules: viss: Added raw histogram support
Browse files Browse the repository at this point in the history
Raw histogram output is enabled in viss module for VPAC3 and VPAC3L
test case for the same is enabled which writes distribution in a bin
file

SITREQ-5193

Signed-off-by: Shreyash Sinha <[email protected]>
  • Loading branch information
sinha-shreyash authored and ravi-rahul committed Nov 20, 2024
1 parent cf91501 commit c9673db
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 17 deletions.
1 change: 1 addition & 0 deletions modules/include/tiovx_viss_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef struct {
char sensor_name[ISS_SENSORS_MAX_NAME];
vx_bool enable_h3a_pad;
vx_bool enable_aewb_pad;
vx_bool enable_histogram_pad;
} TIOVXVissNodeCfg;

void tiovx_viss_init_cfg(TIOVXVissNodeCfg *cfg);
Expand Down
54 changes: 46 additions & 8 deletions modules/src/tiovx_viss_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
#define TIOVX_MODULES_DEFAULT_VISS_SENSOR "SENSOR_SONY_IMX219_RPI"
#define TIOVX_MODULES_DEFAULT_VISS_WIDTH 1920
#define TIOVX_MODULES_DEFAULT_VISS_HEIGHT 1080
#define NUM_BINS 128
#define OFFSET 0
#define DISTRIBUTION_RANGE 128

typedef struct {
vx_user_data_object viss_params_obj;
Expand Down Expand Up @@ -237,6 +240,7 @@ void tiovx_viss_init_cfg(TIOVXVissNodeCfg *node_cfg)
sprintf(node_cfg->sensor_name, TIOVX_MODULES_DEFAULT_VISS_SENSOR);
node_cfg->enable_h3a_pad = vx_false_e;
node_cfg->enable_aewb_pad = vx_false_e;
node_cfg->enable_histogram_pad = vx_false_e;

node_cfg->input_cfg.params.num_exposures = 1;
node_cfg->input_cfg.params.line_interleaved = vx_false_e;
Expand Down Expand Up @@ -386,6 +390,31 @@ vx_status tiovx_viss_init_node(NodeObj *node)
node->num_outputs++;
}

if (node_cfg->enable_histogram_pad == vx_true_e) {
#ifdef SOC_J721E
TIOVX_MODULE_ERROR("[VISS] Raw Histogram is not supported on J721E\n");
status = VX_FAILURE;
return status;
#endif
node->srcs[node->num_outputs].node = node;
node->srcs[node->num_outputs].pad_index = node->num_outputs;
node->srcs[node->num_outputs].node_parameter_index = 12;
node->srcs[node->num_outputs].num_channels = node_cfg->num_channels;
exemplar = (vx_reference)vxCreateDistribution(
node->graph->tiovx_context,
NUM_BINS,
OFFSET,
DISTRIBUTION_RANGE);
status = tiovx_module_create_pad_exemplar(&node->srcs[node->num_outputs],
exemplar);
if (VX_SUCCESS != status) {
TIOVX_MODULE_ERROR("[VISS] Create Histogram Output Failed\n");
return status;
}
vxReleaseReference(&exemplar);
node->num_outputs++;
}

sprintf(node->name, "viss_node");

tiovx_viss_module_configure_params(node);
Expand All @@ -402,6 +431,8 @@ vx_status tiovx_viss_create_node(NodeObj *node)
vx_user_data_object ae_awb_result = NULL;
vx_image output[] = {NULL, NULL, NULL, NULL, NULL};
vx_user_data_object h3a_stats = NULL;
vx_distribution histogram = NULL;
int output_index = 0;
vx_bool replicate[] = {vx_false_e, vx_false_e, vx_false_e,
vx_true_e, vx_false_e, vx_false_e,
vx_false_e, vx_false_e, vx_false_e,
Expand All @@ -410,13 +441,21 @@ vx_status tiovx_viss_create_node(NodeObj *node)

if (node_cfg->enable_aewb_pad == vx_true_e) {
replicate[1] = vx_true_e;

ae_awb_result = (vx_user_data_object)node->sinks[1].exemplar;
}

for (int i = 0; i < TIOVX_VISS_MODULE_MAX_OUTPUTS; i++) {
if (node_cfg->output_select[i] == TIOVX_VISS_MODULE_OUTPUT_EN) {
output[i] = (vx_image)node->srcs[output_index].exemplar;
replicate[i+4] = vx_true_e;
output_index++;
}
}

if (node_cfg->enable_h3a_pad == vx_true_e) {
h3a_stats =
(vx_user_data_object)node->srcs[node->num_outputs - 1].exemplar;
(vx_user_data_object)node->srcs[output_index].exemplar;
output_index++;
} else {
h3a_stats = vxCreateUserDataObject(node->graph->tiovx_context,
"tivx_h3a_data_t",
Expand All @@ -438,11 +477,10 @@ vx_status tiovx_viss_create_node(NodeObj *node)
node_priv->h3a_stats_arr, 0);
}

for (int i = 0, j = 0; i < TIOVX_VISS_MODULE_MAX_OUTPUTS; i++) {
if (node_cfg->output_select[i] == TIOVX_VISS_MODULE_OUTPUT_EN) {
output[i] = (vx_image)node->srcs[j++].exemplar;
replicate[i+4] = vx_true_e;
}
if (node_cfg->enable_histogram_pad == vx_true_e) {
replicate[12] = vx_true_e;
histogram = (vx_distribution)node->srcs[output_index].exemplar;
output_index++;
}

node->tiovx_node = tivxVpacVissNode(node->graph->tiovx_graph,
Expand All @@ -452,7 +490,7 @@ vx_status tiovx_viss_create_node(NodeObj *node)
(tivx_raw_image)(node->sinks[0].exemplar),
output[0], output[1], output[2],
output[3], output[4],
h3a_stats, NULL, NULL, NULL);
h3a_stats, NULL, NULL, histogram);

status = vxGetStatus((vx_reference)node->tiovx_node);
if (VX_SUCCESS != status) {
Expand Down
39 changes: 30 additions & 9 deletions tests/app_tiovx_viss_module_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,29 @@ vx_status app_modules_viss_test(vx_int32 argc, vx_char* argv[])
NodeObj *node = NULL;
TIOVXVissNodeCfg cfg;
BufPool *in_buf_pool = NULL, *out_buf_pool = NULL;
Buf *inbuf = NULL, *outbuf = NULL;
Buf *inbuf = NULL, *out_buf = NULL;
char input_filename[100];
char output_filename[100];
vx_uint32 bytes_read;

sprintf(input_filename, "%s/raw_images/modules_test/imx219_1920x1080_capture.raw", EDGEAI_DATA_PATH);
sprintf(output_filename, "%s/output/imx219_1920x1080_capture_nv12.yuv", EDGEAI_DATA_PATH);
#ifndef SOC_J721E
BufPool *histogram_buf_pool = NULL;
Buf *histogram_buf = NULL;
char output_distribution_name[100];
sprintf(output_distribution_name, "%s/output/imx219_1920x1080_capture_distribution.bin", EDGEAI_DATA_PATH);
#endif

tiovx_viss_init_cfg(&cfg);

sprintf(cfg.sensor_name, SENSOR_NAME);
snprintf(cfg.dcc_config_file, TIVX_FILEIO_FILE_PATH_LENGTH, "%s", DCC_VISS);
cfg.width = INPUT_WIDTH;
cfg.height = INPUT_HEIGHT;
#ifndef SOC_J721E
cfg.enable_histogram_pad = vx_true_e;
#endif
sprintf(cfg.target_string, TIVX_TARGET_VPAC_VISS1);

cfg.input_cfg.params.format[0].pixel_container = TIVX_RAW_IMAGE_8_BIT;
Expand All @@ -108,20 +117,32 @@ vx_status app_modules_viss_test(vx_int32 argc, vx_char* argv[])
tiovx_modules_enqueue_buf(inbuf);

out_buf_pool = node->srcs[0].buf_pool;
outbuf = tiovx_modules_acquire_buf(out_buf_pool);
tiovx_modules_enqueue_buf(outbuf);
out_buf = tiovx_modules_acquire_buf(out_buf_pool);
tiovx_modules_enqueue_buf(out_buf);
#ifndef SOC_J721E
histogram_buf_pool = node->srcs[1].buf_pool;
histogram_buf = tiovx_modules_acquire_buf(histogram_buf_pool);
tiovx_modules_enqueue_buf(histogram_buf);
#endif

tiovx_modules_schedule_graph(&graph);
tiovx_modules_wait_graph(&graph);

inbuf = tiovx_modules_dequeue_buf(in_buf_pool);
outbuf = tiovx_modules_dequeue_buf(out_buf_pool);

writeImage(output_filename, (vx_image)outbuf->handle);

out_buf = tiovx_modules_dequeue_buf(out_buf_pool);
#ifndef SOC_J721E
histogram_buf = tiovx_modules_dequeue_buf(histogram_buf_pool);
#endif

writeImage(output_filename, (vx_image)out_buf->handle);
#ifndef SOC_J721E
writeDistribution(output_distribution_name, (vx_distribution)histogram_buf->handle);
#endif
tiovx_modules_release_buf(inbuf);
tiovx_modules_release_buf(outbuf);

tiovx_modules_release_buf(out_buf);
#ifndef SOC_J721E
tiovx_modules_release_buf(histogram_buf);
#endif
tiovx_modules_clean_graph(&graph);

return status;
Expand Down
1 change: 1 addition & 0 deletions utils/include/tiovx_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extern char *EDGEAI_DATA_PATH;

vx_status readImage(char* file_name, vx_image img);
vx_status writeImage(char* file_name, vx_image img);
vx_status writeDistribution(char* file_name, vx_distribution dist);
vx_status resetImage(vx_image img, int32_t value);

vx_status readRawImage(char* file_name, tivx_raw_image img, vx_uint32 *bytes_read);
Expand Down
42 changes: 42 additions & 0 deletions utils/src/tiovx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,48 @@ vx_status readImage(char* file_name, vx_image img)
return(status);
}

vx_status writeDistribution(char* file_name, vx_distribution dist)
{
vx_status status;

status = vxGetStatus((vx_reference)dist);

if((vx_status)VX_SUCCESS == status)
{
FILE * fp = fopen(file_name,"wb");

if(fp == NULL)
{
TIOVX_MODULE_ERROR("Unable to open file %s \n", file_name);
return (VX_FAILURE);
}

{
void *data_ptr;
vx_map_id map_id;
vx_size num_dist;
vx_size dist_size;

vxQueryDistribution(dist, VX_DISTRIBUTION_BINS, &num_dist, sizeof(vx_size));
vxQueryDistribution(dist, VX_DISTRIBUTION_SIZE, &dist_size, sizeof(vx_size));

status = vxMapDistribution(dist,
&map_id,
&data_ptr,
VX_READ_ONLY,
VX_MEMORY_TYPE_HOST,
0);

fwrite(data_ptr, dist_size/num_dist, num_dist, fp);
status = vxUnmapDistribution(dist, map_id);
}

fclose(fp);
}

return(status);
}

vx_status writeImage(char* file_name, vx_image img)
{
vx_status status;
Expand Down

0 comments on commit c9673db

Please sign in to comment.