Skip to content

Commit

Permalink
Merge branch 'enh-pursue-chessboard-detection' into 'master'
Browse files Browse the repository at this point in the history
ENH: improvements in the chessboard corner detection and memory leak fixes.

See merge request DO-CV/sara!398
  • Loading branch information
Odd Kiva committed Aug 1, 2022
2 parents cd1a9cc + 3d66cd8 commit 3a6876a
Show file tree
Hide file tree
Showing 61 changed files with 2,609 additions and 1,381 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ set(BUILD_SHARED_LIBS ${SARA_BUILD_SHARED_LIBS})
# Add Sara to the CMake module path.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(sara_create_asan_build_type)

# Import macros and configure Sara library version.
include(sara_macros)
sara_dissect_version()
Expand Down
9 changes: 0 additions & 9 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
OPENGL
======
- Learn how to use framebuffer for texture streaming.

VULKAN
======
- Hello Triangle tutorial.


Autocalibration with radial distortion
======================================
Reimplement Fitzgibbon's approach (fundamental matrix with one radial distortion
coefficients).

Bundle Adjustment Tests
=======================

Expand Down
16 changes: 8 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ function build_library()

# Use latest Qt version instead of the system Qt.
#
# TODO: migrate to Qt6.
# if [ "${platform_name}" == "Linux" ]; then
# cmake_options+="-DQt5_DIR=${HOME}/opt/Qt-5.15.0-amd64/lib/cmake/Qt5 "
if [ "${platform_name}" == "Darwin" ]; then
cmake_options+="-DSARA_USE_QT6:BOOL=ON "
cmake_options+="-DSARA_USE_QT6:BOOL=ON "
if [ "${platform_name}" == "Linux" ]; then
my_cmake_prefix_paths="/usr/local/Qt-6.3.1"
elif [ "${platform_name}" == "Darwin" ]; then
cmake_options+="-DQt6_DIR=$(brew --prefix qt)/lib/cmake/Qt6 "
fi

Expand All @@ -107,9 +106,8 @@ function build_library()
# Compile Halide code.
cmake_options+="-DSARA_USE_HALIDE:BOOL=ON "
if [ "${platform_name}" == "Linux" ]; then
cmake_options+="-DCMAKE_PREFIX_PATH=$HOME/opt/Halide-13.0.0-x86-64-linux "
fi
if [ "${platform_name}" == "Darwin" ]; then
my_cmake_prefix_paths="${my_cmake_prefix_paths};$HOME/opt/Halide-14.0.0-x86-64-linux"
elif [ "${platform_name}" == "Darwin" ]; then
cmake_options+="-DLLVM_DIR=$(brew --prefix llvm)/lib/cmake/llvm "
fi

Expand All @@ -118,6 +116,8 @@ function build_library()
cmake_options+="-DNvidiaVideoCodec_ROOT=${HOME}/opt/Video_Codec_SDK_11.0.10 "
fi

cmake_options+="-DCMAKE_PREFIX_PATH=${my_cmake_prefix_paths} "

# Use OpenCV tools
cmake_options+="-DSARA_USE_OPENCV:BOOL=ON"

Expand Down
18 changes: 18 additions & 0 deletions cmake/asan_suppressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The address sanitizer has problem with OpenCL.
#
# This is documented in:
# - https://github.com/ddemidov/vexcl/issues/204
# In particular, it complains `clGetPlatformIDs`.

# Turn off complaints related to Swift bindings.
leak:Foundation

# Qt
#
# On NVIDIA platforms, there seems to be memory leaks related to OpenGL...
# Maybe it is related to this:
# https://forums.developer.nvidia.com/t/possible-memory-leak-in-the-510-60-linux-driver/214123
#
# Luckily the memory leak does not show up on the GitLab CI.
leak:dbus
leak:nvidia-glcore
6 changes: 1 addition & 5 deletions cmake/sara_configure_cxx_compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (UNIX)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
# Additional flags for Debug builds to code coverage.
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DDEBUG -D_DEBUG -fno-inline")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG")
if (NOT APPLE)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
Expand All @@ -48,10 +48,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fexceptions)

# Silence Eigen compile warnings.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy-with-user-provided-copy")

# Additional flags for Release builds.
set(CMAKE_CXX_FLAGS_RELEASE -O3)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO -O2)
Expand Down
41 changes: 41 additions & 0 deletions cmake/sara_create_asan_build_type.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# From: https://stackoverflow.com/questions/44320465/whats-the-proper-way-to-enable-addresssanitizer-in-cmake-that-works-in-xcode

get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)

if(isMultiConfig)
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
endif()
else()
set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")

if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()

set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS_DEBUG} -O0 -g -fsanitize=address -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C compiler for Asan build type or configuration."
FORCE)

set(CMAKE_CXX_FLAGS_ASAN
"${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -DDEBUG -D_DEBUG -fsanitize=address -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C++ compiler for Asan build type or configuration."
FORCE)

set(CMAKE_EXE_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address"
CACHE STRING
"Linker flags to be used to create executables for Asan build type."
FORCE)

set(CMAKE_SHARED_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address"
CACHE
STRING
"Linker lags to be used to create shared libraries for Asan build type."
FORCE)
10 changes: 5 additions & 5 deletions cpp/drafts/OpenCL/Core/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace DO::Sara {
class Context
{
public:
Context(const Device& device)
inline Context(const Device& device)
{
auto err = cl_int{};
_context =
Expand All @@ -42,22 +42,22 @@ namespace DO::Sara {
sizeof(_ref_count), &_ref_count, nullptr);
}

~Context()
inline ~Context()
{
auto err = clReleaseContext(_context);
if (err < 0)
std::cerr << format("Error: failed to release OpenCL program! %s\n",
std::cerr << format("Error: failed to release OpenCL context! %s\n",
get_error_string(err))
<< std::endl;
}

operator cl_context() const
inline operator cl_context() const
{
return _context;
}

template <typename T>
void push_property(cl_uint key, T value)
inline void push_property(cl_uint key, T value)
{
_properties.push_back(key);
_properties.push_back(reinterpret_cast<cl_context_properties>(value));
Expand Down
26 changes: 14 additions & 12 deletions cpp/drafts/OpenCL/Core/DeviceBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,44 @@ namespace DO::Sara {
class DeviceBuffer
{
public:
DeviceBuffer() = default;
inline DeviceBuffer() = default;

DeviceBuffer(Context& context, T* data, size_t size,
cl_mem_flags flags = CL_MEM_READ_WRITE)
inline DeviceBuffer(Context& context, T* data, size_t size,
cl_mem_flags flags = CL_MEM_READ_WRITE)
: _data(data)
, _size(size)
, _buffer(nullptr)
{
auto err = cl_int{};
_buffer = clCreateBuffer(context, flags, size * sizeof(T), _data, &err);
if (err < 0)
if (err != CL_SUCCESS)
throw std::runtime_error(
format("Error: failed to allocate buffer in device memory! %s\n",
get_error_string(err)));
}

~DeviceBuffer()
inline ~DeviceBuffer()
{
auto err = clReleaseMemObject(_buffer);
if (err < 0)
std::cerr << format("Error: failed to release buffer in device memory! %s",
get_error_string(err)) << std::endl;
const auto err = clReleaseMemObject(_buffer);
if (err != CL_SUCCESS)
std::cerr << format(
"Error: failed to release buffer in device memory! %s",
get_error_string(err))
<< std::endl;
}

operator cl_mem&()
inline operator cl_mem&()
{
return _buffer;
}

size_t size() const
inline size_t size() const
{
return _size;
}

private:
T *_data = nullptr;
T* _data = nullptr;
size_t _size = 0;
cl_mem _buffer = nullptr;
};
Expand Down
44 changes: 24 additions & 20 deletions cpp/drafts/OpenCL/Core/Platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <vector>



namespace DO::Sara {

//! @addtogroup OpenCL
Expand All @@ -38,63 +37,68 @@ namespace DO::Sara {
std::string profile;
std::string extensions;

friend inline std::ostream& operator<<(std::ostream& os, const Platform& p)
friend inline auto operator<<(std::ostream& os, const Platform& p)
-> std::ostream&
{
const auto length = static_cast<int>(std::string("Extensions ").size());
using std::left;
using std::setw;
os << left << setw(length) << "ID" << ": " << p.id << "\n";
os << left << setw(length) << "Name" << ": " << p.name << "\n";
os << left << setw(length) << "Vendor" << ": " << p.vendor << "\n";
os << left << setw(length) << "Version" << ": " << p.version << "\n";
os << left << setw(length) << "Profile" << ": " << p.profile << "\n";
os << left << setw(length) << "Extensions" << ": " << p.extensions << "\n";
os << left << setw(length) << "ID"
<< ": " << p.id << "\n";
os << left << setw(length) << "Name"
<< ": " << p.name << "\n";
os << left << setw(length) << "Vendor"
<< ": " << p.vendor << "\n";
os << left << setw(length) << "Version"
<< ": " << p.version << "\n";
os << left << setw(length) << "Profile"
<< ": " << p.profile << "\n";
os << left << setw(length) << "Extensions"
<< ": " << p.extensions << "\n";
return os;
}
};

//! @brief Read the OpenCL platform.
template <int _InfoType>
std::string get_platform_info(cl_platform_id platform_id)
inline auto get_platform_info(cl_platform_id platform_id) -> std::string
{
cl_int err;

size_t buffer_length;
err = clGetPlatformInfo(platform_id, _InfoType, 0, nullptr, &buffer_length);
if (err < 0)
throw std::runtime_error(format(
"Error: cannot get platform info! %s",
get_error_string(err)));
throw std::runtime_error(
format("Error: cannot get platform info! %s", get_error_string(err)));

std::vector<char> buffer;
buffer.resize(buffer_length);
err = clGetPlatformInfo(platform_id, _InfoType, buffer_length, &buffer[0],
nullptr);
if (err < 0)
throw std::runtime_error(format(
"Error: cannot get platform info! %s",
get_error_string(err)));
throw std::runtime_error(
format("Error: cannot get platform info! %s", get_error_string(err)));

return std::string(buffer.begin(), buffer.end());
}


std::vector<Platform> get_platforms()
inline auto get_platforms() -> std::vector<Platform>
{
cl_int err;

cl_uint num_platforms;
err = clGetPlatformIDs(1, nullptr, &num_platforms);
if (err < 0)
throw std::runtime_error(format(
"Error: cannot get number of platforms! %s", get_error_string(err)));
"Error: cannot get number of platforms! %s", get_error_string(err)));

std::vector<cl_platform_id> platform_ids(num_platforms);
err = clGetPlatformIDs(num_platforms, &platform_ids[0], nullptr);
if (err < 0)
throw std::runtime_error(format(
"Error: cannot get the list of platforms",
get_error_string(err)));
throw std::runtime_error(format("Error: cannot get the list of platforms",
get_error_string(err)));


std::vector<Platform> platforms(num_platforms);
for (cl_uint i = 0; i < num_platforms; ++i)
Expand Down
8 changes: 5 additions & 3 deletions cpp/drafts/OpenCL/test/test_opencl_device_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ BOOST_AUTO_TEST_CASE(test_buffer)
Device device = get_devices(platform, CL_DEVICE_TYPE_ALL).front();
Context context(device);

float in_array[10];
DeviceBuffer<float> in_array_buffer(context, in_array, 10,
CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
{
float in_array[10];
DeviceBuffer<float> in_array_buffer(context, in_array, 10,
CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
}
}
Loading

0 comments on commit 3a6876a

Please sign in to comment.