blob: 179eb15f06b43a6287adb64879f66c1d0cc8a3bc [file] [log] [blame]
/*
* Copyright (c) 2012-2017 The Khronos Group Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined OPENVX_USE_ENHANCED_VISION || OPENVX_CONFORMANCE_VISION
#include "test_engine/test.h"
#include <VX/vx.h>
#include <VX/vxu.h>
TESTCASE(Integral, CT_VXContext, ct_setup_vx_context, 0)
TEST(Integral, testNodeCreation)
{
vx_context context = context_->vx_context_;
vx_image src_image = 0, dst_image = 0;
vx_graph graph = 0;
vx_node node = 0;
ASSERT_VX_OBJECT(src_image = vxCreateImage(context, 128, 128, VX_DF_IMAGE_U8), VX_TYPE_IMAGE);
ASSERT_VX_OBJECT(dst_image = vxCreateImage(context, 128, 128, VX_DF_IMAGE_U32), VX_TYPE_IMAGE);
ASSERT_VX_OBJECT(graph = vxCreateGraph(context), VX_TYPE_GRAPH);
ASSERT_VX_OBJECT(node = vxIntegralImageNode(graph, src_image, dst_image), VX_TYPE_NODE);
VX_CALL(vxReleaseNode(&node));
VX_CALL(vxReleaseGraph(&graph));
VX_CALL(vxReleaseImage(&dst_image));
VX_CALL(vxReleaseImage(&src_image));
ASSERT(node == 0);
ASSERT(graph == 0);
ASSERT(dst_image == 0);
ASSERT(src_image == 0);
}
static CT_Image integral_generate_random(const char* fileName, int width, int height)
{
CT_Image image;
ASSERT_NO_FAILURE_(return 0,
image = ct_allocate_ct_image_random(width, height, VX_DF_IMAGE_U8, &CT()->seed_, 0, 256));
return image;
}
static CT_Image integral_read_image(const char* fileName, int width, int height)
{
CT_Image image = NULL;
ASSERT_(return 0, width == 0 && height == 0);
image = ct_read_image(fileName, 1);
ASSERT_(return 0, image);
ASSERT_(return 0, image->format == VX_DF_IMAGE_U8);
return image;
}
static CT_Image integral_create_reference_image(CT_Image src)
{
CT_Image dst;
CT_ASSERT_(return NULL, src->format == VX_DF_IMAGE_U8);
dst = ct_allocate_image(src->width, src->height, VX_DF_IMAGE_U32);
CT_FILL_IMAGE_32U(return 0, dst,
{
uint32_t res = *CT_IMAGE_DATA_PTR_8U(src, x, y);
if (y > 0)
res += *CT_IMAGE_DATA_PTR_32U(dst, x, y - 1);
if (x > 0)
res += *CT_IMAGE_DATA_PTR_32U(dst, x - 1, y);
if (y > 0 && x > 0)
res -= *CT_IMAGE_DATA_PTR_32U(dst, x - 1, y - 1);
*dst_data = res;
});
return dst;
}
static void integral_check(CT_Image src, CT_Image dst)
{
CT_Image dst_ref = NULL;
ASSERT(src && dst);
ASSERT_NO_FAILURE(dst_ref = integral_create_reference_image(src));
EXPECT_EQ_CTIMAGE(dst_ref, dst);
#if 0
if (CT_HasFailure())
{
printf("=== SRC ===\n");
ct_dump_image_info_ex(src, 16, 4);
printf("=== DST ===\n");
ct_dump_image_info_ex(dst, 16, 4);
printf("=== EXPECTED ===\n");
ct_dump_image_info_ex(dst_ref, 16, 4);
}
#endif
}
typedef struct {
const char* testName;
CT_Image (*generator)(const char* fileName, int width, int height);
const char* fileName;
int width, height;
} Arg;
#define PARAMETERS \
CT_GENERATE_PARAMETERS("randomInput", ADD_SIZE_SMALL_SET, ARG, integral_generate_random, NULL), \
CT_GENERATE_PARAMETERS("lena", ADD_SIZE_NONE, ARG, integral_read_image, "lena.bmp")
TEST_WITH_ARG(Integral, testGraphProcessing, Arg,
PARAMETERS
)
{
vx_context context = context_->vx_context_;
vx_image src_image = 0, dst_image = 0;
vx_graph graph = 0;
vx_node node = 0;
CT_Image src = NULL, dst = NULL;
ASSERT_NO_FAILURE(src = arg_->generator(arg_->fileName, arg_->width, arg_->height));
ASSERT_VX_OBJECT(src_image = ct_image_to_vx_image(src, context), VX_TYPE_IMAGE);
ASSERT_VX_OBJECT(dst_image = vxCreateImage(context, src->width, src->height, VX_DF_IMAGE_U32), VX_TYPE_IMAGE);
ASSERT_VX_OBJECT(graph = vxCreateGraph(context), VX_TYPE_GRAPH);
ASSERT_VX_OBJECT(node = vxIntegralImageNode(graph, src_image, dst_image), VX_TYPE_NODE);
VX_CALL(vxVerifyGraph(graph));
VX_CALL(vxProcessGraph(graph));
ASSERT_NO_FAILURE(dst = ct_image_from_vx_image(dst_image));
ASSERT_NO_FAILURE(integral_check(src, dst));
VX_CALL(vxReleaseNode(&node));
VX_CALL(vxReleaseGraph(&graph));
ASSERT(node == 0);
ASSERT(graph == 0);
VX_CALL(vxReleaseImage(&dst_image));
VX_CALL(vxReleaseImage(&src_image));
ASSERT(dst_image == 0);
ASSERT(src_image == 0);
}
TEST_WITH_ARG(Integral, testImmediateProcessing, Arg,
PARAMETERS
)
{
vx_context context = context_->vx_context_;
vx_image src_image = 0, dst_image = 0;
CT_Image src = NULL, dst = NULL;
ASSERT_NO_FAILURE(src = arg_->generator(arg_->fileName, arg_->width, arg_->height));
ASSERT_VX_OBJECT(src_image = ct_image_to_vx_image(src, context), VX_TYPE_IMAGE);
ASSERT_VX_OBJECT(dst_image = vxCreateImage(context, src->width, src->height, VX_DF_IMAGE_U32), VX_TYPE_IMAGE);
VX_CALL(vxuIntegralImage(context, src_image, dst_image));
ASSERT_NO_FAILURE(dst = ct_image_from_vx_image(dst_image));
ASSERT_NO_FAILURE(integral_check(src, dst));
VX_CALL(vxReleaseImage(&dst_image));
VX_CALL(vxReleaseImage(&src_image));
ASSERT(dst_image == 0);
ASSERT(src_image == 0);
}
TESTCASE_TESTS(Integral, testNodeCreation, testGraphProcessing, testImmediateProcessing)
#endif //OPENVX_USE_ENHANCED_VISION || OPENVX_CONFORMANCE_VISION