Skip to content

Commit

Permalink
feat: add minimal iDatum support as POC
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Jan 17, 2025
1 parent d0b3d45 commit bced1f5
Show file tree
Hide file tree
Showing 8 changed files with 585 additions and 5 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if (VIDEOREADER_CFFI)
find_package(ffmpeg)
find_package(galaxy)
find_package(pylon)
find_package(idatum)
endif()

set(WITH_FFMPEG "OFF")
Expand Down Expand Up @@ -93,11 +94,23 @@ if (galaxy_FOUND)
)
endif()

set(WITH_IDATUM "OFF")
if (idatum_FOUND)
set(WITH_IDATUM "ON")
target_compile_definitions(videoreader PRIVATE VIDEOREADER_WITH_IDATUM)
target_link_libraries(videoreader PRIVATE idatum::idatum)
target_sources(videoreader PRIVATE
src/videoreader_idatum.cpp
src/videoreader_idatum.hpp
)
endif()

message(STATUS
"videoreader: "
"FFMPEG[${WITH_FFMPEG}] "
"PYLON[${WITH_PYLON}] "
"GALAXY[${WITH_GALAXY}] "
"IDATUM[${WITH_IDATUM}] "
"CAPI[${VIDEOREADER_BUILD_CAPI}]"
)

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ See [Findgalaxy.cmake](cmake/Findgalaxy.cmake) for exact logic of finding galaxy

Download [pylon SDK](https://www.baslerweb.com/). Then set `PYLON_DIR` environment variable to the SDK directory. See [Findpylon.cmake](cmake/Findpylon.cmake) for exact logic of finding pylon SDK.

### iDatum cameras (contrastech)

Download [iDatum SDK](https://www.visiondatum.com/upfile/onlinedoc/LEO_Area_USB_EN.html). Then set `IDATUM_DIR` environment variable to the SDK directory. See [Findidatum.cmake](cmake/Findidatum.cmake) for exact logic of finding iDatum SDK.


### pip

`pip install git+https://github.com/Visillect/videoreader`

`FFMPEG_DIR=... GALAXY_DIR=... PYLON_DIR=... pip install git+https://github.com/Visillect/videoreader`
When the SDKs aren't in default locations, the user can specify directories explicitly:
`FFMPEG_DIR=... GALAXY_DIR=... PYLON_DIR=... IDATUM_DIR=... pip install git+https://github.com/Visillect/videoreader`


## Examples:
Expand Down
131 changes: 131 additions & 0 deletions cmake/Findidatum.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Ad-hoc writings by Arseniy Terekhin<[email protected]>.
# Suggestions are welcomed!

set(IDATUM_DIR "" CACHE STRING "iDatum directory hint")

find_path(IDATUM_INCLUDE_DIR MvCameraControl.h
HINTS
${IDATUM_DIR}
$ENV{IDATUM_DIR}
$ENV{HOME}/.local
PATH_SUFFIXES inc include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
/usr/include
/sw/include
/opt/local/include
/opt/iDatum/include
/opt/include
/mingw/include
)

if (IDATUM_INCLUDE_DIR)
find_library(IDATUM_MvCameraControl_LIBRARY
NAMES libMvCameraControl.so
HINTS
${IDATUM_DIR}
$ENV{IDATUM_DIR}
$ENV{HOME}/.local
PATH_SUFFIXES lib lib/64
PATHS
/usr/local
/usr
/sw
/opt/local
/opt
/mingw
"${IDATUM_INCLUDE_DIR}/../lib/64"
)
get_filename_component(IDATUM_LIB_DIR "${IDATUM_MvCameraControl_LIBRARY}" DIRECTORY)
set(IDATUM_GCBase_LIBRARY "${IDATUM_LIB_DIR}/libGCBase_gcc421_v3_0.so")

set(IDATUM_VERSION_FILE "${CMAKE_BINARY_DIR}/idatum_version.c")
file(WRITE "${IDATUM_VERSION_FILE}"
"#include <stdio.h>\n"
"#include <MvCameraControl.h>\n\n"
"int main(){\n"
" union {\n"
" int version;\n"
" struct {unsigned char Test, Rev, Sub, Main;};\n"
" } version_s;\n\n"
" int version = MV_CC_GetSDKVersion();"
" version_s.version = version;"
" printf(\"idatum_version: %d.%d.%d.%d (%#08x)\", version_s.Main, version_s.Sub, version_s.Rev, version_s.Test, version);\n"
" return 0;\n"
"}\n"
)

set(ENV{LD_LIBRARY_PATH} "${IDATUM_LIB_DIR}")

try_run(
# Name of variable to store the run result (process exit status; number) in:
test_run_result

# Name of variable to store the compile result (TRUE or FALSE) in:
test_compile_result

# Binary directory:
"${CMAKE_CURRENT_BINARY_DIR}"

# Source file to be compiled:
"${IDATUM_VERSION_FILE}"

# Where to store the output produced during compilation:
COMPILE_OUTPUT_VARIABLE test_compile_output

# Where to store the output produced by running the compiled executable:
RUN_OUTPUT_VARIABLE test_run_output

# LINK_LIBRARIES iDatum
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${IDATUM_INCLUDE_DIR}"

LINK_LIBRARIES "${IDATUM_MvCameraControl_LIBRARY}" # "${IDATUM_GCBase_LIBRARY}"
)
if (NOT test_compile_result)
message(FATAL_ERROR "${test_compile_output}")
endif()
endif()

string(REGEX MATCH "\\d+\\.\\d+\\.\\d+\\.\\d+" IDATUM_VERSION_STRING "${test_run_output}")

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
idatum
REQUIRED_VARS
IDATUM_INCLUDE_DIR
IDATUM_GCBase_LIBRARY
VERSION_VAR IDATUM_VERSION_STRING
)

if(IDATUM_FOUND AND NOT TARGET idatum)
add_library(idatum::GCBase UNKNOWN IMPORTED)
set_target_properties(idatum::GCBase PROPERTIES
IMPORTED_LOCATION "${IDATUM_GCBase_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${IDATUM_INCLUDE_DIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_WITH_INSTALL_RPATH 1
INSTALL_RPATH "${IDATUM_LIB_DIR}"
)

message(STATUS "GCMABSE = ${IDATUM_GCBase_LIBRARY}")
add_library(idatum::MvCameraControl UNKNOWN IMPORTED)
set_target_properties(idatum::MvCameraControl PROPERTIES
IMPORTED_LOCATION "${IDATUM_MvCameraControl_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${IDATUM_INCLUDE_DIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_WITH_INSTALL_RPATH 1
)
message(STATUS "GCMABSE = ${IDATUM_MvCameraControl_LIBRARY}")

add_library(idatum::idatum INTERFACE IMPORTED)
set_target_properties(idatum::idatum PROPERTIES
INTERFACE_LINK_LIBRARIES "idatum::GCBase;idatum::MvCameraControl"
BUILD_WITH_INSTALL_RPATH 1
INSTALL_RPATH "${IDATUM_LIB_DIR}"
)
message(STATUS "!!!${IDATUM_LIB_DIR}")
# INSTALL_RPATH "$ORIGIN/.."
endif()
2 changes: 1 addition & 1 deletion include/videoreader/videoreader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class VideoReader {
public:
enum class SCALAR_TYPE : int32_t { U8 };
enum class SCALAR_TYPE : int32_t { U8, U16 };
struct VRImage {
int32_t height;
int32_t width;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "videoreader"
version = "0.0.1"
version = "0.0.2"
authors = [
{ name="Arseniy Terekhin", email="[email protected]" },
]
Expand Down
20 changes: 18 additions & 2 deletions src/videoreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
#include "videoreader_galaxy.hpp"
#endif

#ifdef VIDEOREADER_WITH_IDATUM
#include "videoreader_idatum.hpp"
#endif

static void default_vr_allocate(VideoReader::VRImage* image, void* unused) {
std::size_t size = image->stride * image->height;
std::size_t const size = image->stride * image->height;
image->data = new (std::nothrow) uint8_t[size];
}

Expand Down Expand Up @@ -65,6 +69,18 @@ std::unique_ptr<VideoReader> VideoReader::create(
userdata));
}
#endif
#ifdef VIDEOREADER_WITH_IDATUM
if (url.find("idatum://") == 0) {
return std::unique_ptr<VideoReader>(new VideoReaderIDatum(
url,
parameter_pairs,
extras,
allocate_callback,
delallocate_callback,
log_callback,
userdata));
}
#endif
#ifdef VIDEOREADER_WITH_FFMPEG
return std::unique_ptr<VideoReader>(new VideoReaderFFmpeg(
url,
Expand All @@ -76,7 +92,7 @@ std::unique_ptr<VideoReader> VideoReader::create(
userdata));
#else
#if !defined(VIDEOREADER_WITH_FFMPEG) && !defined(VIDEOREADER_WITH_PYLON) && \
!defined(VIDEOREADER_WITH_GALAXY)
!defined(VIDEOREADER_WITH_GALAXY) && !defined(VIDEOREADER_WITH_IDATUM)
throw std::runtime_error("build without any video backed");
#else
throw std::runtime_error("unsupported uri");
Expand Down
Loading

0 comments on commit bced1f5

Please sign in to comment.