Skip to content

Commit

Permalink
add separate api and private/unit test executables
Browse files Browse the repository at this point in the history
Related: #94

We need a separate executables for:
(1) the public (possibly shared) ACF api
(2) the private support class/functions used internally in ACF that require focused testing

* add SIMD channel conversion code to ACF (imgrated from drishti) and to private unit test
* move optimized separable triangle filter shader test to private unit test
* extract ogles_gpgpu::ACF::getImage() texture read code to acf/transfer.{h,cpp} as stand-alone functions for easier reuse (without require compilatino of GPUACF.{h,cpp}
* collect private unit test sources with sugar in ACF_TEST_SRCS variable and build into the acf unit test executable
  • Loading branch information
headupinclouds committed Jun 12, 2018
1 parent 47f1ed1 commit ab42668
Show file tree
Hide file tree
Showing 14 changed files with 1,059 additions and 82 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ if((ACF_BUILD_TESTS OR ACF_BUILD_EXAMPLES) AND ACF_HAS_GPU AND ACF_BUILD_OGLES_G
endif()

hunter_add_package(sugar)
find_package(sugar CONFIG REQUIRED)

# Include sources from here so they will be visible for tests
sugar_include(.)
add_subdirectory(lib)

##################
Expand Down
11 changes: 8 additions & 3 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#
# Note that requirements propagated automatically, for example:

find_package(sugar CONFIG REQUIRED)
sugar_include(.)

### acf_shaders ### : for acf lib and tests
if(ACF_BUILD_OGLES_GPGPU)
add_library(acf_shaders ${ACF_GPU_SRCS} ${ACF_GPU_HDRS})
Expand Down Expand Up @@ -47,6 +44,14 @@ endif()
target_include_directories(acf
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>" # generated acf_export.h
)

# Create a convenience INTERFACE lib for testing
add_library(acf_headers INTERFACE)
target_include_directories(acf_headers
INTERFACE
"$<BUILD_INTERFACE:${ACF_ROOT_DIR}/src/lib/acf>" # for io, acf
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>" # generated acf_export.h
)

foreach(lib acf ${acf_modules})
Expand Down
24 changes: 1 addition & 23 deletions src/lib/acf/acf/GPUACF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <acf/ACF.h>
#include <acf/MatP.h>
#include <acf/convert.h>
#include <acf/transfer.h>

#include <util/make_unique.h>

Expand Down Expand Up @@ -536,29 +537,6 @@ void ACF::postConfig()
}
}

cv::Mat ACF::getImage(ProcInterface& proc, cv::Mat& frame)
{
if (dynamic_cast<MemTransferOptimized*>(proc.getMemTransferObj()))
{
MemTransfer::FrameDelegate delegate = [&](const Size2d& size, const void* pixels, size_t bytesPerRow) {
frame = cv::Mat(size.height, size.width, CV_8UC4, const_cast<void*>(pixels), bytesPerRow).clone();
};
proc.getResultData(delegate);
}
else
{
frame.create(proc.getOutFrameH(), proc.getOutFrameW(), CV_8UC4); // noop if preallocated
proc.getResultData(frame.ptr());
}
return frame;
}

cv::Mat ACF::getImage(ProcInterface& proc)
{
cv::Mat frame;
return getImage(proc, frame);
}

bool ACF::processImage(ProcInterface& proc, MemTransfer::FrameDelegate& delegate)
{
bool status = false;
Expand Down
4 changes: 1 addition & 3 deletions src/lib/acf/acf/GPUACF.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <acf/ACF.h>
#include <acf/acf_common.h>
#include <acf/acf_export.h>
#include <ogles_gpgpu/common/proc/../gl/memtransfer.h>
#include <ogles_gpgpu/common/gl/memtransfer.h>
#include <ogles_gpgpu/common/common_includes.h>
// ogles_gpgpu shader lib:
#include <ogles_gpgpu/common/proc/video.h>
Expand Down Expand Up @@ -76,8 +76,6 @@ struct ACF_EXPORT ACF : public ogles_gpgpu::VideoSource

void preConfig() override;
void postConfig() override;
static cv::Mat getImage(ProcInterface& proc);
static cv::Mat getImage(ProcInterface& proc, cv::Mat& frame);

virtual void operator()(const FrameInput& frame);

Expand Down
1 change: 0 additions & 1 deletion src/lib/acf/acf/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <opencv2/core/mat.hpp>
#include <opencv2/core/mat.inl.hpp>


ACF_NAMESPACE_BEGIN

struct PlaneInfo
Expand Down
19 changes: 19 additions & 0 deletions src/lib/acf/acf/sugar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sugar_files(ACF_SRCS
gradientHist.cpp
gradientMag.cpp
rgbConvert.cpp
transfer.cpp
#######################
### Toolbox sources ###
#######################
Expand All @@ -44,6 +45,7 @@ sugar_files(ACF_HDRS
ACFObject.h
ObjectDetector.h
random.h
transfer.h
#######################
### Toolbox headers ###
#######################
Expand All @@ -60,6 +62,12 @@ sugar_files(ACF_HDRS_PUBLIC
draw.h
)

# Collect sources for testing
sugar_files(ACF_TEST_SRCS
convert.cpp
convert.h
)

if(ACF_BUILD_OGLES_GPGPU)
# Public GPUACF classes added to the main library
sugar_files(ACF_HDRS_PUBLIC GPUACF.h)
Expand All @@ -85,4 +93,15 @@ if(ACF_BUILD_OGLES_GPGPU)
gpu/triangle_opt.cpp
gpu/binomial.cpp
)

# Collect private unit test sources
sugar_Files(ACF_TEST_SRCS
transfer.cpp
transfer.h
gpu/triangle_opt.h
gpu/triangle_opt.cpp
gpu/multipass/triangle_opt_pass.h
gpu/multipass/triangle_opt_pass.cpp
)

endif()
41 changes: 41 additions & 0 deletions src/lib/acf/acf/transfer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*! -*-c++-*-
@file transfer.cpp
@author David Hirvonen
@brief Implementation of gpu->cpu transfer routines.
\copyright Copyright 2018 Elucideye, Inc. All rights reserved.
\license{This project is released under the 3 Clause BSD License.}
*/

#include <acf/transfer.h>
#include <ogles_gpgpu/common/gl/memtransfer_optimized.h>
#include <ogles_gpgpu/common/proc/base/procinterface.h>

BEGIN_OGLES_GPGPU

cv::Mat getImage(ProcInterface& proc, cv::Mat& frame)
{
if (dynamic_cast<MemTransferOptimized*>(proc.getMemTransferObj()))
{
MemTransfer::FrameDelegate delegate = [&](const Size2d& size, const void* pixels, size_t bytesPerRow) {
frame = cv::Mat(size.height, size.width, CV_8UC4, const_cast<void*>(pixels), bytesPerRow).clone();
};
proc.getResultData(delegate);
}
else
{
frame.create(proc.getOutFrameH(), proc.getOutFrameW(), CV_8UC4); // noop if preallocated
proc.getResultData(frame.ptr());
}
return frame;
}

cv::Mat getImage(ProcInterface& proc)
{
cv::Mat frame;
return getImage(proc, frame);
}

END_OGLES_GPGPU

25 changes: 25 additions & 0 deletions src/lib/acf/acf/transfer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*! -*-c++-*-
@file transfer.h
@author David Hirvonen
@brief Declaration of gpu->cpu transfer routines.
\copyright Copyright 2018 Elucideye, Inc. All rights reserved.
\license{This project is released under the 3 Clause BSD License.}
*/

#ifndef __acf_transfer_h__
#define __acf_transfer_h__

#include <opencv2/core.hpp>
#include <ogles_gpgpu/common/proc/base/procinterface.h>

BEGIN_OGLES_GPGPU

cv::Mat getImage(ProcInterface& proc);
cv::Mat getImage(ProcInterface& proc, cv::Mat& frame);

END_OGLES_GPGPU

#endif // __acf_transfer_h__

37 changes: 0 additions & 37 deletions src/lib/acf/acf/ut/CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/sugar.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sugar_include(lib)
50 changes: 39 additions & 11 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# Copyright (c) 2015-2017, Ruslan Baratov, David Hirvonen
# All rights reserved.

set(test_name ACFTest)
set(test_app test-acf)
################
### api test ### : STATIC or SHARED w/ hidden symbols
################

set(acf_ut_srcs test-acf.cpp)
set(test_api_name ACFTest_api)
set(test_api_app test-acf-api)

add_executable(${test_app} ${acf_ut_srcs})
set_property(TARGET ${test_app} PROPERTY FOLDER "app/tests")
target_link_libraries(${test_app} PUBLIC acf::acf acf_common acf_shaders GTest::gtest ${OpenCV_LIBS})
set(acf_ut_srcs test-acf-api.cpp)

add_executable(${test_api_app} ${acf_ut_srcs})
set_property(TARGET ${test_api_app} PROPERTY FOLDER "app/tests")
target_link_libraries(${test_api_app} PUBLIC acf::acf acf_common GTest::gtest ${OpenCV_LIBS})

if (ACF_BUILD_OGLES_GPGPU AND TARGET aglet::aglet)
target_link_libraries(${test_app} PUBLIC aglet::aglet)
target_compile_definitions(${test_app} PUBLIC ACF_DO_GPU=1)
target_link_libraries(${test_api_app} PUBLIC aglet::aglet)
target_compile_definitions(${test_api_app} PUBLIC ACF_DO_GPU=1)
endif()

# GTest + CTest
gauze_add_test(
NAME ${test_name}
COMMAND ${test_app}
NAME ${test_api_name}
COMMAND ${test_api_app}
"$<GAUZE_RESOURCE_FILE:${DRISHTI_FACES_FACE_IMAGE}>"
"$<GAUZE_RESOURCE_FILE:${DRISHTI_FACES_FACE_IMAGE}>"
"$<GAUZE_RESOURCE_FILE:${DRISHTI_ASSETS_FACE_DETECTOR}>"
Expand All @@ -29,9 +33,33 @@ gauze_add_test(

if(WIN32 OR CYGWIN)
set_property(
TEST ${test_name}
TEST ${test_api_name}
PROPERTY
ENVIRONMENT
"PATH=$<TARGET_FILE_DIR:acf>;$ENV{PATH}"
)
endif()

#################
### unit test ### : this will always use static linking
#################

set(test_unit_name ACFTest_unit)
set(test_unit_app test-acf-unit)

set(acf_ut_srcs test-acf-unit.cpp ${ACF_TEST_SRCS})

add_executable(${test_unit_app} ${acf_ut_srcs})
set_property(TARGET ${test_unit_app} PROPERTY FOLDER "app/tests")
target_link_libraries(${test_unit_app} PUBLIC acf_headers acf_common GTest::gtest ${OpenCV_LIBS})

if (ACF_BUILD_OGLES_GPGPU AND TARGET aglet::aglet)
target_link_libraries(${test_unit_app} PUBLIC aglet::aglet ogles_gpgpu::ogles_gpgpu)
target_compile_definitions(${test_unit_app} PUBLIC ACF_DO_GPU=1)
endif()

# GTest + CTest
gauze_add_test(
NAME ${test_unit_name}
COMMAND ${test_unit_app}
)

0 comments on commit ab42668

Please sign in to comment.