In custom filter examples, remove tensor-common header.
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
#include <errno.h>
#include <math.h>
#include <tensor_filter_custom.h>
-#include <tensor_common.h>
#define TSIZE (4)
#include <string.h>
#include <errno.h>
#include <tensor_filter_custom.h>
-/* To use nnstreamer utilities (not mandatory for custom filters */
-#include <tensor_common.h>
#define TSIZE (4)
* @author Sangjung Woo <sangjung.woo@samsung.com>
* @bug No known bugs
* @see nnstreamer_customfilter_example_average.c
- *
- * This example calculates the average value of input tensor for
+ *
+ * This example calculates the average value of input tensor for
* each channel (i.e. R, G & B). The shape of the input tensor is
- * [N][y][x][M] and that of the output tensor is [N][1][1][M].
+ * [N][y][x][M] and that of the output tensor is [N][1][1][M].
*/
#include <opencv2/opencv.hpp>
#include <glib.h>
#include <tensor_filter_custom.h>
-#include <tensor_common.h>
/**
* @brief _pt_data Internal data structure
} pt_data;
/**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+ size_t data_size = 0;
+ int i;
+
+ if (info != NULL) {
+ data_size = tensor_element_size[info->type];
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ data_size *= info->dimension[i];
+ }
+ }
+
+ return data_size;
+}
+
+/**
* @brief pt_init
*/
static void *
std::vector<cv::Mat> channels;
cv::Scalar mean_result;
void *buffer;
-
+
g_assert (pdata);
g_assert (input);
g_assert (output);
- in_size = gst_tensor_info_get_size (&prop->input_meta.info[0]);
+ in_size = get_tensor_data_size (&prop->input_meta.info[0]);
buffer = g_malloc (in_size);
/* Get Mat object from input tensor */
/**
* NNStreamer OpenCV Custom Filter Example: Scaler
- *
+ *
* Copyright (C) 2018 Sangjung Woo <sangjung.woo@samsung.com>
*
* LICENSE: LGPL-2.1
* @author Sangjung Woo <sangjung.woo@samsung.com>
* @bug No known bugs
* @see nnstreamer_customfilter_example_scaler_allocator.c
- *
- * This example scales an input tensor of [N][input_h][input_w][M]
+ *
+ * This example scales an input tensor of [N][input_h][input_w][M]
* to an ouput tensor of [N][output_h][output_w][M].
*
* The custom property is to be given as, "custom=[new-x]x[new-y]", where new-x and new-y are unsigned integers.
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
-#include <cassert>
#include <glib.h>
#include <tensor_filter_custom.h>
-#include <tensor_common.h>
/**
* @brief Private data structure
} pt_data;
/**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+ size_t data_size = 0;
+ int i;
+
+ if (info != NULL) {
+ data_size = tensor_element_size[info->type];
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ data_size *= info->dimension[i];
+ }
+ }
+
+ return data_size;
+}
+
+/**
* @brief init callback of tensor_filter custom
*/
static void *
pt_exit (void *private_data, const GstTensorFilterProperties * prop)
{
pt_data *pdata = static_cast<pt_data *> (private_data);
- assert (pdata);
+ g_assert (pdata);
g_free (pdata);
}
{
pt_data *pdata = static_cast<pt_data *> (private_data);
- assert (pdata);
- assert (in_info);
- assert (out_info);
+ g_assert (pdata);
+ g_assert (in_info);
+ g_assert (out_info);
out_info->num_tensors = 1;
void* buffer;
cv::Mat img_src, img_dst;
- assert (pdata);
- assert (input);
- assert (output);
+ g_assert (pdata);
+ g_assert (input);
+ g_assert (output);
- in_size = gst_tensor_info_get_size (&prop->input_meta.info[0]);
- out_size = gst_tensor_info_get_size (&prop->output_meta.info[0]);
+ in_size = get_tensor_data_size (&prop->input_meta.info[0]);
+ out_size = get_tensor_data_size (&prop->output_meta.info[0]);
buffer = g_malloc (in_size);
output[0].data = g_malloc (out_size);
/* Scale from the shape of input tensor to that of output tensor
* which is given as custom property */
- cv::resize (img_src, img_dst, cv::Size(pdata->out_width, pdata->out_height),
+ cv::resize (img_src, img_dst, cv::Size(pdata->out_width, pdata->out_height),
0, 0, CV_INTER_NN);
/* Convert Mat object to output tensor */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include <tensor_filter_custom.h>
-#include <tensor_common.h>
#define D1 (3)
#define D2 (280)
} pt_data;
/**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+ size_t data_size = 0;
+ int i;
+
+ if (info != NULL) {
+ data_size = tensor_element_size[info->type];
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ data_size *= info->dimension[i];
+ }
+ }
+
+ return data_size;
+}
+
+/**
* @brief _pt_data
*/
static void *
pt_exit (void *private_data, const GstTensorFilterProperties * prop)
{
pt_data *data = private_data;
- g_assert (data);
+ assert (data);
free (data);
}
{
pt_data *data = private_data;
- g_assert (data);
- g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
+ assert (data);
+ assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 1;
info->info[0] = data->info;
{
pt_data *data = private_data;
- g_assert (data);
- g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
+ assert (data);
+ assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 1;
info->info[0] = data->info;
pt_data *data = private_data;
size_t size;
- g_assert (data);
- g_assert (input);
- g_assert (output);
+ assert (data);
+ assert (input);
+ assert (output);
- size = gst_tensor_info_get_size (&data->info);
+ size = get_tensor_data_size (&data->info);
- g_assert (input[0].data != output[0].data);
+ assert (input[0].data != output[0].data);
memcpy (output[0].data, input[0].data, size);
return 0;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include <tensor_filter_custom.h>
-#include <tensor_common.h>
/**
* @brief _pt_data
} pt_data;
/**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+ size_t data_size = 0;
+ int i;
+
+ if (info != NULL) {
+ data_size = tensor_element_size[info->type];
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ data_size *= info->dimension[i];
+ }
+ }
+
+ return data_size;
+}
+
+/**
* @brief pt_init
*/
static void *
pt_init (const GstTensorFilterProperties * prop)
{
pt_data *data = (pt_data *) malloc (sizeof (pt_data));
- g_assert (data);
+ assert (data);
data->id = 0;
return data;
pt_exit (void *private_data, const GstTensorFilterProperties * prop)
{
pt_data *data = private_data;
- g_assert (data);
+ assert (data);
free (data);
}
{
int i, t;
- g_assert (in_info);
- g_assert (out_info);
+ assert (in_info);
+ assert (out_info);
out_info->num_tensors = in_info->num_tensors;
size_t size;
int t;
- g_assert (data);
- g_assert (input);
- g_assert (output);
+ assert (data);
+ assert (input);
+ assert (output);
for (t = 0; t < prop->output_meta.num_tensors; t++) {
- size = gst_tensor_info_get_size (&prop->output_meta.info[t]);
+ size = get_tensor_data_size (&prop->output_meta.info[t]);
- g_assert (input[t].data != output[t].data);
+ assert (input[t].data != output[t].data);
memcpy (output[t].data, input[t].data, size);
}
#include <assert.h>
#include <glib.h>
#include <tensor_filter_custom.h>
-#include <tensor_common.h>
/**
* @brief Private data structure
}
/**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+ size_t data_size = 0;
+ int i;
+
+ if (info != NULL) {
+ data_size = tensor_element_size[info->type];
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ data_size *= info->dimension[i];
+ }
+ }
+
+ return data_size;
+}
+
+/**
* @brief init callback of tensor_filter custom
*/
static void *
/* allocate output data */
elementsize = tensor_element_size[prop->output_meta.info[0].type];
- size = gst_tensor_info_get_size (&prop->output_meta.info[0]);
+ size = get_tensor_data_size (&prop->output_meta.info[0]);
output[0].data = malloc (size);