Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 143 additions & 42 deletions HAL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,25 @@ include( install_package )

string(TOLOWER ${PROJECT_NAME} LIBRARY_NAME)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-inconsistent-missing-override -Wextra")
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-inconsistent-missing-override -Wextra")
endif()

#############################################################################
# Find required libraries
find_package( Eigen3 REQUIRED )
find_package( Protobuf REQUIRED )
if(ANDROID)
# Override to use hosts protoc compiler
unset(PROTOBUF_PROTOC_EXECUTABLE CACHE)
find_host_package(Protobuf REQUIRED)
endif()
find_package( protobuf REQUIRED CONFIG)
find_package( Sophus REQUIRED )
find_package( GLog REQUIRED )
find_package( TinyXML2 QUIET )
find_package( gflags REQUIRED CONFIG)
find_package( glog REQUIRED CONFIG)
find_package( tinyxml2 QUIET CONFIG)

if(TinyXML2_FOUND)
if(tinyxml2_FOUND)
add_definitions(-DHAVE_TINYXML2)
list(APPEND LINK_LIBS ${TinyXML2_LIBRARIES})
list(APPEND USER_INC ${TinyXML2_INCLUDE_DIRS})
list(APPEND LINK_LIBS tinyxml2)
endif()


find_package(OpenCV QUIET COMPONENTS core)
if(NOT OpenCV_FOUND)
message(WARNING "No OpenCV found; camera drivers disabled.")
Expand All @@ -49,14 +47,18 @@ elseif(OpenCV_VERSION_MAJOR EQUAL 3)
find_package(OpenCV QUIET COMPONENTS core imgproc imgcodecs videoio)
endif()

if(WIN32)
find_path(DIRENT_INCLUDE_DIR NAMES dirent.h)
find_package(dlfcn-win32 REQUIRED CONFIG)
list( APPEND LINK_LIBS dlfcn-win32::dl)
find_path(POSIX_shim_INCLUDE_DIR NAMES unistd.h)
endif()

list( APPEND USER_INC ${EIGEN3_INCLUDE_DIR} )
list( APPEND USER_INC ${Sophus_INCLUDE_DIRS} )
list( APPEND USER_INC ${PROTOBUF_INCLUDE_DIR} )
list( APPEND USER_INC ${GLog_INCLUDE_DIRS} )

include_directories( ${LIB_INC_DIR} ${USER_INC} )

list( APPEND LINK_LIBS ${PROTOBUF_LIBRARIES} ${GLog_LIBRARIES})
list( APPEND LINK_LIBS protobuf::libprotobuf glog::glog gflags_shared)

#############################################################################
# HAL macros for driver writers.
Expand All @@ -80,7 +82,16 @@ macro( add_to_hal_libraries )
set_property( GLOBAL APPEND PROPERTY P_LIBRARIES "${lib}" )
else()
# For imported targets, we just want to depend on the library directly
get_target_property(libpath ${lib} LOCATION)
if(NOT WIN32)
set(prop LOCATION)
else()
set(prop IMPORTED_IMPLIB_DEBUG)
get_target_property(libpath ${lib} ${prop})
if(NOT libpath)
set(prop IMPORTED_IMPLIB_RELEASE)
endif()
endif()
get_target_property(libpath ${lib} ${prop})
if (libpath)
set_property( GLOBAL APPEND PROPERTY P_LIBRARIES "${libpath}" )
# This shouldn't really happen, but let's cover our bases.
Expand Down Expand Up @@ -140,6 +151,7 @@ endmacro()
#############################################################################
# Add Devices


add_subdirectory( Devices )
add_subdirectory( ThirdParty )
add_subdirectory( IMU )
Expand Down Expand Up @@ -179,7 +191,9 @@ set( _PROTO_SRCS
${PROTO_DIR}/NodeCamMessage.proto
${PROTO_DIR}/Command.proto
)

IF(WIN32)
set(PROTOBUF_GENERATE_CPP_EXPORT dllexport_decl=HAL_EXPORT:)
ENDIF()
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${_PROTO_SRCS})

add_to_hal_sources( ${PROTO_SRCS} )
Expand All @@ -205,13 +219,18 @@ foreach(val RANGE ${len_c_o_s} )
set_source_files_properties( ${source} PROPERTIES COMPILE_FLAGS ${flag} )
endforeach()

if(TinyXML2_FOUND)
include_directories( ${TinyXML2_INCLUDE_DIR} )
endif()

#############################################################################
## Protobuf

find_package(OpenCV QUIET COMPONENTS core)

set(OpenCV_FOUND FALSE)
if(OpenCV_VERSION_MAJOR EQUAL 2)
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
elseif(OpenCV_VERSION_MAJOR EQUAL 3)
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs videoio highgui)
endif()

list(APPEND HAL_SOURCES
${PROTO_DIR}/Logger.cpp
${PROTO_DIR}/Reader.cpp
Expand Down Expand Up @@ -243,49 +262,131 @@ endif()
##########################################################################

include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
include_directories( ${LIB_INC_DIR} )
if(TinyXML2_FOUND)
include_directories( ${TinyXML2_INCLUDE_DIR} )
endif()
include_directories( ${INTERNAL_INC} )
include_directories( ${USER_INC} )
include_directories( ${CMAKE_CURRENT_BINARY_DIR}/Messages )
include_directories( ${CMAKE_BINARY_DIR} )
include_directories( ${OpenCV_INCLUDE_DIRS} )
link_directories(/usr/local/lib)
link_directories(${CMAKE_INSTALL_PREFIX}/lib)

set(HAL_LIBS
${INTERNAL_LIBS}
${PROTOBUF_LIBRARIES}
${LINK_LIBS}
CACHE STRING "HAL required libraries"
${OpenCV_LIBS}
)

list( REMOVE_ITEM HAL_LIBS "debug" )
list( REMOVE_ITEM HAL_LIBS "optimized" )

set(HAL_INCLUDES
${LIB_INC_DIR}
${USER_INC}
CACHE STRING "HAL required includes" )

${USER_INC} )

add_library( hal ${HAL_SOURCES} )
target_link_libraries( hal ${HAL_LIBS} )

SET_TARGET_PROPERTIES(hal PROPERTIES PREFIX lib)

if (BUILD_SHARED_LIBS)

if (WIN32)
set (_EXPORT "__declspec(dllexport)")
set (_IMPORT "__declspec(dllimport)")
endif()

target_compile_definitions (hal PRIVATE
"HAL_EXPORT=${_EXPORT}")
target_compile_definitions (hal INTERFACE
"HAL_EXPORT=${_IMPORT}")

else()
target_compile_definitions (hal PUBLIC HAL_EXPORT=)
endif()

if(WIN32)
target_include_directories(hal PUBLIC ${DIRENT_INCLUDE_DIR} )
target_include_directories(hal PUBLIC ${POSIX_shim_INCLUDE_DIR} )
endif()

if(ANDROID)
set_target_properties(hal PROPERTIES LINK_FLAGS " -Wl,--build-id ")
endif()


########################################################
## Create configure file for inclusion in library
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h" )

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Devices/SharedLoad.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/Devices/SharedLoad.h" )

set( GENERATED_HEADERS ${PROTO_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/config.h
${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/ThirdPartyConfig.h )

install_package(
PKG_NAME HAL
LIB_NAME hal
VERSION ${HAL_VERSION}
INSTALL_HEADERS ${HAL_HEADERS}
INSTALL_GENERATED_HEADERS ${GENERATED_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
INCLUDE_DIRS ${HAL_INCLUDES}
LINK_LIBS ${HAL_LIBS}
)
${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/ThirdPartyConfig.h ${CMAKE_CURRENT_BINARY_DIR}/Devices/SharedLoad.h)

include_directories( ${CMAKE_BINARY_DIR} )
IF(USB1_LIBRARY)
set(HAL_LIBS ${HAL_LIBS} ${USB1_LIBRARY})
ENDIF()

include (CMakePackageConfigHelpers)


install (TARGETS hal
EXPORT hal-targets
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/HAL
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

set(LOAD_DEPENDENCY "find_package( protobuf CONFIG )
find_dependency( gflags )
find_dependency( glog )")

if(tinyxml2_FOUND)
set(LOAD_DEPENDENCY "${LOAD_DEPENDENCY}
find_dependency(tinyxml2)")
endif()

if(WIN32)
set(LOAD_DEPENDENCY "${LOAD_DEPENDENCY}
find_dependency(dlfcn-win32)")
endif()


configure_package_config_file (hal-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/hal-config.cmake
INSTALL_DESTINATION lib/cmake/hal
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file (hal-config-version.cmake VERSION
${HAL_VERSION} COMPATIBILITY SameMajorVersion)

export (TARGETS hal NAMESPACE hal:: FILE hal-targets.cmake)
export (PACKAGE HAL)

install (FILES
${CMAKE_CURRENT_BINARY_DIR}/hal-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/hal-config-version.cmake
DESTINATION lib/cmake/hal)

install (EXPORT hal-targets NAMESPACE hal:: DESTINATION lib/cmake/hal)

foreach(hdr IN LISTS HAL_HEADERS )
get_filename_component( _fp ${hdr} ABSOLUTE )
file( RELATIVE_PATH _rpath ${CMAKE_SOURCE_DIR} ${_fp} )
get_filename_component( _dir ${_rpath} DIRECTORY )
install( FILES ${_fp}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${_dir} )
endforeach()

foreach(hdr IN LISTS GENERATED_HEADERS )
get_filename_component( _fp ${hdr} ABSOLUTE )
file( RELATIVE_PATH _rpath ${CMAKE_BINARY_DIR} ${_fp} )
get_filename_component( _dir ${_rpath} DIRECTORY )
install( FILES ${_fp}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${_dir} )
endforeach()

9 changes: 9 additions & 0 deletions HAL/Camera/Drivers/Convert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

message( STATUS "HAL: building 'Convert' abstract camera driver (using libopencv).")
find_package(OpenCV QUIET COMPONENTS core)

set(OpenCV_FOUND FALSE)
if(OpenCV_VERSION_MAJOR EQUAL 2)
find_package(OpenCV QUIET COMPONENTS core imgproc highgui)
elseif(OpenCV_VERSION_MAJOR EQUAL 3)
find_package(OpenCV QUIET COMPONENTS core imgproc imgcodecs videoio)
endif()

add_to_hal_libraries( ${OpenCV_LIBS} )
add_to_hal_include_dirs( ${OpenCV_INCLUDE_DIRS} )
Expand Down
23 changes: 18 additions & 5 deletions HAL/Camera/Drivers/FileReader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@

set( BUILD_FileReader true CACHE BOOL force )

if( BUILD_FileReader )
find_package(OpenCV QUIET COMPONENTS core)

set(OpenCV_FOUND FALSE)
if(OpenCV_VERSION_MAJOR EQUAL 2)
find_package(OpenCV QUIET COMPONENTS core imgproc highgui)
elseif(OpenCV_VERSION_MAJOR EQUAL 3)
find_package(OpenCV QUIET COMPONENTS core imgproc imgcodecs videoio highgui)
endif()


if( BUILD_FileReader AND OpenCV_FOUND)

message( STATUS "HAL: building 'FileReader' camera driver.")
add_to_hal_sources(
FileReaderDriver.cpp FileReaderFactory.cpp ReadImage.cpp
FileReaderDriver.h ReadImage.h
)
add_to_hal_libraries( ${OpenCV_LIBS} )
add_to_hal_include_dirs( ${OpenCV_INCLUDE_DIRS} )
add_to_hal_sources(
FileReaderDriver.cpp FileReaderFactory.cpp ReadImage.cpp
FileReaderDriver.h ReadImage.h
)

endif()
33 changes: 31 additions & 2 deletions HAL/Camera/Drivers/FileReader/FileReaderDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <HAL/Devices/DeviceException.h>
#include <HAL/Utils/StringUtils.h>

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>

#include "ReadImage.h"

Expand Down Expand Up @@ -40,6 +40,8 @@ FileReaderDriver::FileReaderDriver(const std::vector<std::string>& ChannelRegex,

m_vFileList.resize(m_nNumChannels);

m_vOffsets.resize(m_nNumChannels);

for(unsigned int ii = 0; ii < m_nNumChannels; ii++) {
// Now generate the list of files for each channel
std::vector< std::string >& vFiles = m_vFileList[ii];
Expand Down Expand Up @@ -191,11 +193,30 @@ bool FileReaderDriver::_Read() {
// now fetch the next set of images
std::string sFileName;

//pre-read filenames and collect timestamps
std::vector<double> timestamps(m_nNumChannels);
for (unsigned int ii = 0; ii < m_nNumChannels; ++ii) {
if (m_nCurrentImageIndex + m_vOffsets[ii] < m_vFileList[ii].size() && m_nCurrentImageIndex + m_vOffsets[ii] >= 0) {
sFileName = m_vFileList[ii][m_nCurrentImageIndex + m_vOffsets[ii]];
timestamps[ii] = _GetTimestamp(sFileName);
}
}

//if timestamps are different send blank image

auto min_timestamp = *std::min_element(timestamps.begin(), timestamps.end());

hal::CameraMsg vImages;
double device_timestamp = -1;
for(unsigned int ii = 0; ii < m_nNumChannels; ++ii) {
hal::ImageMsg* pbImg = vImages.add_image();
sFileName = m_vFileList[ii][m_nCurrentImageIndex];
if (m_nCurrentImageIndex + m_vOffsets[ii] < m_vFileList[ii].size() && m_nCurrentImageIndex + m_vOffsets[ii] >= 0) {
sFileName = m_vFileList[ii][m_nCurrentImageIndex + m_vOffsets[ii]];
}
else
{
sFileName = m_vFileList[ii][m_nCurrentImageIndex];
}
cv::Mat cvImg = _ReadFile(sFileName, m_iCvImageReadFlags);

double timestamp = _GetTimestamp(sFileName);
Expand Down Expand Up @@ -224,6 +245,14 @@ bool FileReaderDriver::_Read() {
if(cvImg.channels() == 3) {
pbImg->set_format(hal::PB_RGB);
}


if (std::abs(timestamps[ii] - min_timestamp) > 0.001 /*seconds = 1 ms*/) {
m_vOffsets[ii]--; // this image is too far in the future, process it next time
cvImg.setTo(0);
}


pbImg->set_data(
(const char*)cvImg.data,
cvImg.rows * cvImg.cols * cvImg.elemSize1() * cvImg.channels());
Expand Down
1 change: 1 addition & 0 deletions HAL/Camera/Drivers/FileReader/FileReaderDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class FileReaderDriver : public CameraDriverInterface {
std::string m_sBaseDir;
unsigned int m_nNumChannels;
unsigned int m_nCurrentImageIndex;
std::vector< int > m_vOffsets; // Vector of index offsets to align the timestamps
bool m_bLoop;
unsigned int m_nNumImages;
unsigned int m_nBufferSize;
Expand Down
1 change: 1 addition & 0 deletions HAL/Camera/Drivers/FileReader/ReadImage.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ReadImage.h"

#include <fstream>
#include <opencv2/highgui/highgui.hpp>

namespace hal
{
Expand Down
Loading