144 Commits

Author SHA1 Message Date
John Zhao
d5bdce4f75 Update README.md 2018-06-08 16:45:24 +08:00
John Zhao
7ed11b01ff Update doc version 2018-06-08 16:13:28 +08:00
John Zhao
9caf979d4c Merge branch 'feature/one-thread-read' into develop 2018-06-08 12:17:13 +08:00
John Zhao
9b91304f0b Get stream & motion datas in one thread 2018-06-07 11:19:58 +08:00
John Zhao
0286da50c6 Add intermediate tutorials 2018-06-05 15:28:10 +08:00
John Zhao
3e96e56d8b Detect OpenCV 4.x 2018-06-05 15:00:44 +08:00
John Zhao
9451fdd90c Fix view points rotation 2018-06-05 14:42:39 +08:00
John Zhao
1293757486 Update README.md 2018-06-05 00:30:44 +08:00
John Zhao
190c5d883c Update doc version 2018-06-04 22:41:25 +08:00
John Zhao
2fe6309994 Update get_depth_with_region sample 2018-06-04 22:27:23 +08:00
John Zhao
dfb574c179 Support find plugin to load 2018-06-04 22:09:20 +08:00
John Zhao
b7436e41b9 Output build.info 2018-06-04 14:15:54 +08:00
John Zhao
046661745d Update tools requirements 2018-06-02 16:43:48 +08:00
John Zhao
9d79526d6a Update uvc camera sample 2018-06-02 16:04:11 +08:00
John Zhao
7451b6417d Restore lock stream datas 2018-06-01 16:50:15 +08:00
John Zhao
9c20d62763 Increase v4l2 request buffers 2018-06-01 16:34:21 +08:00
John Zhao
a0cf8fd902 Do small changes 2018-06-01 07:09:03 +00:00
John Zhao
c5dd47708e Disable log to file 2018-06-01 10:55:45 +08:00
John Zhao
2fddba75e9 Update control channel doc 2018-06-01 10:40:57 +08:00
John Zhao
5a836b2ae3 Add proc period support 2018-06-01 10:32:36 +08:00
John Zhao
e4fddf2b8d Merge win support into develop 2018-06-01 00:38:37 +08:00
John Zhao
1da095f5c3 Optimize streams 2018-05-31 23:41:32 +08:00
John Zhao
f447739488 Add async callback for motion datas 2018-05-31 20:36:17 +08:00
KalmanSLightech
84103d91bb change the callback's parameter in uvc-v4l2.cc 2018-05-31 16:19:32 +08:00
KalmanSLightech
8bf0d982ea spelling mistake 2018-05-31 15:48:58 +08:00
John Zhao
7e55f78418 Add async callback support 2018-05-31 15:39:42 +08:00
kalman
5be47846e7 change the way to get xu control's range 2018-05-31 15:09:00 +08:00
John Zhao
425b181216 Improve lock stream datas 2018-05-31 10:28:52 +08:00
John Zhao
b96d7a1782 Fix log message 2018-05-30 22:15:50 +08:00
John Zhao
6c7b4e1fb2 Add get_info service to ros wrapper 2018-05-30 22:02:05 +08:00
John Zhao
240b18270b Change log fatal 2018-05-30 12:41:35 +08:00
John Zhao
87470f29a9 Update xu_control_range in uvc-wmf.cc 2018-05-30 11:12:28 +08:00
John Zhao
b4f73dfa0b Add show depth values sample 2018-05-29 17:38:44 +08:00
John Zhao
5daf4162e4 Add log info in uvc-wmf.cc 2018-05-29 12:23:11 +08:00
John Zhao
aed39f0942 Change channel value 2018-05-29 12:21:30 +08:00
John Zhao
3673324079 Update uvc-wmf.cc & add xu_control_range 2018-05-25 12:32:58 +08:00
John Zhao
f17eff7e01 Improve detect vs version in makefile 2018-05-24 16:00:22 +08:00
John Zhao
3112779174 Update doc version 2018-05-23 12:46:33 +08:00
John Zhao
1130a99c8d Update comments of samples 2018-05-22 11:33:07 +08:00
John Zhao
13939734a7 Update python wrapper 2018-05-22 11:32:30 +08:00
kalman
0b7375698d change xu guid 2018-05-18 18:36:52 +08:00
John Zhao
49771d5b8e Format uvc-wmf.cc 2018-05-18 11:47:05 +08:00
John Zhao
d414182721 Add api create to python wrapper 2018-05-18 00:19:12 +08:00
John Zhao
072fe4d397 Add python wrapper 2018-05-17 17:28:43 +08:00
John Zhao
2ff0ed504d Update md5sum.sh 2018-05-16 16:56:02 +08:00
John Zhao
25d3526086 Fix imu track period 2018-05-16 16:37:12 +08:00
John Zhao
3a49eec9c0 Update README.md 2018-05-16 11:43:46 +08:00
John Zhao
3547acc422 Update doc version 2018-05-16 11:00:54 +08:00
John Zhao
152af37138 Fix forward declaration 2018-05-16 10:48:15 +08:00
John Zhao
dd2fc88846 Update doc comments 2018-05-16 10:31:31 +08:00
John Zhao
de0f0d0639 Log error and return if no devices 2018-05-15 22:01:15 +08:00
John Zhao
58fdc4c01b Fix capture video stream in uvc-wmf 2018-05-15 17:32:04 +08:00
John Zhao
276406dd1e Add imu track period 2018-05-15 14:54:22 +08:00
John Zhao
a83be6bde6 Add ros README.md 2018-05-14 13:48:58 +08:00
John Zhao
9e7c2cfa68 Get real exposure time and draw 2018-05-13 10:34:03 +08:00
John Zhao
aca1f8b183 Done control tutorials 2018-05-13 10:12:24 +08:00
John Zhao
abef84e8dc Extract util in tutorials 2018-05-12 22:53:36 +08:00
John Zhao
012ddb2ed0 Update api camera sample 2018-05-12 22:19:45 +08:00
John Zhao
994342ae3a Merge branch 'develop' of https://code.slightech.com:666/mynteye/mynt-eye-sdk-2 into develop 2018-05-11 17:13:05 +08:00
John Zhao
42cf45a4c0 Add save_all_infos tool 2018-05-11 16:48:22 +08:00
John Zhao
ff70cc47f3 Update CMakeLists.txt 2018-05-11 16:15:26 +08:00
John Zhao
02d78f132d Update guide tools doc 2018-05-11 14:08:53 +08:00
John Zhao
76d12ccec7 Show depth if new in get_from_callbacks 2018-05-11 13:23:04 +08:00
John Zhao
8b7e43d76d Update comments in get_from_callbacks 2018-05-11 13:08:55 +08:00
John Zhao
806359e900 Add tutorial get_from_callbacks 2018-05-11 11:35:48 +08:00
John Zhao
c74ebb3cd5 Add draw img data 2018-05-11 10:14:58 +08:00
John Zhao
63105b5ae4 Add tutorial get_imu 2018-05-11 09:56:21 +08:00
John Zhao
90bb1cdd9a Update tutorial get_points 2018-05-10 22:11:20 +08:00
John Zhao
4dc9108ae4 Add copyright information 2018-05-10 14:46:34 +08:00
John Zhao
bbdc0ac178 Update uvc-wmf.cc 2018-05-10 14:46:21 +08:00
John Zhao
40dc61d2b6 Add get stream data tutorials 2018-05-10 13:55:20 +08:00
John Zhao
1fec1300a8 Add tutorial get_with_plugin 2018-05-09 13:40:34 +08:00
John Zhao
401c003906 Add plugin support 2018-05-08 11:12:45 +08:00
kalman
ca0ae22aea change a parameter of ksproperty 2018-05-07 21:58:01 +08:00
kalman
9988c49060 corrected a mistake about get 2018-05-07 21:53:59 +08:00
kalman
b8f20c570c change the node and confirm the KSNODETYPE_DEV 2018-05-07 20:33:10 +08:00
kalman
8ca90f3478 add KSNODETYPE_DEV_SPECIFIC_LOCAL 2018-05-07 16:43:47 +08:00
John Zhao
7f0fa15c06 Update CMakeLists.txt 2018-05-07 16:29:20 +08:00
kalman
b1b9b60626 add uvc extension unit guid 2018-05-07 15:03:52 +08:00
kalman
113d2e5951 add two space 2018-05-05 21:10:49 +08:00
kalman
ff33770ca4 add some log 2018-05-05 20:52:36 +08:00
kalman
8d017f5e2d add code in uvc-wmf.cc 2018-05-05 16:27:05 +08:00
John Zhao
e041d43183 Test addons support and add tutorial ir control 2018-05-04 15:59:07 +08:00
John Zhao
2e31a79b1a Add add-ons enum type 2018-05-04 13:44:13 +08:00
John Zhao
8b21989dcc Add tutorial get_device_info 2018-05-03 16:40:09 +08:00
John Zhao
fbc7c3b6ef Add api create methods 2018-05-03 16:33:27 +08:00
John Zhao
c6586cf164 Fix macro target_create_scripts 2018-05-03 16:13:39 +08:00
John Zhao
b0b12c2cc7 Update guide docs 2018-05-03 14:45:33 +08:00
John Zhao
505b7df188 Update init.sh 2018-05-03 14:21:28 +08:00
John Zhao
2d7ae598f0 Install curl in init.sh 2018-05-03 11:33:13 +08:00
John Zhao
54d5c85b48 Publish points in ros 2018-04-30 14:43:18 +08:00
John Zhao
f636ba3a86 Support enable stream and publish them in ros 2018-04-30 10:51:09 +08:00
John Zhao
f3d6fcdcb9 Could inverse extrinsics 2018-04-29 14:47:35 +08:00
John Zhao
77837933bc Publish camera info in ros wrapper 2018-04-29 14:15:38 +08:00
John Zhao
96b5e20580 Impl ros wrapper with api layer 2018-04-28 14:54:23 +08:00
John Zhao
2111a183d0 Done points and depth processor 2018-04-28 14:27:43 +08:00
John Zhao
c49342f9f7 Add process return bool 2018-04-28 13:37:25 +08:00
John Zhao
c176f55af2 Done disparity processor 2018-04-28 13:26:46 +08:00
John Zhao
21f2f91343 Done rectify processor 2018-04-28 12:44:15 +08:00
John Zhao
9e497cfa80 Process synthetic stream data and callback 2018-04-28 12:40:29 +08:00
John Zhao
cf80332e13 Complete native streams 2018-04-27 22:35:43 +08:00
John Zhao
3467c822c9 Combine enable/disable stream with processors 2018-04-27 15:47:54 +08:00
John Zhao
a5ce17a987 Add processor files 2018-04-27 09:58:53 +08:00
John Zhao
81be95db12 Update processor 2018-04-26 15:15:33 +08:00
John Zhao
b97baae06d Add processor and update api 2018-04-26 14:44:47 +08:00
John Zhao
8f10285773 Add synthetic files 2018-04-26 10:33:37 +08:00
John Zhao
1fd44f7f0c Update api & link libs 2018-04-26 09:22:29 +08:00
John Zhao
cd28fa58d3 Add with api option 2018-04-25 16:06:38 +08:00
John Zhao
2dc470e14f Update samples, tools readme and guide doc 2018-04-25 13:22:36 +08:00
John Zhao
44364e7d82 Create bat for all exe 2018-04-25 12:08:25 +08:00
John Zhao
f766f2df22 Create bat for test exe 2018-04-25 11:32:54 +08:00
John Zhao
9cf58f6e70 Make build on win 2018-04-23 23:11:11 +08:00
John Zhao
145046249d Save all fields of device info 2018-04-21 22:05:38 +08:00
John Zhao
cf15498994 Update option doc 2018-04-21 15:46:40 +08:00
John Zhao
cdd98925b5 Add device writer tools 2018-04-21 15:45:33 +08:00
John Zhao
045c94dda7 Log message if get device info failed 2018-04-20 12:45:40 +08:00
John Zhao
3899b020b8 Move select device to utils 2018-04-20 12:44:23 +08:00
John Zhao
a3f90d31c7 Public headers of device layer and some utils 2018-04-19 23:19:00 +08:00
John Zhao
ad03d33d9c Change log message 2018-04-19 22:47:12 +08:00
John Zhao
f6120d5ae6 Improve intrinsics & extrinsics interfaces 2018-04-19 22:44:40 +08:00
John Zhao
e04a05f6f9 Complete read/write files 2018-04-19 17:23:02 +08:00
John Zhao
e50d9cec9b Fix imu gyro unit 2018-04-19 09:46:02 +08:00
John Zhao
c473a1fef3 Make ros wrapper on indigo 2018-04-18 21:40:58 +08:00
John Zhao
d99bc7bce5 Fix warnings in building with gcc4 2018-04-18 14:44:01 +08:00
John Zhao
7b288456a7 Add cmake version tip to init.sh 2018-04-18 12:17:13 +08:00
John Zhao
06b69da37a Update init.sh script 2018-04-18 11:36:36 +08:00
John Zhao
492b1063c3 Update spec docs 2018-04-17 16:31:02 +08:00
John Zhao
185ffc2811 Change checksum log message 2018-04-17 14:46:11 +08:00
John Zhao
460c707253 Fix query devices on linux 2016-02-12 21:30:31 +08:00
John Zhao
03d6043c08 Sleep 1 ms when publish imu in ros 2018-04-16 17:18:27 +08:00
John Zhao
3c65958c10 Update README.md 2018-04-16 12:54:18 +08:00
John Zhao
9147458c3a Add checksum tools 2018-04-16 12:20:31 +08:00
John Zhao
080db4ae2a Update tools README.md 2018-04-16 10:42:53 +08:00
John Zhao
b42a9529f3 Update README.md 2018-04-15 23:29:06 +08:00
John Zhao
9bb99499a2 Update TargetArch.cmake 2016-02-12 01:52:59 +08:00
John Zhao
ddb5cb46b7 Update enable plugin log info 2018-06-08 00:49:07 +08:00
John Zhao
0af640015b Detect opencv with world 2018-06-08 00:48:25 +08:00
John Zhao
064b536822 Update tutorials with opencv 2018-06-08 00:22:59 +08:00
John Zhao
209617dd24 Get compiler version values 2018-06-07 23:47:01 +08:00
John Zhao
ac88a68ebc Update build.info and support native system on win 2018-06-07 23:32:36 +08:00
John Zhao
ee6d9f5a3b Use absolute paths in bat 2018-06-07 21:40:41 +08:00
John Zhao
09fb4c04df Obtain raw frame in api stream data 2018-06-07 17:39:51 +08:00
John Zhao
22ea971407 Fix default int value in build.info 2018-06-07 16:23:38 +08:00
John Zhao
87458482d9 Update default topics 2018-06-07 12:45:23 +08:00
172 changed files with 15243 additions and 987 deletions

12
.gitignore vendored
View File

@@ -1,5 +1,7 @@
.DS_Store
/.vscode/
.vs/
.vscode/
_build/
_install/
@@ -12,12 +14,15 @@ _output/
/*ERROR*
/*FATAL*
/plugins/
# ros
/wrappers/ros/build
/wrappers/ros/devel
/wrappers/ros/install
/wrappers/ros/.catkin_workspace
/wrappers/ros/src/cv_bridge
/wrappers/ros/src/CMakeLists.txt
# tools
@@ -26,3 +31,8 @@ _output/
/mynteye/
/mynteye.bag
/dataset*/
# wrappers
/wrappers/python/third_party/numpy-opencv-converter/
/wrappers/python/third_party/pyboostcvconverter/

View File

@@ -1,13 +1,36 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
cmake_minimum_required(VERSION 3.0)
project(mynteye VERSION 2.0.0 LANGUAGES C CXX)
include(cmake/Common.cmake)
# options
include(cmake/Option.cmake)
# flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if(OS_WIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
include(cmake/DetectCXX11.cmake)
@@ -25,15 +48,42 @@ LIST(APPEND CMAKE_PREFIX_PATH third_party/glog/_build)
find_package(glog REQUIRED)
message(STATUS "Found glog: ${glog_VERSION}")
if(WITH_API)
include(cmake/DetectOpenCV.cmake)
endif()
find_package(Boost COMPONENTS filesystem)
if(Boost_FOUND)
set(WITH_BOOST_FILESYSTEM true)
add_definitions(-DWITH_FILESYSTEM)
add_definitions(-DWITH_BOOST_FILESYSTEM)
message(STATUS "With boost filesystem: ${Boost_VERSION}")
#message(STATUS " Boost_LIBRARIES: ${Boost_LIBRARIES}")
elseif(OS_WIN)
add_definitions(-DWITH_FILESYSTEM)
add_definitions(-DWITH_NATIVE_FILESYSTEM)
message(STATUS "With native filesystem")
endif()
LIST(APPEND CMAKE_MODULE_PATH cmake)
include(CMakePackageConfigHelpers)
# config
set(MYNTEYE_NAME ${PROJECT_NAME})
set(MYNTEYE_NAMESPACE "mynteye")
message(STATUS "Namespace: ${MYNTEYE_NAMESPACE}")
if(MSVC)
string(REPLACE "/" "\\\\" MYNTEYE_SDK_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
string(REPLACE "/" "\\\\" MYNTEYE_SDK_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
else()
file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" MYNTEYE_SDK_ROOT_DIR)
file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" MYNTEYE_SDK_INSTALL_DIR)
endif()
configure_file(
include/mynteye/mynteye.h.in
include/mynteye/mynteye.h @ONLY
@@ -41,7 +91,7 @@ configure_file(
# targets
include(cmake/Common.cmake)
add_definitions(-DMYNTEYE_EXPORTS)
set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output")
set_outdir(
@@ -66,14 +116,26 @@ target_include_directories(main PRIVATE
## libmynteye
set(MYNTEYE_NAME ${PROJECT_NAME})
set(MYNTEYE_PUBLIC_H
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/callbacks.h
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/global.h
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/glog_init.h
${CMAKE_CURRENT_BINARY_DIR}/include/mynteye/mynteye.h
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/types.h
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/utils.h
${CMAKE_CURRENT_SOURCE_DIR}/src/device/context.h
${CMAKE_CURRENT_SOURCE_DIR}/src/device/device.h
${CMAKE_CURRENT_SOURCE_DIR}/src/internal/files.h
${CMAKE_CURRENT_SOURCE_DIR}/src/internal/strings.h
${CMAKE_CURRENT_SOURCE_DIR}/src/internal/times.h
)
if(WITH_API)
list(APPEND MYNTEYE_PUBLIC_H
${CMAKE_CURRENT_SOURCE_DIR}/src/api/api.h
${CMAKE_CURRENT_SOURCE_DIR}/src/api/plugin.h
${CMAKE_CURRENT_SOURCE_DIR}/src/api/processor/object.h
)
endif()
if(OS_WIN)
set(UVC_SRC src/uvc/uvc-wmf.cc)
@@ -94,21 +156,41 @@ set(MYNTEYE_SRCS
${UVC_SRC}
src/internal/channels.cc
src/internal/config.cc
src/internal/dl.cc
src/internal/files.cc
src/internal/motions.cc
src/internal/streams.cc
src/internal/strings.cc
src/internal/types.cc
src/public/types.cc
src/public/utils.cc
src/device/context.cc
src/device/device.cc
src/device/device_s.cc
)
if(WITH_API)
list(APPEND MYNTEYE_SRCS
src/api/api.cc
src/api/synthetic.cc
src/api/processor/processor.cc
src/api/processor/rectify_processor.cc
src/api/processor/disparity_processor.cc
src/api/processor/disparity_normalized_processor.cc
src/api/processor/depth_processor.cc
src/api/processor/points_processor.cc
)
endif()
set(MYNTEYE_LINKLIBS
glog::glog
${UVC_LIB}
)
if(WITH_API)
list(APPEND MYNTEYE_LINKLIBS ${OpenCV_LIBS})
endif()
if(WITH_BOOST_FILESYSTEM)
list(APPEND MYNTEYE_LINKLIBS ${Boost_LIBRARIES})
endif()
#message(STATUS "MYNTEYE_LINKLIBS: ${MYNTEYE_LINKLIBS}")
add_library(${MYNTEYE_NAME} SHARED ${MYNTEYE_SRCS})
@@ -169,3 +251,56 @@ install(FILES
install(EXPORT ${MYNTEYE_NAME}-targets
DESTINATION ${MYNTEYE_CMAKE_INSTALLDIR}
)
## build.info
macro(set_default_value VARIABLE DEFAULT)
if(NOT ${VARIABLE})
set(${VARIABLE} ${DEFAULT})
endif()
endmacro()
macro(set_version_values VARIABLE)
string(REPLACE "." ";" __version_list "${${VARIABLE}}")
list(LENGTH __version_list __len)
if(${__len} GREATER 0)
list(GET __version_list 0 ${VARIABLE}_MAJOR)
endif()
if(${__len} GREATER 1)
list(GET __version_list 1 ${VARIABLE}_MINOR)
endif()
if(${__len} GREATER 2)
list(GET __version_list 2 ${VARIABLE}_PATCH)
endif()
if(${__len} GREATER 3)
list(GET __version_list 3 ${VARIABLE}_TWEAK)
endif()
endmacro()
find_package(CUDA QUIET)
set_version_values(CMAKE_CXX_COMPILER_VERSION)
set_default_value(CMAKE_CXX_COMPILER_VERSION_MAJOR 0)
set_default_value(CMAKE_CXX_COMPILER_VERSION_MINOR 0)
set_default_value(CMAKE_CXX_COMPILER_VERSION_PATCH 0)
set_default_value(CMAKE_CXX_COMPILER_VERSION_TWEAK 0)
set_default_value(CUDA_VERSION_MAJOR 0)
set_default_value(CUDA_VERSION_MINOR 0)
set_default_value(OpenCV_VERSION_MAJOR 0)
set_default_value(OpenCV_VERSION_MINOR 0)
set_default_value(OpenCV_VERSION_PATCH 0)
set_default_value(OpenCV_VERSION_TWEAK 0)
set_default_value(${PROJECT_NAME}_VERSION_MAJOR 0)
set_default_value(${PROJECT_NAME}_VERSION_MINOR 0)
set_default_value(${PROJECT_NAME}_VERSION_PATCH 0)
set_default_value(${PROJECT_NAME}_VERSION_TWEAK 0)
configure_file(
cmake/templates/build.info.in
build.info @ONLY
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/build.info
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mynteye
)

View File

@@ -1,3 +1,16 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
ifndef _COMMON_DEFS_MAKE_
_COMMON_DEFS_MAKE_ := 1
@@ -150,7 +163,6 @@ ifneq ($(MAKE),)
endif
CMAKE_OPTIONS :=
CMAKE_OPTIONS += -DCMAKE_INSTALL_PREFIX=$(shell pwd)/_install
# CMAKE_OPTIONS += -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
CMAKE_OPTIONS_AFTER :=
@@ -159,23 +171,32 @@ ifeq ($(HOST_OS),Win)
ifeq ($(HOST_NAME),MinGW)
CMAKE += -G "MinGW Makefiles"
else ifeq ($(HOST_ARCH),x64)
VS_VERSION := $(shell echo "$(shell which cl)" | sed "s/.*Visual\sStudio\s\([0-9]\+\).*/\1/g")
ifeq (15,$(VS_VERSION))
ifeq ($(VS_CODE),)
WHICH_CL := $(shell which cl)
ifeq ($(WHICH_CL),)
$(error "Visual Studio version is unknown. Could set VS_CODE to specify it, e.g. make [TARGET] VS_CODE=2017")
endif
# C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\...
# C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\...
VS_CODE := $(shell echo "$(WHICH_CL)" | grep -Po "(?<=Visual Studio[ /])[0-9]+")
endif
# $(call mkinfo,"VS_CODE: $(VS_CODE)")
ifeq ($(filter $(VS_CODE),15 2017),$(VS_CODE))
CMAKE += -G "Visual Studio 15 2017 Win64"
else ifeq (14,$(VS_VERSION))
else ifeq ($(filter $(VS_CODE),14 2015),$(VS_CODE))
CMAKE += -G "Visual Studio 14 2015 Win64"
else ifeq (12,$(VS_VERSION))
else ifeq ($(filter $(VS_CODE),12 2013),$(VS_CODE))
CMAKE += -G "Visual Studio 12 2013 Win64"
else ifeq (11,$(VS_VERSION))
else ifeq ($(filter $(VS_CODE),11 2012),$(VS_CODE))
CMAKE += -G "Visual Studio 11 2012 Win64"
else ifeq (10,$(VS_VERSION))
else ifeq ($(filter $(VS_CODE),10 2010),$(VS_CODE))
CMAKE += -G "Visual Studio 10 2010 Win64"
else ifeq (9,$(VS_VERSION))
else ifeq ($(filter $(VS_CODE),9 2008),$(VS_CODE))
CMAKE += -G "Visual Studio 9 2008 Win64"
else ifeq (8,$(VS_VERSION))
else ifeq ($(filter $(VS_CODE),8 2005),$(VS_CODE))
CMAKE += -G "Visual Studio 8 2005 Win64"
else
$(call mkinfo,"Connot specify Visual Studio Win64")
$(error "Visual Studio version is not proper, VS_CODE: $(VS_CODE)")
endif
endif

View File

@@ -1,5 +1,21 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
include CommonDefs.mk
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
.DEFAULT_GOAL := help
help:
@@ -14,10 +30,15 @@ help:
@echo " make samples build samples"
@echo " make tools build tools"
@echo " make ros build ros wrapper"
@echo " make py build python wrapper"
@echo " make clean|cleanall clean generated or useless things"
.PHONY: help
all: test tools samples
.PHONY: all
# doc
apidoc:
@@ -59,7 +80,7 @@ init: submodules
build: third_party
@$(call echo,Make $@)
@$(call cmake_build,./_build)
@$(call cmake_build,./_build,..,-DCMAKE_INSTALL_PREFIX=$(MKFILE_DIR)/_install)
.PHONY: build
@@ -68,10 +89,18 @@ build: third_party
test: install
@$(call echo,Make $@)
@$(call echo,Make gtest,33)
ifeq ($(HOST_OS),Win)
@$(call cmake_build,./test/gtest/_build,..,-Dgtest_force_shared_crt=ON)
else
@$(call cmake_build,./test/gtest/_build)
endif
@$(call echo,Make test,33)
@$(call cmake_build,./test/_build)
ifeq ($(HOST_OS),Win)
@.\\\test\\\_output\\\bin\\\mynteye_test.bat
else
@./test/_output/bin/mynteye_test
endif
.PHONY: test
@@ -79,7 +108,15 @@ test: install
install: build
@$(call echo,Make $@)
ifeq ($(HOST_OS),Win)
ifneq ($(HOST_NAME),MinGW)
@cd ./_build; msbuild.exe INSTALL.vcxproj /property:Configuration=Release
else
@cd ./_build; make install
endif
else
@cd ./_build; make install
endif
.PHONY: install
@@ -103,7 +140,11 @@ tools: install
ros: install
@$(call echo,Make $@)
ifeq ($(HOST_OS),Win)
$(error "Can't make ros on win")
else
@cd ./wrappers/ros && catkin_make
endif
.PHONY: ros
@@ -121,6 +162,44 @@ cleanros:
.PHONY: cleanros
# python
PBCVT_DIR := wrappers/python/third_party/pyboostcvconverter
$(PBCVT_DIR):
@git clone https://github.com/Algomorph/pyboostcvconverter.git $@
pbcvt: $(PBCVT_DIR)
@$(call cmake_build,$(PBCVT_DIR)/_build,.., \
-DCMAKE_INSTALL_PREFIX=$(MKFILE_DIR)/wrappers/python/_install \
-DPYTHON_DESIRED_VERSION=2.X)
@cd $(PBCVT_DIR)/_build; make install
.PHONY: pbcvt
NPCV_DIR := wrappers/python/third_party/numpy-opencv-converter
$(NPCV_DIR):
@git clone https://github.com/GarrickLin/numpy-opencv-converter.git $@
py: python
python: install $(NPCV_DIR)
@$(call echo,Make $@)
@$(call cmake_build,./wrappers/python/_build)
@cd ./wrappers/python/_build; make install
.PHONY: py python
cleanpy:
@$(call echo,Make $@)
@$(call rm,./wrappers/python/_build/)
@$(call rm,./wrappers/python/_output/)
@$(call rm,./wrappers/python/_install/)
@$(call rm,./$(PBCVT_DIR)/_build/)
.PHONY: cleanpy
# clean
clean:
@@ -138,6 +217,7 @@ clean:
ifeq ($(HOST_OS),Linux)
@$(MAKE) cleanros
endif
@$(MAKE) cleanpy
cleanlog:
@$(call rm_f,*INFO*)
@@ -150,6 +230,8 @@ cleanall: clean
@$(call rm,./test/gtest/_build/)
@$(call rm,./third_party/glog/_build/)
@$(FIND) . -type f -name ".DS_Store" -print0 | xargs -0 rm -f
@$(call rm,./$(PBCVT_DIR)/)
@$(call rm,./$(NPCV_DIR)/)
.PHONY: clean cleanlog cleanall
@@ -157,6 +239,8 @@ cleanall: clean
host:
@$(call echo,Make $@)
@echo MKFILE_PATH: $(MKFILE_PATH)
@echo MKFILE_DIR: $(MKFILE_DIR)
@echo HOST_OS: $(HOST_OS)
@echo HOST_ARCH: $(HOST_ARCH)
@echo HOST_NAME: $(HOST_NAME)

View File

@@ -4,8 +4,32 @@
MYNT® EYE SDK 2.0 is a cross-platform library for MYNT® EYE cameras.
The following platforms have been tested:
* Windows 10
* Ubuntu 16.04 / 14.04
* Jetson TX2
Please follow the guide doc to install the SDK on different platforms.
## Documentations
* [API Doc](https://github.com/slightech/MYNT-EYE-SDK-2/releases): API reference, some guides and data spec.
* [Guide Doc](https://github.com/slightech/MYNT-EYE-SDK-2-Guide/releases): How to install and start using the SDK.
> Supported languages: `zh-Hans`.
## Firmwares
[Google Drive]: https://drive.google.com/drive/folders/1tdFCcTBMNcImEGZ39tdOZmlX2SHKCr2f
[百度网盘]: https://pan.baidu.com/s/1yPQDp2r0x4jvNwn2UjlMUQ
Get firmwares from our online disks: [Google Drive][], [百度网盘][]. The latest version is `2.0.0-rc`.
## Usage
In short,
```bash
$ make
Usage:
@@ -27,9 +51,13 @@ Init project, build samples and run someone.
```bash
make init
make samples
./samples/_output/bin/device/camera_d
./samples/_output/bin/device/camera_d
```
## Mirrors
国内镜像:[码云](https://gitee.com/mynt/MYNT-EYE-SDK-2)。
## License
This project is licensed under the Apache License, Version 2.0. Copyright 2018 Slightech Co., Ltd.

View File

@@ -1,15 +1,60 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard()
include(CMakeParseArguments)
set(CUR_DIR ${CMAKE_CURRENT_LIST_DIR})
if(MSVC OR MSYS OR MINGW)
set(OS_WIN TRUE)
set(HOST_OS Win)
elseif(APPLE)
set(OS_MAC TRUE)
set(HOST_OS Mac)
elseif(UNIX)
set(OS_LINUX TRUE)
set(HOST_OS Linux)
else()
message(FATAL_ERROR "Unsupported OS.")
endif()
set(HOST_NAME "${HOST_OS}")
if(OS_LINUX)
execute_process(COMMAND uname -a COMMAND tr -d '\n' OUTPUT_VARIABLE UNAME_A)
string(TOLOWER "${UNAME_A}" UNAME_A)
if(${UNAME_A} MATCHES ".*(tegra|jetsonbot).*")
set(OS_TEGRA TRUE)
set(HOST_NAME Tegra)
elseif(${UNAME_A} MATCHES ".*ubuntu.*")
set(OS_UBUNTU TRUE)
set(HOST_NAME Ubuntu)
endif()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/TargetArch.cmake)
target_architecture(HOST_ARCH)
message(STATUS "HOST_ARCH: ${HOST_ARCH}")
# CMAKE_CXX_COMPILER_ID
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
# CMAKE_CXX_COMPILER_VERSION
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_VERSION.html
# set_outdir(ARCHIVE_OUTPUT_DIRECTORY
# LIBRARY_OUTPUT_DIRECTORY
# RUNTIME_OUTPUT_DIRECTORY)
@@ -24,3 +69,52 @@ macro(set_outdir ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY RUNTIME_OUTPU
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endforeach()
endmacro()
set(__exe2bat_relative_path false)
macro(exe2bat exe_name exe_dir dll_search_paths)
message(STATUS "Generating ${exe_name}.bat")
set(__exe_name ${exe_name})
if(__exe2bat_relative_path)
set(__dll_relative_search_paths "")
foreach(path ${dll_search_paths})
file(RELATIVE_PATH __relative_path "${exe_dir}" "${path}")
file(TO_NATIVE_PATH ${__relative_path} __relative_path)
list(APPEND __dll_relative_search_paths ${__relative_path})
endforeach()
set(__dll_search_paths "${__dll_relative_search_paths}")
else()
set(__dll_native_search_paths "")
foreach(path ${dll_search_paths})
file(TO_NATIVE_PATH ${path} __native_path)
list(APPEND __dll_native_search_paths ${__native_path})
endforeach()
set(__dll_search_paths "${__dll_native_search_paths}")
endif()
configure_file(
"${CUR_DIR}/templates/exe.bat.in"
"${exe_dir}/${__exe_name}.bat"
)
endmacro()
# target_create_scripts(NAME
# [BIN_DIR bin_dir]
# [DLL_SEARCH_PATHS path1 path2 ...])
macro(target_create_scripts NAME)
set(options)
set(oneValueArgs BIN_DIR)
set(multiValueArgs DLL_SEARCH_PATHS)
cmake_parse_arguments(THIS "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if(NOT THIS_BIN_DIR)
set(THIS_BIN_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
#message(STATUS "NAME: ${NAME}")
#message(STATUS "THIS_BIN_DIR: ${THIS_BIN_DIR}")
#message(STATUS "THIS_DLL_SEARCH_PATHS: ${THIS_DLL_SEARCH_PATHS}")
if(OS_WIN)
exe2bat("${NAME}" "${THIS_BIN_DIR}" "${THIS_DLL_SEARCH_PATHS}")
endif()
endmacro()

View File

@@ -1,3 +1,19 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard()
if(MSVC)

37
cmake/DetectOpenCV.cmake Normal file
View File

@@ -0,0 +1,37 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard()
find_package(OpenCV REQUIRED)
message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
if(OpenCV_VERSION VERSION_LESS 3.0)
add_definitions(-DUSE_OPENCV2)
elseif(OpenCV_VERSION VERSION_LESS 4.0)
add_definitions(-DUSE_OPENCV3)
else()
add_definitions(-DUSE_OPENCV4)
endif()
list(FIND OpenCV_LIBS "opencv_world" __index)
if(${__index} GREATER -1)
set(WITH_OPENCV_WORLD TRUE)
endif()
if(MSVC OR MSYS OR MINGW)
get_filename_component(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}/../bin" ABSOLUTE)
else()
set(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}")
endif()

1741
cmake/FindCUDA.cmake Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# The MIT License
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
#######################################################################
# This converts a file written in makefile syntax into one that can be included
# by CMake.
file(READ ${input_file} depend_text)
if (NOT "${depend_text}" STREQUAL "")
# message("FOUND DEPENDS")
string(REPLACE "\\ " " " depend_text ${depend_text})
# This works for the nvcc -M generated dependency files.
string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
set(dependency_list "")
foreach(file ${depend_text})
string(REGEX REPLACE "^ +" "" file ${file})
# OK, now if we had a UNC path, nvcc has a tendency to only output the first '/'
# instead of '//'. Here we will test to see if the file exists, if it doesn't then
# try to prepend another '/' to the path and test again. If it still fails remove the
# path.
if(NOT EXISTS "${file}")
if (EXISTS "/${file}")
set(file "/${file}")
else()
message(WARNING " Removing non-existent dependency file: ${file}")
set(file "")
endif()
endif()
if(NOT IS_DIRECTORY "${file}")
# If softlinks start to matter, we should change this to REALPATH. For now we need
# to flatten paths, because nvcc can generate stuff like /bin/../include instead of
# just /include.
get_filename_component(file_absolute "${file}" ABSOLUTE)
list(APPEND dependency_list "${file_absolute}")
endif()
endforeach()
else()
# message("FOUND NO DEPENDS")
endif()
# Remove the duplicate entries and sort them.
list(REMOVE_DUPLICATES dependency_list)
list(SORT dependency_list)
foreach(file ${dependency_list})
set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
endforeach()
file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")

View File

@@ -0,0 +1,109 @@
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# The MIT License
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
#######################################################################
# Parses a .cubin file produced by nvcc and reports statistics about the file.
file(READ ${input_file} file_text)
if (NOT "${file_text}" STREQUAL "")
string(REPLACE ";" "\\;" file_text ${file_text})
string(REPLACE "\ncode" ";code" file_text ${file_text})
list(LENGTH file_text len)
foreach(line ${file_text})
# Only look at "code { }" blocks.
if(line MATCHES "^code")
# Break into individual lines.
string(REGEX REPLACE "\n" ";" line ${line})
foreach(entry ${line})
# Extract kernel names.
if (${entry} MATCHES "[^g]name = ([^ ]+)")
set(entry "${CMAKE_MATCH_1}")
# Check to see if the kernel name starts with "_"
set(skip FALSE)
# if (${entry} MATCHES "^_")
# Skip the rest of this block.
# message("Skipping ${entry}")
# set(skip TRUE)
# else ()
message("Kernel: ${entry}")
# endif ()
endif()
# Skip the rest of the block if necessary
if(NOT skip)
# Registers
if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
set(entry "${CMAKE_MATCH_3}")
message("Registers: ${entry}")
endif()
# Local memory
if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
set(entry "${CMAKE_MATCH_3}")
message("Local: ${entry}")
endif()
# Shared memory
if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
set(entry "${CMAKE_MATCH_3}")
message("Shared: ${entry}")
endif()
if (${entry} MATCHES "^}")
message("")
endif()
endif()
endforeach()
endif()
endforeach()
else()
# message("FOUND NO DEPENDS")
endif()

View File

@@ -0,0 +1,288 @@
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# The MIT License
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
##########################################################################
# This file runs the nvcc commands to produce the desired output file along with
# the dependency file needed by CMake to compute dependencies. In addition the
# file checks the output of each command and if the command fails it deletes the
# output files.
# Input variables
#
# verbose:BOOL=<> OFF: Be as quiet as possible (default)
# ON : Describe each step
#
# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or
# RelWithDebInfo, but it should match one of the
# entries in CUDA_HOST_FLAGS. This is the build
# configuration used when compiling the code. If
# blank or unspecified Debug is assumed as this is
# what CMake does.
#
# generated_file:STRING=<> File to generate. This argument must be passed in.
#
# generated_cubin_file:STRING=<> File to generate. This argument must be passed
# in if build_cubin is true.
if(NOT generated_file)
message(FATAL_ERROR "You must specify generated_file on the command line")
endif()
# Set these up as variables to make reading the generated file easier
set(CMAKE_COMMAND "@CMAKE_COMMAND@") # path
set(source_file "@source_file@") # path
set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@") # path
set(cmake_dependency_file "@cmake_dependency_file@") # path
set(CUDA_make2cmake "@CUDA_make2cmake@") # path
set(CUDA_parse_cubin "@CUDA_parse_cubin@") # path
set(build_cubin @build_cubin@) # bool
set(CUDA_HOST_COMPILER "@CUDA_HOST_COMPILER@") # path
# We won't actually use these variables for now, but we need to set this, in
# order to force this file to be run again if it changes.
set(generated_file_path "@generated_file_path@") # path
set(generated_file_internal "@generated_file@") # path
set(generated_cubin_file_internal "@generated_cubin_file@") # path
set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@") # path
set(CUDA_NVCC_FLAGS @CUDA_NVCC_FLAGS@ ;; @CUDA_WRAP_OPTION_NVCC_FLAGS@) # list
@CUDA_NVCC_FLAGS_CONFIG@
set(nvcc_flags "@nvcc_flags@") # list
set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") # list (needs to be in quotes to handle spaces properly).
set(format_flag "@format_flag@") # string
if(build_cubin AND NOT generated_cubin_file)
message(FATAL_ERROR "You must specify generated_cubin_file on the command line")
endif()
# This is the list of host compilation flags. It C or CXX should already have
# been chosen by FindCUDA.cmake.
@CUDA_HOST_FLAGS@
# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
set(nvcc_host_compiler_flags "")
# If we weren't given a build_configuration, use Debug.
if(NOT build_configuration)
set(build_configuration Debug)
endif()
string(TOUPPER "${build_configuration}" build_configuration)
#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}")
foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}})
# Extra quotes are added around each flag to help nvcc parse out flags with spaces.
set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"")
endforeach()
if (nvcc_host_compiler_flags)
set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags})
endif()
#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"")
# Add the build specific configuration flags
list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
# Any -ccbin existing in CUDA_NVCC_FLAGS gets highest priority
list( FIND CUDA_NVCC_FLAGS "-ccbin" ccbin_found0 )
list( FIND CUDA_NVCC_FLAGS "--compiler-bindir" ccbin_found1 )
if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
if (CUDA_HOST_COMPILER STREQUAL "@_CUDA_MSVC_HOST_COMPILER@" AND DEFINED CCBIN)
set(CCBIN -ccbin "${CCBIN}")
else()
set(CCBIN -ccbin "${CUDA_HOST_COMPILER}")
endif()
endif()
# cuda_execute_process - Executes a command with optional command echo and status message.
#
# status - Status message to print if verbose is true
# command - COMMAND argument from the usual execute_process argument structure
# ARGN - Remaining arguments are the command with arguments
#
# CUDA_result - return value from running the command
#
# Make this a macro instead of a function, so that things like RESULT_VARIABLE
# and other return variables are present after executing the process.
macro(cuda_execute_process status command)
set(_command ${command})
if(NOT "x${_command}" STREQUAL "xCOMMAND")
message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})")
endif()
if(verbose)
execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
# Now we need to build up our command string. We are accounting for quotes
# and spaces, anything else is left up to the user to fix if they want to
# copy and paste a runnable command line.
set(cuda_execute_process_string)
foreach(arg ${ARGN})
# If there are quotes, excape them, so they come through.
string(REPLACE "\"" "\\\"" arg ${arg})
# Args with spaces need quotes around them to get them to be parsed as a single argument.
if(arg MATCHES " ")
list(APPEND cuda_execute_process_string "\"${arg}\"")
else()
list(APPEND cuda_execute_process_string ${arg})
endif()
endforeach()
# Echo the command
execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string})
endif()
# Run the command
execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result )
endmacro()
# Delete the target file
cuda_execute_process(
"Removing ${generated_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
)
# For CUDA 2.3 and below, -G -M doesn't work, so remove the -G flag
# for dependency generation and hope for the best.
set(depends_CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}")
set(CUDA_VERSION @CUDA_VERSION@)
if(CUDA_VERSION VERSION_LESS "3.0")
cmake_policy(PUSH)
# CMake policy 0007 NEW states that empty list elements are not
# ignored. I'm just setting it to avoid the warning that's printed.
cmake_policy(SET CMP0007 NEW)
# Note that this will remove all occurrences of -G.
list(REMOVE_ITEM depends_CUDA_NVCC_FLAGS "-G")
cmake_policy(POP)
endif()
# nvcc doesn't define __CUDACC__ for some reason when generating dependency files. This
# can cause incorrect dependencies when #including files based on this macro which is
# defined in the generating passes of nvcc invocation. We will go ahead and manually
# define this for now until a future version fixes this bug.
set(CUDACC_DEFINE -D__CUDACC__)
# Generate the dependency file
cuda_execute_process(
"Generating dependency file: ${NVCC_generated_dependency_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
-M
${CUDACC_DEFINE}
"${source_file}"
-o "${NVCC_generated_dependency_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${depends_CUDA_NVCC_FLAGS}
-DNVCC
${CUDA_NVCC_INCLUDE_ARGS}
)
if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}")
endif()
# Generate the cmake readable dependency file to a temp file. Don't put the
# quotes just around the filenames for the input_file and output_file variables.
# CMake will pass the quotes through and not be able to find the file.
cuda_execute_process(
"Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
COMMAND "${CMAKE_COMMAND}"
-D "input_file:FILEPATH=${NVCC_generated_dependency_file}"
-D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
-P "${CUDA_make2cmake}"
)
if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}")
endif()
# Copy the file if it is different
cuda_execute_process(
"Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}"
)
if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}")
endif()
# Delete the temporary file
cuda_execute_process(
"Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}"
)
if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}")
endif()
# Generate the code
cuda_execute_process(
"Generating ${generated_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${format_flag} -o "${generated_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${CUDA_NVCC_FLAGS}
-DNVCC
${CUDA_NVCC_INCLUDE_ARGS}
)
if(CUDA_result)
# Since nvcc can sometimes leave half done files make sure that we delete the output file.
cuda_execute_process(
"Removing ${generated_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
)
message(FATAL_ERROR "Error generating file ${generated_file}")
else()
if(verbose)
message("Generated ${generated_file} successfully.")
endif()
endif()
# Cubin resource report commands.
if( build_cubin )
# Run with -cubin to produce resource usage report.
cuda_execute_process(
"Generating ${generated_cubin_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${CUDA_NVCC_FLAGS}
${nvcc_flags}
${CCBIN}
${nvcc_host_compiler_flags}
-DNVCC
-cubin
-o "${generated_cubin_file}"
${CUDA_NVCC_INCLUDE_ARGS}
)
# Execute the parser script.
cuda_execute_process(
"Executing the parser script"
COMMAND "${CMAKE_COMMAND}"
-D "input_file:STRING=${generated_cubin_file}"
-P "${CUDA_parse_cubin}"
)
endif()

23
cmake/IncludeGuard.cmake Normal file
View File

@@ -0,0 +1,23 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
# include_guard: https://cmake.org/cmake/help/latest/command/include_guard.html
macro(cmake_include_guard)
get_property(INCLUDE_GUARD GLOBAL PROPERTY "_INCLUDE_GUARD_${CMAKE_CURRENT_LIST_FILE}")
if(INCLUDE_GUARD)
return()
endif()
set_property(GLOBAL PROPERTY "_INCLUDE_GUARD_${CMAKE_CURRENT_LIST_FILE}" TRUE)
endmacro()

18
cmake/Option.cmake Normal file
View File

@@ -0,0 +1,18 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
option(WITH_API "Build with API layer, need OpenCV" ON)
message(STATUS "Options:")
message(STATUS " WITH_API: ${WITH_API}")

167
cmake/TargetArch.cmake Executable file
View File

@@ -0,0 +1,167 @@
# Based on the Qt 5 processor detection code, so should be very accurate
# http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qprocessordetection.h
# Currently handles arm (v5, v6, v7, v8), x86 (32/64), ia64, and ppc (32/64)
# Regarding POWER/PowerPC, just as is noted in the Qt source,
# "There are many more known variants/revisions that we do not handle/detect."
set(archdetect_c_code "
#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) \\
|| defined(__aarch64__) || defined(__ARM64__)
#if defined(__aarch64__) || defined(__ARM64__)
#define cmake_ARM_64
#else
#define cmake_ARM_32
#endif
#if defined(__ARM_ARCH) && __ARM_ARCH > 1
#define cmake_ARM __ARM_ARCH
#elif defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM > 1
#define cmake_ARM __TARGET_ARCH_ARM
#elif defined(_M_ARM) && _M_ARM > 1
#define cmake_ARM _M_ARM
#elif defined(__ARM64_ARCH_8__) \\
|| defined(__aarch64__) \\
|| defined(__ARMv8__) \\
|| defined(__ARMv8_A__)
#define cmake_ARM 8
#elif defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
|| defined(__ARM_ARCH_7S__) \\
|| defined(_ARM_ARCH_7) \\
|| defined(__CORE_CORTEXA__)
#define cmake_ARM 7
#elif defined(__ARM_ARCH_6__) \\
|| defined(__ARM_ARCH_6J__) \\
|| defined(__ARM_ARCH_6T2__) \\
|| defined(__ARM_ARCH_6Z__) \\
|| defined(__ARM_ARCH_6K__) \\
|| defined(__ARM_ARCH_6ZK__) \\
|| defined(__ARM_ARCH_6M__)
#define cmake_ARM 6
#elif defined(__ARM_ARCH_5TEJ__) \\
|| defined(__ARM_ARCH_5TE__)
#define cmake_ARM 5
#else
#define cmake_ARM 0
#endif
#if cmake_ARM >= 8
#error cmake_ARCH armv8
#elif cmake_ARM >= 7
#error cmake_ARCH armv7
#elif cmake_ARM >= 6
#error cmake_ARCH armv6
#elif cmake_ARM >= 5
#error cmake_ARCH armv5
#else
#if defined(cmake_ARM_64)
#error cmake_ARCH arm64
#else
#error cmake_ARCH arm
#endif
#endif
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
")
# Set ppc_support to TRUE before including this file or ppc and ppc64
# will be treated as invalid architectures since they are no longer supported by Apple
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values
# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()

51
cmake/Utils.cmake Normal file
View File

@@ -0,0 +1,51 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard()
include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake)
# make_executable(NAME
# [SRCS src1 src2 ...]
# [LINK_LIBS lib1 lib2 ...]
# [DLL_SEARCH_PATHS path1 path2 ...]
# [WITH_THREAD])
macro(make_executable NAME)
set(options WITH_THREAD)
set(oneValueArgs)
set(multiValueArgs SRCS LINK_LIBS DLL_SEARCH_PATHS)
cmake_parse_arguments(THIS "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
add_executable(${NAME} ${THIS_SRCS})
target_link_libraries(${NAME} ${THIS_LINK_LIBS})
target_create_scripts(${NAME} DLL_SEARCH_PATHS ${THIS_DLL_SEARCH_PATHS})
if(OS_WIN)
target_compile_definitions(${NAME}
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()
if(THIS_WITH_THREAD)
#find_package(Threads REQUIRED)
if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(PUBLIC ${NAME} "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(${NAME} "${CMAKE_THREAD_LIBS_INIT}")
endif()
endif()
endmacro()

View File

@@ -0,0 +1,27 @@
%YAML:1.0
---
HOST_OS: "@HOST_OS@"
HOST_NAME: "@HOST_NAME@"
HOST_ARCH: "@HOST_ARCH@"
HOST_COMPILER: "@CMAKE_CXX_COMPILER_ID@"
COMPILER_VERSION: "@CMAKE_CXX_COMPILER_VERSION@"
COMPILER_VERSION_MAJOR: @CMAKE_CXX_COMPILER_VERSION_MAJOR@
COMPILER_VERSION_MINOR: @CMAKE_CXX_COMPILER_VERSION_MINOR@
COMPILER_VERSION_PATCH: @CMAKE_CXX_COMPILER_VERSION_PATCH@
COMPILER_VERSION_TWEAK: @CMAKE_CXX_COMPILER_VERSION_TWEAK@
CUDA_VERSION: "@CUDA_VERSION@"
CUDA_VERSION_MAJOR: @CUDA_VERSION_MAJOR@
CUDA_VERSION_MINOR: @CUDA_VERSION_MINOR@
CUDA_VERSION_STRING: "@CUDA_VERSION_STRING@"
OpenCV_VERSION: "@OpenCV_VERSION@"
OpenCV_VERSION_MAJOR: @OpenCV_VERSION_MAJOR@
OpenCV_VERSION_MINOR: @OpenCV_VERSION_MINOR@
OpenCV_VERSION_PATCH: @OpenCV_VERSION_PATCH@
OpenCV_VERSION_TWEAK: @OpenCV_VERSION_TWEAK@
OpenCV_VERSION_STATUS: "@OpenCV_VERSION_STATUS@"
OpenCV_WITH_WORLD: "@WITH_OPENCV_WORLD@"
MYNTEYE_VERSION: "@mynteye_VERSION@"
MYNTEYE_VERSION_MAJOR: @mynteye_VERSION_MAJOR@
MYNTEYE_VERSION_MINOR: @mynteye_VERSION_MINOR@
MYNTEYE_VERSION_PATCH: @mynteye_VERSION_PATCH@
MYNTEYE_VERSION_TWEAK: @mynteye_VERSION_TWEAK@

View File

@@ -0,0 +1,13 @@
@echo off
set "MY_DIR=%~dp0"
set "MY_PWD=%cd%"
if "%MY_PATH_SET_@__exe_name@%"=="" (
set "MY_PATH_SET_@__exe_name@=1"
set "PATH=@__dll_search_paths@;%PATH%"
)
::cd "%MY_DIR%"
"%MY_DIR%@__exe_name@.exe" %*
::cd "%MY_PWD%"
::pause >nul

View File

@@ -1,4 +1,18 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
# _VERBOSE_=1
# _TEST_=1

View File

@@ -1,4 +1,18 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
LANGS=(
en
zh-Hans

View File

@@ -38,7 +38,7 @@ PROJECT_NAME = "MYNT EYE SDK"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = v2.0
PROJECT_NUMBER = 2.0.0-rc
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
@@ -793,6 +793,7 @@ WARN_LOGFILE =
INPUT = mainpage.md \
guides.md \
guide_build_linux.md \
guide_build_win.md \
guide_samples.md \
guide_tools.md \
guide_log.md \
@@ -2099,7 +2100,9 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = DOXYGEN_WORKING
PREDEFINED = DOXYGEN_WORKING \
"MYNTEYE_BEGIN_NAMESPACE=namespace mynteye {" \
"MYNTEYE_END_NAMESPACE=}"
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The

View File

@@ -1,5 +1,7 @@
# 编译 on Linux {#guide_build_linux}
> Ubuntu 16.04, Ubuntu 14.04
## 获取代码
```bash
@@ -13,6 +15,18 @@ cd mynt-eye-sdk-2/
make init
```
### [OpenCV](https://opencv.org/)
编译前可在系统终端Windows 命令提示符)里如下指定 OpenCV 路径,其为 `OpenCVConfig.cmake` 目录:
```bash
# Linux, macOS
export OpenCV_DIR=~/opencv
# Windows
set OpenCV_DIR=C:\opencv
```
## 编译代码
```bash

View File

@@ -0,0 +1,113 @@
# 编译 on Windows {#guide_build_win}
> Windows 10
## 前提条件
* [Git](https://git-scm.com/downloads),用于获取代码。
* [CMake](https://cmake.org/download/),用于构建编译。
* [Doxygen](http://www.stack.nl/~dimitri/doxygen/download.html),用于生成文档。
最终命令提示符Command Prompt, cmd里可找到如下命令
```cmd
>cmake --version
cmake version 3.10.1
>git --version
git version 2.11.1.windows.1
>doxygen --version
1.8.13
```
* [Visual Studio](https://www.visualstudio.com/)
* [Visual Studio 2015](https://my.visualstudio.com/Downloads?q=Visual Studio 2015)
* [Visual Studio 2017](https://my.visualstudio.com/Downloads?q=Visual Studio 2017)
* [Windows 10 SDK](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk)
以 Visual Studio 2015 举例,请在系统环境变量 `PATH` 里添加上如下路径:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
C:\Program Files (x86)\MSBuild\14.0\Bin
最终命令提示符Command Prompt, cmd里可找到如下命令
```cmd
>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
>link
Microsoft (R) Incremental Linker Version 14.00.24215.1
>lib
Microsoft (R) Library Manager Version 14.00.24215.1
>msbuild
Microsoft (R) 生成引擎版本 14.0.25420.1
```
* [MSYS2](http://www.msys2.org/)
* [国内镜像](https://lug.ustc.edu.cn/wiki/mirrors/help/msys2)
* [pacman](https://wiki.archlinux.org/index.php/pacman)
打开 MSYS2 MSYS ,然后执行:
```msys
$ pacman -Syu
$ pacman -S make
```
并在系统环境变量 `PATH` 里添加上如下路径:
C:\msys64\usr\bin
最终命令提示符Command Prompt, cmd里可找到如下命令
```cmd
>make --version
GNU Make 4.2.1
```
## 获取代码
```cmd
>git clone https://github.com/slightech/MYNT-EYE-SDK-2.git
```
## 准备依赖
```cmd
>cd mynt-eye-sdk-2
>make init
Make init
Init deps
Install cmd: pacman -S
Install deps: git clang-format
pacman -S clang-format (not exists)
error: target not found: clang-format
pip install --upgrade autopep8 cpplint pylint requests
...
Init git hooks
ERROR: clang-format-diff is not installed!
Expect cmake version >= 3.0
cmake version 3.10.1
```
### [OpenCV](https://opencv.org/)
编译前可在系统终端Windows 命令提示符)里如下指定 OpenCV 路径,其为 `OpenCVConfig.cmake` 目录:
```bash
# Linux, macOS
export OpenCV_DIR=~/opencv
# Windows
set OpenCV_DIR=C:\opencv
```
## 编译代码
```cmd
>make install
```

View File

@@ -1,3 +1,13 @@
# OpenCV 依赖 {#guide_opencv}
目前 SDK 本身未依赖 OpenCV ,仅是样例依赖其显示图像。
SDK 提供了三层接口,其 OpenCV 依赖情况如下:
* `api` 上层接口,依赖 OpenCV 。
* `device`,中间层接口,不依赖 OpenCV 。
* `uvc`,底层接口,不依赖 OpenCV 。
如果不想使用 OpenCV ,你可编辑 `<sdk>/cmake/Option.cmake` 里的 `WITH_API` 选项,设为 `OFF` 就能关闭 `api` 层代码编译:
```cmake
option(WITH_API "Build with API layer, need OpenCV" ON)
```

View File

@@ -2,15 +2,18 @@
样例在 `<sdk>/samples` 目录,其提供了不同接口层的使用范例。
* `api` API 层接口,依赖 OpenCV 。
* `device`,中间层接口,不依赖 OpenCV 。
* `uvc`,底层接口。
> 目前 API 层接口,正在实现中。
## 依赖
* [OpenCV](https://opencv.org/),用于显示图像。
* 编译前可在系统终端Windows 命令提示符)里如下指定 OpenCV 路径,其为 `OpenCVConfig.cmake` 目录:
```bash
# Linux, macOS
export OpenCV_DIR=~/opencv
# Windows
set OpenCV_DIR=C:\opencv
```
## 编译
@@ -20,8 +23,24 @@ make samples
## 运行
运行 `api` 层接口样例,显示图像并输出 IMU 。
```bash
./samples/_output/bin/api/camera_a
# Windows
.\samples\_output\bin\api\camera_a.bat
```
运行 `device` 层接口样例,显示图像并输出 IMU 。
```bash
./samples/_output/bin/device/camera_d
# Windows
.\samples\_output\bin\device\camera_d.bat
```
## 结语
更多样例的说明,请见 `samples/README.md`

View File

@@ -1,20 +1,40 @@
# 工具 {#guide_tools}
样例`<sdk>/tools` 目录,其提供一些有用的工具
工具`<sdk>/tools` 目录,其提供一些有用的脚本和程序
## 准备
## 依赖
* [OpenCV](https://opencv.org/),部分工具需要。
* 编译前可在系统终端Windows 命令提示符)里如下指定 OpenCV 路径,其为 `OpenCVConfig.cmake` 目录:
```bash
# Linux, macOS
export OpenCV_DIR=~/opencv
# Windows
set OpenCV_DIR=C:\opencv
```
* Python 第三方库,脚本需要。
```bash
cd tools/
sudo pip install -r requirements.txt
```
## 编译
```bash
make tools
cd tools/
sudo pip install -r requirements.txt
```
## 录制数据集
```bash
./tools/_output/bin/dataset/record
# Windows
.\tools\_output\bin\dataset\record.bat
```
默认录制进 `dataset` 目录,加参数可指定该目录。
@@ -46,6 +66,8 @@ python tools/analytics/stamp_analytics.py -i dataset -c tools/config/mynteye/myn
\includegraphics[width=0.6\textwidth,keepaspectratio]{stamp_analytics.png}
\endlatexonly
> 如果用 ROS ,分析脚本也支持 ROS Bag 格式。
## 结语
如果用 ROS ,分析脚本也支持 ROS Bag 格式。关于 ROS 的录制和分析,请见 `tools/README.md`
设备信息读写、校验码等更多工具的说明,请见 `tools/README.md`

View File

@@ -1,6 +1,7 @@
# SDK 指导 {#guides}
* @subpage guide_build_linux
* @subpage guide_build_win
* @subpage guide_samples
* @subpage guide_tools
* @subpage guide_log

View File

@@ -2,11 +2,11 @@
| 名称 | 字段 | 地址 | 带宽 | 说明 |
| :----- | :----- | :----- | :----- | :----- |
| 相机控制通道 | XU_CAM_CTRL_CHANNEL | 0x0100 | 3 | |
| 半双工通道 | XU_HALF_DUPLEX_CHANNEL | 0x0200 | 20 | |
| IMU 请求通道 | XU_IMUDATA_WRITE_CHANNEL | 0x0300 | 5 | |
| IMU 响应通道 | XU_IMUDATA_READ_CHANNEL | 0x0400 | 2000 | |
| 文件通道 | XU_FILE_CHANNEL | 0x0500 | 2000 | |
| 相机控制通道 | XU_CAM_CTRL_CHANNEL | 1 | 3 | |
| 半双工通道 | XU_HALF_DUPLEX_CHANNEL | 2 | 20 | |
| IMU 请求通道 | XU_IMUDATA_WRITE_CHANNEL | 3 | 5 | |
| IMU 响应通道 | XU_IMUDATA_READ_CHANNEL | 4 | 2000 | |
| 文件通道 | XU_FILE_CHANNEL | 5 | 2000 | |
## 相机控制通道
@@ -32,7 +32,7 @@
| Header bit | Description |
| :--------- | :---------- |
| 0 | 0: get; 1: set |
| 0 | 0: Get; 1: Set |
| 1~4 | 未定义 |
| 5 | IMU 参数 |
| 6 | 图像参数 |
@@ -48,6 +48,6 @@
| File | ID | Max Size |
| :--- | :- | :------- |
| 硬件信息 | 0 | 256 |
| 图像参数 | 1 | 256 |
| IMU 参数 | 2 | 512 |
| 硬件信息 | 1 | 250 |
| 图像参数 | 2 | 250 |
| IMU 参数 | 4 | 500 |

View File

@@ -4,14 +4,14 @@
| :----- | :----- | :-------- | :-------------- | :----------------- | :-------- | :----- |
| VID | vid | 0x04B4 | √ | × | 2 | |
| PID | pid | 0x00F9 | √ | × | 2 | |
| 设备名称 | name | MYNT-EYE-? | √ | √ | 16 | MYNT-EYE-S1000 |
| 序列号 | serial_number | - | √ | √ | 16 | |
| 固件版本 | firmware_version | - | √ | √ | 2 | major,minor |
| 硬件版本 | hardware_version | - | × | √ | 3 | major,minor,flag |
| 协议版本 | spec_version | - | × | √ | 2 | major,minor |
| 镜头类型 | lens_type | - | × | √ | 4 | vendor(2),product(2) |
| IMU 类型 | imu_type | - | × | √ | 4 | vendor(2),product(2) |
| 基线长度 | nominal_baseline | - | × | √ | 2 | 单位 mm |
| 设备名称 | name | MYNT-EYE-? | √ | √ Get | 16 | MYNT-EYE-S1000 |
| 序列号 | serial_number | - | √ | √ Get | 16 | |
| 固件版本 | firmware_version | - | √ | √ Get | 2 | major,minor |
| 硬件版本 | hardware_version | - | × | √ Get | 3 | major,minor,flag |
| 协议版本 | spec_version | - | × | √ Get | 2 | major,minor |
| 镜头类型 | lens_type | - | × | √ Get/Set | 4 | vendor(2),product(2) ,未 Set 默认 0 |
| IMU 类型 | imu_type | - | × | √ Get/Set | 4 | vendor(2),product(2) ,未 Set 默认 0 |
| 基线长度 | nominal_baseline | - | × | √ Get/Set | 2 | 单位 mm ,未 set 默认 0 |
* 描述符获取:指通用 USB 设备信息,可用工具查看。
* 拓展通道获取指通过拓展通道UVC Extension Unit问硬件获取到的信息需要读取。

View File

@@ -37,6 +37,6 @@ IMU 包/小包,是一组 IMU 数据。
| Description | 相对基准时间戳的偏移量 | 图像帧 ID | 加速度计 x y z 三轴的值 | IMU 的温度 | 陀螺仪 x y z 三轴的值 |
* 加速度计和陀螺仪的计量值换算成物理值公式: **real = data * range / 0x10000**
* 加速度计量程默认值为 **8 g** ,陀螺仪量程默认值为 **1000 deg/s^2**
* 加速度计量程默认值为 **8 g** ,陀螺仪量程默认值为 **1000 deg/s**
* 温度计量值换算成物理值公式: **real = data / ratio + offset**
* ``ratio`` 默认值为 **326.8** ``offset`` 默认值为 **25℃**

View File

@@ -1,5 +1,18 @@
#ifndef MYNTEYE_INTERNAL_CALLBACKS_H_ // NOLINT
#define MYNTEYE_INTERNAL_CALLBACKS_H_
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_CALLBACKS_H_ // NOLINT
#define MYNTEYE_CALLBACKS_H_
#pragma once
#include <cstdint>
@@ -16,13 +29,23 @@ MYNTEYE_BEGIN_NAMESPACE
namespace device {
class Frame {
/**
* @ingroup datatypes
* Frame with raw data.
*/
class MYNTEYE_API Frame {
public:
using data_t = std::vector<std::uint8_t>;
/**
* Construct the frame with StreamRequest and raw data.
*/
Frame(const StreamRequest &request, const void *data)
: Frame(request.width, request.height, request.format, data) {}
/**
* Construct the frame with stream info and raw data.
*/
Frame(
std::uint16_t width, std::uint16_t height, Format format,
const void *data)
@@ -36,30 +59,37 @@ class Frame {
}
}
/** Get the width. */
std::uint16_t width() const {
return width_;
}
/** Get the height. */
std::uint16_t height() const {
return height_;
}
/** Get the format. */
Format format() const {
return format_;
}
/** Get the data. */
std::uint8_t *data() {
return data_.data();
}
/** Get the const data. */
const std::uint8_t *data() const {
return data_.data();
}
/** Get the size of data. */
std::size_t size() const {
return data_.size();
}
/** Clone a new frame. */
Frame clone() const {
Frame frame(width_, height_, format_, nullptr);
std::copy(data_.begin(), data_.end(), frame.data_.begin());
@@ -74,12 +104,23 @@ class Frame {
data_t data_;
};
/**
* @ingroup datatypes
* Device stream data.
*/
struct MYNTEYE_API StreamData {
/** ImgData. */
std::shared_ptr<ImgData> img;
/** Frame. */
std::shared_ptr<Frame> frame;
};
/**
* @ingroup datatypes
* Device motion data.
*/
struct MYNTEYE_API MotionData {
/** ImuData. */
std::shared_ptr<ImuData> imu;
};
@@ -90,4 +131,4 @@ using MotionCallback = std::function<void(const MotionData &data)>;
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_INTERNAL_CALLBACKS_H_ NOLINT
#endif // MYNTEYE_CALLBACKS_H_ NOLINT

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_GLOBAL_H_
#define MYNTEYE_GLOBAL_H_
#pragma once

View File

@@ -1,16 +1,35 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_GLOG_INIT_H_ // NOLINT
#define MYNTEYE_GLOG_INIT_H_
#pragma once
#include <glog/logging.h>
/** Helper to init glog with args. */
struct glog_init {
glog_init(int /*argc*/, char *argv[]) {
/**
* Init glog with args in constructor, and shutdown it in destructor.
*/
glog_init(int argc, char *argv[]) {
(void)argc;
// FLAGS_logtostderr = true;
FLAGS_alsologtostderr = true;
FLAGS_colorlogtostderr = true;
FLAGS_log_dir = ".";
// FLAGS_log_dir = ".";
FLAGS_max_log_size = 1024;
FLAGS_stop_logging_if_full_disk = true;

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_MYNTEYE_H_
#define MYNTEYE_MYNTEYE_H_
#pragma once
@@ -45,4 +58,7 @@ MYNTEYE_API_VERSION_CHECK( \
# define MYNTEYE_USE_NAMESPACE
#endif
constexpr char MYNTEYE_SDK_ROOT_DIR[] = "@MYNTEYE_SDK_ROOT_DIR@";
constexpr char MYNTEYE_SDK_INSTALL_DIR[] = "@MYNTEYE_SDK_INSTALL_DIR@";
#endif // MYNTEYE_MYNTEYE_H_

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_TYPES_H_ // NOLINT
#define MYNTEYE_TYPES_H_
#pragma once
@@ -59,21 +72,21 @@ enum class Stream : std::uint8_t {
* might provide.
*/
enum class Capabilities : std::uint8_t {
/** Provices stereo stream */
/** Provides stereo stream */
STEREO,
/** Provices color stream */
/** Provides color stream */
COLOR,
/** Provices depth stream */
/** Provides depth stream */
DEPTH,
/** Provices point cloud stream */
/** Provides point cloud stream */
POINTS,
/** Provices fisheye stream */
/** Provides fisheye stream */
FISHEYE,
/** Provices infrared stream */
/** Provides infrared stream */
INFRARED,
/** Provices second infrared stream */
/** Provides second infrared stream */
INFRARED2,
/** Provices IMU (accelerometer, gyroscope) data */
/** Provides IMU (accelerometer, gyroscope) data */
IMU,
/** Last guard */
LAST
@@ -110,15 +123,35 @@ enum class Info : std::uint8_t {
* @brief Camera control options define general configuration controls.
*/
enum class Option : std::uint8_t {
/** Image gain, setting it if manual-exposure */
/**
* Image gain, valid if manual-exposure
*
* range: [0,48], default: 24
*/
GAIN,
/** Image brightness, setting it if manual-exposure */
/**
* Image brightness, valid if manual-exposure
*
* range: [0,240], default: 120
*/
BRIGHTNESS,
/** Image contrast */
/**
* Image contrast, valid if manual-exposure
*
* range: [0,255], default: 127
*/
CONTRAST,
/** Image frame rate */
/**
* Image frame rate, must set IMU_FREQUENCY together
*
* values: {10,15,20,25,30,35,40,45,50,55,60}, default: 25
*/
FRAME_RATE,
/** IMU frequency */
/**
* IMU frequency, must set FRAME_RATE together
*
* values: {100,200,250,333,500}, default: 200
*/
IMU_FREQUENCY,
/**
* Exposure mode
@@ -127,13 +160,29 @@ enum class Option : std::uint8_t {
* 1: disable auto-exposure (manual-exposure)
*/
EXPOSURE_MODE,
/** Max gain, setting it if auto-exposure */
/**
* Max gain, valid if auto-exposure
*
* range: [0,48], default: 48
*/
MAX_GAIN,
/** Max exposure time, setting it if auto-exposure */
/**
* Max exposure time, valid if auto-exposure
*
* range: [0,240], default: 240
*/
MAX_EXPOSURE_TIME,
/** Desired brightness */
/**
* Desired brightness, valid if auto-exposure
*
* range: [0,255], default: 192
*/
DESIRED_BRIGHTNESS,
/** IR control */
/**
* IR control
*
* range: [0,160], default: 0
*/
IR_CONTROL,
/**
* HDR mode
@@ -165,8 +214,21 @@ enum class Source : std::uint8_t {
LAST
};
/**
* @ingroup enumerations
* @brief Add-Ons are peripheral modules of our hardware.
*/
enum class AddOns : std::uint8_t {
/** Infrared */
INFRARED,
/** Second infrared */
INFRARED2,
/** Last guard */
LAST
};
#define MYNTEYE_ENUM_HELPERS(TYPE) \
const char *to_string(const TYPE &value); \
MYNTEYE_API const char *to_string(const TYPE &value); \
inline bool is_valid(const TYPE &value) { \
using utype = std::underlying_type<TYPE>::type; \
utype val = static_cast<utype>(value); \
@@ -187,6 +249,7 @@ MYNTEYE_ENUM_HELPERS(Capabilities)
MYNTEYE_ENUM_HELPERS(Info)
MYNTEYE_ENUM_HELPERS(Option)
MYNTEYE_ENUM_HELPERS(Source)
MYNTEYE_ENUM_HELPERS(AddOns)
#undef MYNTEYE_ENUM_HELPERS
@@ -209,25 +272,25 @@ enum class Format : std::uint32_t {
#undef MYNTEYE_FOURCC
const char *to_string(const Format &value);
MYNTEYE_API const char *to_string(const Format &value);
inline std::ostream &operator<<(std::ostream &os, const Format &value) {
return os << to_string(value);
}
std::size_t bytes_per_pixel(const Format &value);
MYNTEYE_API std::size_t bytes_per_pixel(const Format &value);
/**
* Stream request.
*/
struct MYNTEYE_API StreamRequest {
/** width in pixels */
/** Stream width in pixels */
std::uint16_t width;
/** height in pixels */
/** Stream height in pixels */
std::uint16_t height;
/** stream pixel format */
/** Stream pixel format */
Format format;
/** frames per second (unused) */
/** Stream frames per second (unused) */
std::uint16_t fps;
bool operator==(const StreamRequest &other) const {
@@ -239,6 +302,7 @@ struct MYNTEYE_API StreamRequest {
}
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const StreamRequest &request);
/**
@@ -248,36 +312,42 @@ std::ostream &operator<<(std::ostream &os, const StreamRequest &request);
/**
* @ingroup calibration
* Image intrinsics.
* Stream intrinsics,
*/
struct MYNTEYE_API ImgIntrinsics {
/** width of the image in pixels */
struct MYNTEYE_API Intrinsics {
/** The width of the image in pixels */
std::uint16_t width;
/** height of the image in pixels */
/** The height of the image in pixels */
std::uint16_t height;
/** focal length of the image plane, as a multiple of pixel width */
/** The focal length of the image plane, as a multiple of pixel width */
double fx;
/** focal length of the image plane, as a multiple of pixel height */
/** The focal length of the image plane, as a multiple of pixel height */
double fy;
/** horizontal coordinate of the principal point of the image */
/** The horizontal coordinate of the principal point of the image */
double cx;
/** vertical coordinate of the principal point of the image */
/** The vertical coordinate of the principal point of the image */
double cy;
/** distortion model of the image */
/** The distortion model of the image */
std::uint8_t model;
/** distortion coefficients: k1,k2,p1,p2,k3 */
/** The distortion coefficients: k1,k2,p1,p2,k3 */
double coeffs[5];
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const Intrinsics &in);
/**
* @ingroup calibration
* IMU sensor intrinsics: scale, drift and variances.
* IMU intrinsics: scale, drift and variances.
*/
struct MYNTEYE_API ImuSensorIntrinsics {
struct MYNTEYE_API ImuIntrinsics {
/**
* Scale X cross axis cross axis
* cross axis Scale Y cross axis
* cross axis cross axis Scale Z
* Scale matrix.
* \code
* Scale X cross axis cross axis
* cross axis Scale Y cross axis
* cross axis cross axis Scale Z
* \endcode
*/
double scale[3][3];
/* Zero-drift: X, Y, Z */
@@ -289,39 +359,43 @@ struct MYNTEYE_API ImuSensorIntrinsics {
double bias[3];
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const ImuIntrinsics &in);
/**
* @ingroup calibration
* IMU intrinsics, including accelerometer and gyroscope.
* Motion intrinsics, including accelerometer and gyroscope.
*/
struct MYNTEYE_API ImuIntrinsics {
ImuSensorIntrinsics accel;
ImuSensorIntrinsics gyro;
struct MYNTEYE_API MotionIntrinsics {
ImuIntrinsics accel; /**< Accelerometer intrinsics */
ImuIntrinsics gyro; /**< Gyroscope intrinsics */
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const MotionIntrinsics &in);
/**
* @ingroup calibration
* Extrinsics, represent how the different datas are connected.
*/
struct MYNTEYE_API Extrinsics {
double rotation[3][3]; /**< rotation matrix */
double translation[3]; /**< translation vector */
double rotation[3][3]; /**< Rotation matrix */
double translation[3]; /**< Translation vector */
/**
* Inverse this extrinsics.
* @return the inversed extrinsics.
*/
Extrinsics Inverse() const {
return {{{rotation[0][0], rotation[1][0], rotation[2][0]},
{rotation[0][1], rotation[1][1], rotation[2][1]},
{rotation[0][2], rotation[1][2], rotation[2][2]}},
{-translation[0], -translation[1], -translation[2]}};
}
};
/**
* @ingroup calibration
* Image extrinsics.
*/
struct MYNTEYE_API ImgExtrinsics {
Extrinsics left_to_right;
};
/**
* @ingroup calibration
* IMU extrinsics.
*/
struct MYNTEYE_API ImuExtrinsics {
Extrinsics left_to_imu;
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const Extrinsics &ex);
/**
* @defgroup datatypes Datatypes
@@ -337,7 +411,7 @@ struct MYNTEYE_API ImgData {
std::uint16_t frame_id;
/** Image timestamp in 0.01ms */
std::uint32_t timestamp;
/** Image exposure time in 0.01ms */
/** Image exposure time, virtual value in [1, 480] */
std::uint16_t exposure_time;
void Reset() {
@@ -396,11 +470,17 @@ struct MYNTEYE_API ImuData {
* Option info.
*/
struct MYNTEYE_API OptionInfo {
/** Minimum value */
std::int32_t min;
/** Maximum value */
std::int32_t max;
/** Default value */
std::int32_t def;
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const OptionInfo &info);
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_TYPES_H_ NOLINT

62
include/mynteye/utils.h Normal file
View File

@@ -0,0 +1,62 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_UTILS_H_ // NOLINT
#define MYNTEYE_UTILS_H_
#pragma once
#include <memory>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
/**
* @defgroup utils Utiliities
*/
class Device;
namespace device {
/**
* @ingroup utils
*
* Detecting MYNT EYE devices and prompt user to select one.
*
* @return the selected device, or `nullptr` if none.
*/
MYNTEYE_API std::shared_ptr<Device> select();
} // namespace device
namespace utils {
/**
* @ingroup utils
*
* Get real exposure time in ms from virtual value, according to its frame rate.
*
* @param frame_rate the frame rate of the device.
* @param exposure_time the virtual exposure time.
* @return the real exposure time in ms, or the virtual value if frame rate is
* invalid.
*/
MYNTEYE_API float get_real_exposure_time(
std::int32_t frame_rate, std::uint16_t exposure_time);
} // namespace utils
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_UTILS_H_ NOLINT

View File

@@ -1,3 +1,17 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/mynteye-targets.cmake")

View File

@@ -1,13 +1,39 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
cmake_minimum_required(VERSION 3.0)
project(mynteye_samples VERSION 2.0.0 LANGUAGES C CXX)
get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
include(${PRO_DIR}/cmake/Common.cmake)
include(${PRO_DIR}/cmake/Utils.cmake)
# options
include(${PRO_DIR}/cmake/Option.cmake)
# flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if(OS_WIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
include(${PRO_DIR}/cmake/DetectCXX11.cmake)
@@ -29,17 +55,20 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
find_package(mynteye REQUIRED)
message(STATUS "Found mynteye: ${mynteye_VERSION}")
LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
include(${PRO_DIR}/cmake/DetectOpenCV.cmake)
find_package(OpenCV REQUIRED)
message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
#LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
# targets
include(${PRO_DIR}/cmake/Common.cmake)
set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output")
# samples above api layer
if(WITH_API)
add_subdirectory(api)
endif()
# samples above device layer
add_subdirectory(device)
@@ -47,3 +76,7 @@ add_subdirectory(device)
# samples above uvc layer
add_subdirectory(uvc)
# tutorials
add_subdirectory(tutorials)

View File

@@ -1,5 +1,17 @@
# Samples for MYNT® EYE cameras
## Prerequisites
[OpenCV](https://opencv.org/),
```bash
# Linux, macOS
export OpenCV_DIR=~/opencv
# Windows
set OpenCV_DIR=C:\opencv
```
## Build
```bash
@@ -9,6 +21,20 @@ make samples
## Run
Camera with api layer,
```bash
./samples/_output/bin/device/camera_d
./samples/_output/bin/api/camera_a
# Windows
.\samples\_output\bin\api\camera_a.bat
```
Camera with device layer,
```bash
./samples/_output/bin/device/camera_d
# Windows
.\samples\_output\bin\device\camera_d.bat
```

View File

@@ -0,0 +1,41 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
set_outdir(
"${OUT_DIR}/lib/${DIR_NAME}"
"${OUT_DIR}/lib/${DIR_NAME}"
"${OUT_DIR}/bin/${DIR_NAME}"
)
## camera_a
make_executable(camera_a
SRCS camera.cc
LINK_LIBS mynteye ${OpenCV_LIBS}
DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
)
## get_depth_with_region
if(OpenCV_VERSION VERSION_LESS 4.0)
make_executable(get_depth_with_region
SRCS get_depth_with_region.cc
LINK_LIBS mynteye ${OpenCV_LIBS}
DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
)
endif()

144
samples/api/camera.cc Normal file
View File

@@ -0,0 +1,144 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#include "mynteye/times.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// api->SetOptionValue(Option::FRAME_RATE, 25);
// api->SetOptionValue(Option::IMU_FREQUENCY, 500);
api->SetOptionValue(Option::IR_CONTROL, 80);
api->LogOptionInfos();
std::size_t left_count = 0;
api->SetStreamCallback(
Stream::LEFT, [&left_count](const api::StreamData &data) {
CHECK_NOTNULL(data.img);
++left_count;
VLOG(2) << Stream::LEFT << ", count: " << left_count;
VLOG(2) << " frame_id: " << data.img->frame_id
<< ", timestamp: " << data.img->timestamp
<< ", exposure_time: " << data.img->exposure_time;
});
std::size_t right_count = 0;
api->SetStreamCallback(
Stream::RIGHT, [&right_count](const api::StreamData &data) {
CHECK_NOTNULL(data.img);
++right_count;
VLOG(2) << Stream::RIGHT << ", count: " << right_count;
VLOG(2) << " frame_id: " << data.img->frame_id
<< ", timestamp: " << data.img->timestamp
<< ", exposure_time: " << data.img->exposure_time;
});
std::size_t imu_count = 0;
api->SetMotionCallback([&imu_count](const api::MotionData &data) {
CHECK_NOTNULL(data.imu);
++imu_count;
VLOG(2) << "Imu count: " << imu_count;
VLOG(2) << " frame_id: " << data.imu->frame_id
<< ", timestamp: " << data.imu->timestamp
<< ", accel_x: " << data.imu->accel[0]
<< ", accel_y: " << data.imu->accel[1]
<< ", accel_z: " << data.imu->accel[2]
<< ", gyro_x: " << data.imu->gyro[0]
<< ", gyro_y: " << data.imu->gyro[1]
<< ", gyro_z: " << data.imu->gyro[2]
<< ", temperature: " << data.imu->temperature;
});
// api->EnableStreamData(Stream::LEFT_RECTIFIED);
// api->EnableStreamData(Stream::RIGHT_RECTIFIED);
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
api->EnableStreamData(Stream::DEPTH);
// Enable this will cache the motion datas until you get them.
api->EnableMotionDatas();
api->Start(Source::ALL);
cv::namedWindow("frame");
cv::namedWindow("disparity");
cv::namedWindow("depth");
std::size_t motion_count = 0;
auto &&time_beg = times::now();
while (true) {
api->WaitForStreams();
// auto &&left_data = api->GetStreamData(Stream::LEFT);
// auto &&right_data = api->GetStreamData(Stream::RIGHT);
auto &&left_data = api->GetStreamData(Stream::LEFT_RECTIFIED);
auto &&right_data = api->GetStreamData(Stream::RIGHT_RECTIFIED);
if (!left_data.frame.empty() && !right_data.frame.empty()) {
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
}
auto &&disp_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
if (!disp_data.frame.empty()) {
cv::imshow("disparity", disp_data.frame); // CV_8UC1
}
auto &&depth_data = api->GetStreamData(Stream::DEPTH);
if (!depth_data.frame.empty()) {
cv::imshow("depth", depth_data.frame); // CV_16UC1
}
auto &&motion_datas = api->GetMotionDatas();
motion_count += motion_datas.size();
for (auto &&data : motion_datas) {
LOG(INFO) << "Imu frame_id: " << data.imu->frame_id
<< ", timestamp: " << data.imu->timestamp
<< ", accel_x: " << data.imu->accel[0]
<< ", accel_y: " << data.imu->accel[1]
<< ", accel_z: " << data.imu->accel[2]
<< ", gyro_x: " << data.imu->gyro[0]
<< ", gyro_y: " << data.imu->gyro[1]
<< ", gyro_z: " << data.imu->gyro[2]
<< ", temperature: " << data.imu->temperature;
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
auto &&time_end = times::now();
api->Stop(Source::ALL);
float elapsed_ms =
times::count<times::microseconds>(time_end - time_beg) * 0.001f;
LOG(INFO) << "Time beg: " << times::to_local_string(time_beg)
<< ", end: " << times::to_local_string(time_end)
<< ", cost: " << elapsed_ms << "ms";
LOG(INFO) << "Left count: " << left_count
<< ", fps: " << (1000.f * left_count / elapsed_ms);
LOG(INFO) << "Right count: " << right_count
<< ", fps: " << (1000.f * right_count / elapsed_ms);
LOG(INFO) << "Imu count: " << imu_count
<< ", hz: " << (1000.f * imu_count / elapsed_ms);
// LOG(INFO) << "Motion count: " << motion_count
// << ", hz: " << (1000.f * motion_count / elapsed_ms);
return 0;
}

View File

@@ -0,0 +1,227 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#define WIN_FLAGS \
cv::WINDOW_AUTOSIZE | cv::WINDOW_KEEPRATIO | cv::WINDOW_GUI_NORMAL
namespace {
class DepthRegion {
public:
explicit DepthRegion(std::uint32_t n)
: n_(std::move(n)), show_(false), selected_(false), point_(0, 0) {}
~DepthRegion() = default;
/**
* 鼠标事件:默认不选中区域,随鼠标移动而显示。单击后,则会选中区域来显示。你可以再单击已选中区域或双击未选中区域,取消选中。
*/
void OnMouse(const int &event, const int &x, const int &y, const int &flags) {
UNUSED(flags)
if (event != CV_EVENT_MOUSEMOVE && event != CV_EVENT_LBUTTONDOWN) {
return;
}
show_ = true;
if (event == CV_EVENT_MOUSEMOVE) {
if (!selected_) {
point_.x = x;
point_.y = y;
}
} else if (event == CV_EVENT_LBUTTONDOWN) {
if (selected_) {
if (x >= static_cast<int>(point_.x - n_) &&
x <= static_cast<int>(point_.x + n_) &&
y >= static_cast<int>(point_.y - n_) &&
y <= static_cast<int>(point_.y + n_)) {
selected_ = false;
}
} else {
selected_ = true;
}
point_.x = x;
point_.y = y;
}
}
template <typename T>
void ShowElems(
const cv::Mat &depth,
std::function<std::string(const T &elem)> elem2string,
int elem_space = 40,
std::function<std::string(
const cv::Mat &depth, const cv::Point &point, const std::uint32_t &n)>
getinfo = nullptr) {
if (!show_)
return;
int space = std::move(elem_space);
int n = 2 * n_ + 1;
cv::Mat im(space * n, space * n, CV_8UC3, cv::Scalar(255, 255, 255));
int x, y;
std::string str;
int baseline = 0;
for (int i = -n_; i <= n; ++i) {
x = point_.x + i;
if (x < 0 || x >= depth.cols)
continue;
for (int j = -n_; j <= n; ++j) {
y = point_.y + j;
if (y < 0 || y >= depth.rows)
continue;
str = elem2string(depth.at<T>(y, x));
cv::Scalar color(0, 0, 0);
if (i == 0 && j == 0)
color = cv::Scalar(0, 0, 255);
cv::Size sz =
cv::getTextSize(str, cv::FONT_HERSHEY_PLAIN, 1, 1, &baseline);
cv::putText(
im, str, cv::Point(
(i + n_) * space + (space - sz.width) / 2,
(j + n_) * space + (space + sz.height) / 2),
cv::FONT_HERSHEY_PLAIN, 1, color, 1);
}
}
if (getinfo) {
std::string info = getinfo(depth, point_, n_);
if (!info.empty()) {
cv::Size sz =
cv::getTextSize(info, cv::FONT_HERSHEY_PLAIN, 1, 1, &baseline);
cv::putText(
im, info, cv::Point(5, 5 + sz.height), cv::FONT_HERSHEY_PLAIN, 1,
cv::Scalar(255, 0, 255), 1);
}
}
cv::imshow("region", im);
}
void DrawRect(cv::Mat &image) { // NOLINT
if (!show_)
return;
std::uint32_t n = (n_ > 1) ? n_ : 1;
n += 1; // outside the region
cv::rectangle(
image, cv::Point(point_.x - n, point_.y - n),
cv::Point(point_.x + n, point_.y + n),
selected_ ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), 1);
}
private:
std::uint32_t n_;
bool show_;
bool selected_;
cv::Point point_;
};
void OnDepthMouseCallback(int event, int x, int y, int flags, void *userdata) {
DepthRegion *region = reinterpret_cast<DepthRegion *>(userdata);
region->OnMouse(event, x, y, flags);
}
} // namespace
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->SetOptionValue(Option::IR_CONTROL, 80);
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
api->EnableStreamData(Stream::DEPTH);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame", WIN_FLAGS);
cv::namedWindow("depth", WIN_FLAGS);
cv::namedWindow("region", WIN_FLAGS);
DepthRegion depth_region(3);
auto depth_info = [](
const cv::Mat &depth, const cv::Point &point, const std::uint32_t &n) {
UNUSED(depth)
std::ostringstream os;
os << "depth pos: [" << point.y << ", " << point.x << "]"
<< "±" << n << ", unit: mm";
return os.str();
};
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
auto &&disp_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
auto &&depth_data = api->GetStreamData(Stream::DEPTH);
if (!disp_data.frame.empty() && !depth_data.frame.empty()) {
// Show disparity instead of depth, but show depth values in region.
auto &&depth_frame = disp_data.frame;
#ifdef USE_OPENCV3
// ColormapTypes
// http://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65
cv::applyColorMap(depth_frame, depth_frame, cv::COLORMAP_JET);
#endif
cv::setMouseCallback("depth", OnDepthMouseCallback, &depth_region);
// Note: DrawRect will change some depth values to show the rect.
depth_region.DrawRect(depth_frame);
cv::imshow("depth", depth_frame);
depth_region.ShowElems<ushort>(
depth_data.frame,
[](const ushort &elem) {
if (elem >= 10000) {
// Filter errors, or limit to valid range.
//
// reprojectImageTo3D(), missing values will set to 10000
// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga1bc1152bd57d63bc524204f21fde6e02
return std::string("invalid");
}
return std::to_string(elem);
},
80, depth_info);
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -1,3 +1,17 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
set_outdir(
@@ -6,17 +20,10 @@ set_outdir(
"${OUT_DIR}/bin/${DIR_NAME}"
)
include_directories(
${PRO_DIR}/src
)
## camera_d
add_executable(camera_d camera.cc)
target_link_libraries(camera_d mynteye ${OpenCV_LIBS})
if(OS_WIN)
target_compile_definitions(camera_d
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()
make_executable(camera_d
SRCS camera.cc
LINK_LIBS mynteye ${OpenCV_LIBS}
DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
)

View File

@@ -1,50 +1,34 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "mynteye/glog_init.h"
#include "device/context.h"
#include "device/device.h"
#include "mynteye/device.h"
#include "mynteye/utils.h"
#include "internal/times.h"
#include "mynteye/times.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
glog_init _(argc, argv);
LOG(INFO) << "Detecting MYNT EYE devices";
Context context;
auto &&devices = context.devices();
size_t n = devices.size();
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
LOG(INFO) << "MYNT EYE devices:";
for (size_t i = 0; i < n; i++) {
auto &&device = devices[i];
auto &&name = device->GetInfo(Info::DEVICE_NAME);
LOG(INFO) << " index: " << i << ", name: " << name;
}
std::shared_ptr<Device> device = nullptr;
if (n <= 1) {
device = devices[0];
LOG(INFO) << "Only one MYNT EYE device, select index: 0";
} else {
while (true) {
size_t i;
LOG(INFO) << "There are " << n << " MYNT EYE devices, select index: ";
std::cin >> i;
if (i >= n) {
LOG(WARNING) << "Index out of range :(";
continue;
}
device = devices[i];
break;
}
}
auto &&device = device::select();
if (!device)
return 1;
/*
{ // auto-exposure
device->SetOptionValue(Option::EXPOSURE_MODE, 0);

View File

@@ -0,0 +1,144 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
set_outdir(
"${OUT_DIR}/lib/${DIR_NAME}"
"${OUT_DIR}/lib/${DIR_NAME}"
"${OUT_DIR}/bin/${DIR_NAME}"
)
# make_executable2(NAME
# [SRCS src1 src2 ...]
# [WITH_OPENCV]
# [WITH_PCL])
macro(make_executable2 NAME)
set(options WITH_OPENCV WITH_PCL)
set(oneValueArgs)
set(multiValueArgs SRCS)
cmake_parse_arguments(THIS "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
set(__link_libs mynteye)
set(__dll_search_paths ${PRO_DIR}/_install/bin)
if(THIS_WITH_OPENCV)
list(APPEND __link_libs ${OpenCV_LIBS})
list(APPEND __dll_search_paths ${OpenCV_LIB_SEARCH_PATH})
endif()
if(THIS_WITH_PCL)
list(APPEND __link_libs ${PCL_LIBRARIES})
#list(APPEND __link_libs pcl::pcl)
list(APPEND __dll_search_paths ${PCL_LIB_SEARCH_PATH})
endif()
add_executable(${NAME} ${THIS_SRCS})
target_link_libraries(${NAME} ${__link_libs})
target_create_scripts(${NAME} DLL_SEARCH_PATHS ${__dll_search_paths})
if(THIS_WITH_PCL)
target_include_directories(${NAME} PRIVATE ${PCL_INCLUDE_DIRS})
#target_compile_definitions(${NAME} PRIVATE ${PCL_DEFINITIONS})
#target_compile_options(${NAME} PRIVATE ${PCL_COMPILE_OPTIONS})
endif()
if(OS_WIN)
target_compile_definitions(${NAME}
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()
endmacro()
if(WITH_API)
# If you install PCL to different directory, please set CMAKE_PREFIX_PATH to find it.
#LIST(APPEND CMAKE_PREFIX_PATH /usr/local/share)
find_package(PCL)
if(PCL_FOUND)
message(STATUS "Found PCL: ${PCL_VERSION}")
#message(STATUS "PCL_LIBRARIES: ${PCL_LIBRARIES}")
#message(STATUS "PCL_INCLUDE_DIRS: ${PCL_INCLUDE_DIRS}")
#message(STATUS "PCL_LIBRARY_DIRS: ${PCL_LIBRARY_DIRS}")
#message(STATUS "PCL_DEFINITIONS: ${PCL_DEFINITIONS}")
#message(STATUS "PCL_COMPILE_OPTIONS: ${PCL_COMPILE_OPTIONS}")
if(OS_WIN)
get_filename_component(PCL_LIB_SEARCH_PATH "${PCL_LIBRARY_DIRS}/../bin" ABSOLUTE)
else()
set(PCL_LIB_SEARCH_PATH "${PCL_LIBRARY_DIRS}")
endif()
else()
message(WARNING "PCL not found :(")
endif()
# beginner level
## data
make_executable2(get_device_info SRCS data/get_device_info.cc WITH_OPENCV)
make_executable2(get_img_params SRCS data/get_img_params.cc WITH_OPENCV)
make_executable2(get_imu_params SRCS data/get_imu_params.cc WITH_OPENCV)
make_executable2(get_stereo SRCS data/get_stereo.cc WITH_OPENCV)
make_executable2(get_stereo_rectified SRCS data/get_stereo_rectified.cc WITH_OPENCV)
make_executable2(get_disparity SRCS data/get_disparity.cc WITH_OPENCV)
make_executable2(get_depth SRCS data/get_depth.cc WITH_OPENCV)
if(PCL_FOUND)
make_executable2(get_points
SRCS data/get_points.cc util/pc_viewer.cc
WITH_OPENCV WITH_PCL
)
endif()
make_executable2(get_imu SRCS data/get_imu.cc util/cv_painter.cc WITH_OPENCV)
make_executable2(get_from_callbacks
SRCS data/get_from_callbacks.cc util/cv_painter.cc
WITH_OPENCV
)
make_executable2(get_with_plugin SRCS data/get_with_plugin.cc WITH_OPENCV)
## control
make_executable2(ctrl_framerate SRCS control/framerate.cc WITH_OPENCV)
make_executable2(ctrl_auto_exposure
SRCS control/auto_exposure.cc util/cv_painter.cc
WITH_OPENCV
)
make_executable2(ctrl_manual_exposure
SRCS control/manual_exposure.cc util/cv_painter.cc
WITH_OPENCV
)
make_executable2(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV)
endif()
# intermediate level
if(PCL_FOUND)
if(OpenCV_VERSION VERSION_LESS 4.0)
make_executable2(get_depth_and_points
SRCS intermediate/get_depth_and_points.cc util/cv_painter.cc util/pc_viewer.cc
WITH_OPENCV WITH_PCL
)
endif()
endif()
# advanced level

View File

@@ -0,0 +1,71 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#include "util/cv_painter.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// auto-exposure: 0
api->SetOptionValue(Option::EXPOSURE_MODE, 0);
// max_gain: range [0,48], default 48
api->SetOptionValue(Option::MAX_GAIN, 48);
// max_exposure_time: range [0,240], default 240
api->SetOptionValue(Option::MAX_EXPOSURE_TIME, 240);
// desired_brightness: range [0,255], default 192
api->SetOptionValue(Option::DESIRED_BRIGHTNESS, 192);
LOG(INFO) << "Enable auto-exposure";
LOG(INFO) << "Set MAX_GAIN to " << api->GetOptionValue(Option::MAX_GAIN);
LOG(INFO) << "Set MAX_EXPOSURE_TIME to "
<< api->GetOptionValue(Option::MAX_EXPOSURE_TIME);
LOG(INFO) << "Set DESIRED_BRIGHTNESS to "
<< api->GetOptionValue(Option::DESIRED_BRIGHTNESS);
api->Start(Source::VIDEO_STREAMING);
CVPainter painter(api->GetOptionValue(Option::FRAME_RATE));
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
painter.DrawImgData(img, *left_data.img);
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,92 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include <atomic>
#include "mynteye/api.h"
#include "mynteye/times.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Attention: must set FRAME_RATE and IMU_FREQUENCY together, otherwise won't
// succeed.
// FRAME_RATE values: 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60
api->SetOptionValue(Option::FRAME_RATE, 25);
// IMU_FREQUENCY values: 100, 200, 250, 333, 500
api->SetOptionValue(Option::IMU_FREQUENCY, 500);
LOG(INFO) << "Set FRAME_RATE to " << api->GetOptionValue(Option::FRAME_RATE);
LOG(INFO) << "Set IMU_FREQUENCY to "
<< api->GetOptionValue(Option::IMU_FREQUENCY);
// Count img
std::atomic_uint img_count(0);
api->SetStreamCallback(
Stream::LEFT, [&img_count](const api::StreamData &data) {
CHECK_NOTNULL(data.img);
++img_count;
});
// Count imu
std::atomic_uint imu_count(0);
api->SetMotionCallback([&imu_count](const api::MotionData &data) {
CHECK_NOTNULL(data.imu);
++imu_count;
});
api->Start(Source::ALL);
cv::namedWindow("frame");
auto &&time_beg = times::now();
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
auto &&time_end = times::now();
api->Stop(Source::ALL);
// Calculate img fps and imu hz
float elapsed_ms =
times::count<times::microseconds>(time_end - time_beg) * 0.001f;
LOG(INFO) << "Time beg: " << times::to_local_string(time_beg)
<< ", end: " << times::to_local_string(time_end)
<< ", cost: " << elapsed_ms << "ms";
LOG(INFO) << "Img count: " << img_count
<< ", fps: " << (1000.f * img_count / elapsed_ms);
LOG(INFO) << "Imu count: " << imu_count
<< ", hz: " << (1000.f * imu_count / elapsed_ms);
return 0;
}

View File

@@ -0,0 +1,62 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Detect infrared add-ons
LOG(INFO) << "Support infrared: " << std::boolalpha
<< api->Supports(AddOns::INFRARED);
LOG(INFO) << "Support infrared2: " << std::boolalpha
<< api->Supports(AddOns::INFRARED2);
// Get infrared intensity range
auto &&info = api->GetOptionInfo(Option::IR_CONTROL);
LOG(INFO) << Option::IR_CONTROL << ": {" << info << "}";
// Set infrared intensity value
api->SetOptionValue(Option::IR_CONTROL, 80);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,69 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#include "util/cv_painter.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// manual-exposure: 1
api->SetOptionValue(Option::EXPOSURE_MODE, 1);
// gain: range [0,48], default 24
api->SetOptionValue(Option::GAIN, 24);
// brightness/exposure_time: range [0,240], default 120
api->SetOptionValue(Option::BRIGHTNESS, 120);
// contrast/black_level_calibration: range [0,255], default 127
api->SetOptionValue(Option::CONTRAST, 127);
LOG(INFO) << "Enable manual-exposure";
LOG(INFO) << "Set GAIN to " << api->GetOptionValue(Option::GAIN);
LOG(INFO) << "Set BRIGHTNESS to " << api->GetOptionValue(Option::BRIGHTNESS);
LOG(INFO) << "Set CONTRAST to " << api->GetOptionValue(Option::CONTRAST);
api->Start(Source::VIDEO_STREAMING);
CVPainter painter(api->GetOptionValue(Option::FRAME_RATE));
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
painter.DrawImgData(img, *left_data.img);
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,57 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnableStreamData(Stream::DEPTH);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
cv::namedWindow("depth");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
auto &&depth_data = api->GetStreamData(Stream::DEPTH);
if (!depth_data.frame.empty()) {
cv::imshow("depth", depth_data.frame); // CV_16UC1
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,35 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
LOG(INFO) << "Device name: " << api->GetInfo(Info::DEVICE_NAME);
LOG(INFO) << "Serial number: " << api->GetInfo(Info::SERIAL_NUMBER);
LOG(INFO) << "Firmware version: " << api->GetInfo(Info::FIRMWARE_VERSION);
LOG(INFO) << "Hardware version: " << api->GetInfo(Info::HARDWARE_VERSION);
LOG(INFO) << "Spec version: " << api->GetInfo(Info::SPEC_VERSION);
LOG(INFO) << "Lens type: " << api->GetInfo(Info::LENS_TYPE);
LOG(INFO) << "IMU type: " << api->GetInfo(Info::IMU_TYPE);
LOG(INFO) << "Nominal baseline: " << api->GetInfo(Info::NOMINAL_BASELINE);
return 0;
}

View File

@@ -0,0 +1,64 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// api->EnableStreamData(Stream::DISPARITY);
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
// cv::namedWindow("disparity");
cv::namedWindow("disparity_normalized");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
// auto &&disp_data = api->GetStreamData(Stream::DISPARITY);
// if (!disp_data.frame.empty()) {
// cv::imshow("disparity", disp_data.frame);
// }
auto &&disp_norm_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
if (!disp_norm_data.frame.empty()) {
cv::imshow("disparity_normalized", disp_norm_data.frame); // CV_8UC1
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,148 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include <atomic>
#include <memory>
#include <mutex>
#include <sstream>
#include "mynteye/api.h"
#include "util/cv_painter.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Attention: must not block the callbacks.
// Get left image from callback
std::atomic_uint left_count(0);
api->SetStreamCallback(
Stream::LEFT, [&left_count](const api::StreamData &data) {
CHECK_NOTNULL(data.img);
++left_count;
// LOG(INFO) << Stream::LEFT << ", count: " << left_count;
// LOG(INFO) << " frame_id: " << data.img->frame_id
// << ", timestamp: " << data.img->timestamp
// << ", exposure_time: " << data.img->exposure_time;
});
// Get depth image from callback
api->EnableStreamData(Stream::DEPTH);
std::atomic_uint depth_count(0);
cv::Mat depth;
std::mutex depth_mtx;
api->SetStreamCallback(
Stream::DEPTH,
[&depth_count, &depth, &depth_mtx](const api::StreamData &data) {
UNUSED(data)
++depth_count;
{
std::lock_guard<std::mutex> _(depth_mtx);
depth = data.frame;
}
// LOG(INFO) << Stream::DEPTH << ", count: " << depth_count;
});
// Get motion data from callback
std::atomic_uint imu_count(0);
std::shared_ptr<mynteye::ImuData> imu;
std::mutex imu_mtx;
api->SetMotionCallback(
[&imu_count, &imu, &imu_mtx](const api::MotionData &data) {
CHECK_NOTNULL(data.imu);
++imu_count;
{
std::lock_guard<std::mutex> _(imu_mtx);
imu = data.imu;
}
// LOG(INFO) << "Imu count: " << imu_count;
// LOG(INFO) << " frame_id: " << data.imu->frame_id
// << ", timestamp: " << data.imu->timestamp
// << ", accel_x: " << data.imu->accel[0]
// << ", accel_y: " << data.imu->accel[1]
// << ", accel_z: " << data.imu->accel[2]
// << ", gyro_x: " << data.imu->gyro[0]
// << ", gyro_y: " << data.imu->gyro[1]
// << ", gyro_z: " << data.imu->gyro[2]
// << ", temperature: " << data.imu->temperature;
});
api->Start(Source::ALL);
CVPainter painter;
cv::namedWindow("frame");
cv::namedWindow("depth");
unsigned int depth_num = 0;
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
// Concat left and right as img
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
// Draw img data and size
painter.DrawImgData(img, *left_data.img);
// Draw imu data
if (imu) {
std::lock_guard<std::mutex> _(imu_mtx);
painter.DrawImuData(img, *imu);
}
// Draw counts
std::ostringstream ss;
ss << "left: " << left_count << ", depth: " << depth_count
<< ", imu: " << imu_count;
painter.DrawText(img, ss.str(), CVPainter::BOTTOM_RIGHT);
// Show img
cv::imshow("frame", img);
// Show depth
if (!depth.empty()) {
// Is the depth a new one?
if (depth_num != depth_count || depth_num == 0) {
std::lock_guard<std::mutex> _(depth_mtx);
depth_num = depth_count;
// LOG(INFO) << "depth_num: " << depth_num;
ss.str("");
ss.clear();
ss << "depth: " << depth_count;
painter.DrawText(depth, ss.str());
cv::imshow("depth", depth); // CV_16UC1
}
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::ALL);
return 0;
}

View File

@@ -0,0 +1,32 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}";
LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT)
<< "}";
LOG(INFO) << "Extrinsics left to right: {"
<< api->GetExtrinsics(Stream::LEFT, Stream::RIGHT) << "}";
return 0;
}

View File

@@ -0,0 +1,77 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#include "util/cv_painter.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Enable this will cache the motion datas until you get them.
api->EnableMotionDatas();
api->Start(Source::ALL);
CVPainter painter;
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
auto &&motion_datas = api->GetMotionDatas();
/*
for (auto &&data : motion_datas) {
LOG(INFO) << "Imu frame_id: " << data.imu->frame_id
<< ", timestamp: " << data.imu->timestamp
<< ", accel_x: " << data.imu->accel[0]
<< ", accel_y: " << data.imu->accel[1]
<< ", accel_z: " << data.imu->accel[2]
<< ", gyro_x: " << data.imu->gyro[0]
<< ", gyro_y: " << data.imu->gyro[1]
<< ", gyro_z: " << data.imu->gyro[2]
<< ", temperature: " << data.imu->temperature;
}
*/
painter.DrawImgData(img, *left_data.img);
if (!motion_datas.empty()) {
painter.DrawImuData(img, *motion_datas[0].imu);
}
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::ALL);
return 0;
}

View File

@@ -0,0 +1,30 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
LOG(INFO) << "Motion intrinsics: {" << api->GetMotionIntrinsics() << "}";
LOG(INFO) << "Motion extrinsics left to imu: {"
<< api->GetMotionExtrinsics(Stream::LEFT) << "}";
return 0;
}

View File

@@ -0,0 +1,62 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#include "util/pc_viewer.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnableStreamData(Stream::POINTS);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
PCViewer pcviewer;
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
auto &&points_data = api->GetStreamData(Stream::POINTS);
if (!points_data.frame.empty()) {
pcviewer.Update(points_data.frame);
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
if (pcviewer.WasStopped()) {
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,49 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,54 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnableStreamData(Stream::LEFT_RECTIFIED);
api->EnableStreamData(Stream::RIGHT_RECTIFIED);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT_RECTIFIED);
auto &&right_data = api->GetStreamData(Stream::RIGHT_RECTIFIED);
if (!left_data.frame.empty() && !right_data.frame.empty()) {
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,59 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnablePlugin("plugins/linux-x86_64/libplugin_g_cuda9.1_opencv3.4.0.so");
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
cv::namedWindow("disparity");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
auto &&disp_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
if (!disp_data.frame.empty()) {
cv::imshow("disparity", disp_data.frame);
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::ALL);
return 0;
}

View File

@@ -0,0 +1,244 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <glog/logging.h>
#include "mynteye/api.h"
#include "util/cv_painter.h"
#include "util/pc_viewer.h"
#define WIN_FLAGS \
cv::WINDOW_AUTOSIZE | cv::WINDOW_KEEPRATIO | cv::WINDOW_GUI_NORMAL
namespace {
class DepthRegion {
public:
explicit DepthRegion(std::uint32_t n)
: n_(std::move(n)), show_(false), selected_(false), point_(0, 0) {}
~DepthRegion() = default;
/**
* 鼠标事件:默认不选中区域,随鼠标移动而显示。单击后,则会选中区域来显示。你可以再单击已选中区域或双击未选中区域,取消选中。
*/
void OnMouse(const int &event, const int &x, const int &y, const int &flags) {
UNUSED(flags)
if (event != CV_EVENT_MOUSEMOVE && event != CV_EVENT_LBUTTONDOWN) {
return;
}
show_ = true;
if (event == CV_EVENT_MOUSEMOVE) {
if (!selected_) {
point_.x = x;
point_.y = y;
}
} else if (event == CV_EVENT_LBUTTONDOWN) {
if (selected_) {
if (x >= static_cast<int>(point_.x - n_) &&
x <= static_cast<int>(point_.x + n_) &&
y >= static_cast<int>(point_.y - n_) &&
y <= static_cast<int>(point_.y + n_)) {
selected_ = false;
}
} else {
selected_ = true;
}
point_.x = x;
point_.y = y;
}
}
template <typename T>
void ShowElems(
const cv::Mat &depth,
std::function<std::string(const T &elem)> elem2string,
int elem_space = 40,
std::function<std::string(
const cv::Mat &depth, const cv::Point &point, const std::uint32_t &n)>
getinfo = nullptr) {
if (!show_)
return;
int space = std::move(elem_space);
int n = 2 * n_ + 1;
cv::Mat im(space * n, space * n, CV_8UC3, cv::Scalar(255, 255, 255));
int x, y;
std::string str;
int baseline = 0;
for (int i = -n_; i <= n; ++i) {
x = point_.x + i;
if (x < 0 || x >= depth.cols)
continue;
for (int j = -n_; j <= n; ++j) {
y = point_.y + j;
if (y < 0 || y >= depth.rows)
continue;
str = elem2string(depth.at<T>(y, x));
cv::Scalar color(0, 0, 0);
if (i == 0 && j == 0)
color = cv::Scalar(0, 0, 255);
cv::Size sz =
cv::getTextSize(str, cv::FONT_HERSHEY_PLAIN, 1, 1, &baseline);
cv::putText(
im, str, cv::Point(
(i + n_) * space + (space - sz.width) / 2,
(j + n_) * space + (space + sz.height) / 2),
cv::FONT_HERSHEY_PLAIN, 1, color, 1);
}
}
if (getinfo) {
std::string info = getinfo(depth, point_, n_);
if (!info.empty()) {
cv::Size sz =
cv::getTextSize(info, cv::FONT_HERSHEY_PLAIN, 1, 1, &baseline);
cv::putText(
im, info, cv::Point(5, 5 + sz.height), cv::FONT_HERSHEY_PLAIN, 1,
cv::Scalar(255, 0, 255), 1);
}
}
cv::imshow("region", im);
}
void DrawRect(cv::Mat &image) { // NOLINT
if (!show_)
return;
std::uint32_t n = (n_ > 1) ? n_ : 1;
n += 1; // outside the region
cv::rectangle(
image, cv::Point(point_.x - n, point_.y - n),
cv::Point(point_.x + n, point_.y + n),
selected_ ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), 1);
}
private:
std::uint32_t n_;
bool show_;
bool selected_;
cv::Point point_;
};
void OnDepthMouseCallback(int event, int x, int y, int flags, void *userdata) {
DepthRegion *region = reinterpret_cast<DepthRegion *>(userdata);
region->OnMouse(event, x, y, flags);
}
} // namespace
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->SetOptionValue(Option::IR_CONTROL, 80);
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
api->EnableStreamData(Stream::DEPTH);
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame", WIN_FLAGS);
cv::namedWindow("depth", WIN_FLAGS);
cv::namedWindow("region", WIN_FLAGS);
DepthRegion depth_region(3);
auto depth_info = [](
const cv::Mat &depth, const cv::Point &point, const std::uint32_t &n) {
UNUSED(depth)
std::ostringstream os;
os << "depth pos: [" << point.y << ", " << point.x << "]"
<< "±" << n << ", unit: mm";
return os.str();
};
CVPainter painter;
PCViewer pcviewer;
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
painter.DrawImgData(img, *left_data.img);
cv::imshow("frame", img);
auto &&disp_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
auto &&depth_data = api->GetStreamData(Stream::DEPTH);
if (!disp_data.frame.empty() && !depth_data.frame.empty()) {
// Show disparity instead of depth, but show depth values in region.
auto &&depth_frame = disp_data.frame;
#ifdef USE_OPENCV3
// ColormapTypes
// http://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65
cv::applyColorMap(depth_frame, depth_frame, cv::COLORMAP_JET);
#endif
cv::setMouseCallback("depth", OnDepthMouseCallback, &depth_region);
// Note: DrawRect will change some depth values to show the rect.
depth_region.DrawRect(depth_frame);
cv::imshow("depth", depth_frame);
depth_region.ShowElems<ushort>(
depth_data.frame,
[](const ushort &elem) {
if (elem >= 10000) {
// Filter errors, or limit to valid range.
//
// reprojectImageTo3D(), missing values will set to 10000
// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga1bc1152bd57d63bc524204f21fde6e02
return std::string("invalid");
}
return std::to_string(elem);
},
80, depth_info);
}
auto &&points_data = api->GetStreamData(Stream::POINTS);
if (!points_data.frame.empty()) {
pcviewer.Update(points_data.frame);
}
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
if (pcviewer.WasStopped()) {
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@@ -0,0 +1,190 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "util/cv_painter.h"
#include <glog/logging.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <iomanip>
#include <iostream>
#include <memory>
#include <utility>
#include "mynteye/utils.h"
#define FONT_FACE cv::FONT_HERSHEY_PLAIN
#define FONT_SCALE 1
#define FONT_COLOR cv::Scalar(255, 255, 255)
#define THICKNESS 1
namespace {
std::shared_ptr<std::ios> NewFormat(int width, int prec, char fillch = ' ') {
auto fmt = std::make_shared<std::ios>(nullptr);
fmt->setf(std::ios::fixed);
if (width > 0)
fmt->width(std::move(width));
if (prec > 0)
fmt->precision(std::move(prec));
fmt->fill(std::move(fillch));
return fmt;
}
std::ostringstream &Clear(std::ostringstream &os) {
os.str("");
os.clear();
return os;
}
} // namespace
std::ostream &operator<<(
std::ostream &os, const std::shared_ptr<std::ios> &fmt) {
if (fmt)
os.copyfmt(*fmt);
return os;
}
CVPainter::CVPainter(std::int32_t frame_rate)
: frame_rate_(std::move(frame_rate)) {
VLOG(2) << __func__;
}
CVPainter::~CVPainter() {
VLOG(2) << __func__;
}
cv::Rect CVPainter::DrawSize(const cv::Mat &img, const gravity_t &gravity) {
std::ostringstream ss;
ss << img.cols << "x" << img.rows;
return DrawText(img, ss.str(), gravity, 5);
}
cv::Rect CVPainter::DrawImgData(
const cv::Mat &img, const mynteye::ImgData &data,
const gravity_t &gravity) {
int sign = 1;
if (gravity == BOTTOM_LEFT || gravity == BOTTOM_RIGHT)
sign = -1;
static auto fmt_time = NewFormat(0, 2);
std::ostringstream ss;
ss << "frame_id: " << data.frame_id;
ss << ", stamp: " << fmt_time << (0.01f * data.timestamp); // ms
ss << ", expo: ";
if (frame_rate_ == 0) {
ss << data.exposure_time;
} else {
ss << fmt_time << mynteye::utils::get_real_exposure_time(
frame_rate_, data.exposure_time);
}
cv::Rect rect_i = DrawText(img, ss.str(), gravity, 5);
Clear(ss) << "size: " << img.cols << "x" << img.rows;
cv::Rect rect_s =
DrawText(img, ss.str(), gravity, 5, 0, sign * (5 + rect_i.height));
// rect_i.width is the max one
if (sign > 0) {
return cv::Rect(
rect_i.tl(),
cv::Point(rect_i.x + rect_i.width, rect_s.y + rect_s.height));
} else {
return cv::Rect(rect_s.tl(), rect_i.br());
}
}
cv::Rect CVPainter::DrawImuData(
const cv::Mat &img, const mynteye::ImuData &data,
const gravity_t &gravity) {
static std::ostringstream ss;
static auto fmt_imu = NewFormat(8, 4);
static auto fmt_temp = NewFormat(6, 4);
int sign = 1;
if (gravity == BOTTOM_LEFT || gravity == BOTTOM_RIGHT)
sign = -1;
Clear(ss) << "frame_id: " << data.frame_id << ", stamp: " << data.timestamp
<< ", temp: " << fmt_temp << data.temperature;
cv::Rect rect_i = DrawText(img, ss.str(), gravity, 5);
Clear(ss) << "accel(x,y,z): " << fmt_imu << data.accel[0] << "," << fmt_imu
<< data.accel[1] << "," << fmt_imu << data.accel[2];
cv::Rect rect_a =
DrawText(img, ss.str(), gravity, 5, 0, sign * (5 + rect_i.height));
Clear(ss) << "gyro(x,y,z): " << fmt_imu << data.gyro[0] << "," << fmt_imu
<< data.gyro[1] << "," << fmt_imu << data.gyro[2];
cv::Rect rect_g = DrawText(
img, ss.str(), gravity, 5, 0,
sign * (10 + rect_i.height + rect_a.height));
// rect_i.width is the max one
if (sign > 0) {
return cv::Rect(
rect_i.tl(),
cv::Point(rect_i.x + rect_i.width, rect_g.y + rect_g.height));
} else {
return cv::Rect(rect_g.tl(), rect_i.br());
}
}
cv::Rect CVPainter::DrawText(
const cv::Mat &img, const std::string &text, const gravity_t &gravity,
const int &margin, const int &offset_x, const int &offset_y) {
int w = img.cols, h = img.rows;
int baseline = 0;
cv::Size textSize =
cv::getTextSize(text, FONT_FACE, FONT_SCALE, THICKNESS, &baseline);
int x, y;
switch (gravity) {
case TOP_LEFT:
x = margin;
y = margin + textSize.height;
break;
case TOP_RIGHT:
x = w - margin - textSize.width;
y = margin + textSize.height;
break;
case BOTTOM_LEFT:
x = margin;
y = h - margin;
break;
case BOTTOM_RIGHT:
x = w - margin - textSize.width;
y = h - margin;
break;
default: // TOP_LEFT
x = margin;
y = margin + textSize.height;
break;
}
x += offset_x;
y += offset_y;
cv::Point org(x, y);
#ifdef USE_OPENCV2
cv::putText(
const_cast<cv::Mat &>(img), text, org, FONT_FACE, FONT_SCALE, FONT_COLOR,
THICKNESS);
#else
cv::putText(img, text, org, FONT_FACE, FONT_SCALE, FONT_COLOR, THICKNESS);
#endif
return cv::Rect(org, textSize);
}

View File

@@ -0,0 +1,53 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_TUTORIALS_CV_PAINTER_H_ // NOLINT
#define MYNTEYE_TUTORIALS_CV_PAINTER_H_
#pragma once
#include <opencv2/core/core.hpp>
#include <string>
#include "mynteye/types.h"
class CVPainter {
public:
typedef enum Gravity {
TOP_LEFT,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT
} gravity_t;
explicit CVPainter(std::int32_t frame_rate = 0);
~CVPainter();
cv::Rect DrawSize(const cv::Mat &img, const gravity_t &gravity = TOP_LEFT);
cv::Rect DrawImgData(
const cv::Mat &img, const mynteye::ImgData &data,
const gravity_t &gravity = TOP_LEFT);
cv::Rect DrawImuData(
const cv::Mat &img, const mynteye::ImuData &data,
const gravity_t &gravity = TOP_RIGHT);
cv::Rect DrawText(
const cv::Mat &img, const std::string &text,
const gravity_t &gravity = TOP_LEFT, const int &margin = 5,
const int &offset_x = 0, const int &offset_y = 0);
private:
std::int32_t frame_rate_;
};
#endif // MYNTEYE_TUTORIALS_CV_PAINTER_H_ NOLINT

View File

@@ -0,0 +1,102 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "util/pc_viewer.h"
#include <glog/logging.h>
// #include <pcl/common/common_headers.h>
#include <cmath>
std::shared_ptr<pcl::visualization::PCLVisualizer> CustomColorVis(
pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc) {
// --------------------------------------------
// -----Open 3D viewer and add point cloud-----
// --------------------------------------------
std::shared_ptr<pcl::visualization::PCLVisualizer> viewer(
new pcl::visualization::PCLVisualizer("PointCloud Viewer"));
viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(
pc, 255, 255, 255);
viewer->addPointCloud<pcl::PointXYZ>(pc, single_color, "point cloud");
viewer->setPointCloudRenderingProperties(
pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "point cloud");
// viewer->addCoordinateSystem(1.0);
viewer->addCoordinateSystem(1000.0);
viewer->initCameraParameters();
viewer->setCameraPosition(0, 0, -150, 0, -1, 0);
return (viewer);
}
PCViewer::PCViewer() : viewer_(nullptr) {
VLOG(2) << __func__;
}
PCViewer::~PCViewer() {
VLOG(2) << __func__;
if (viewer_) {
// viewer_->saveCameraParameters("pcl_camera_params.txt");
viewer_->close();
viewer_ == nullptr;
}
}
void PCViewer::Update(const cv::Mat &xyz) {
pcl::PointCloud<pcl::PointXYZ>::Ptr pc(new pcl::PointCloud<pcl::PointXYZ>);
ConvertMatToPointCloud(xyz, pc);
Update(pc);
}
void PCViewer::Update(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc) {
if (viewer_ == nullptr) {
viewer_ = CustomColorVis(pc);
}
viewer_->updatePointCloud(pc, "point cloud");
viewer_->spinOnce();
}
bool PCViewer::WasVisual() const {
return viewer_ != nullptr;
}
bool PCViewer::WasStopped() const {
return viewer_ != nullptr && viewer_->wasStopped();
}
void PCViewer::ConvertMatToPointCloud(
const cv::Mat &xyz, pcl::PointCloud<pcl::PointXYZ>::Ptr pc) {
// cv::Mat channels[3];
// cv::split(xyz, channels);
// double min, max;
// cv::minMaxLoc(channels[2], &min, &max);
for (int i = 0; i < xyz.rows; i++) {
for (int j = 0; j < xyz.cols; j++) {
auto &&p = xyz.at<cv::Point3f>(i, j);
if (std::isfinite(p.x) && std::isfinite(p.y) && std::isfinite(p.z)) {
// LOG(INFO) << "[" << i << "," << j << "] x: " << p.x << ", y: " << p.y
// << ", z: " << p.z;
pcl::PointXYZ point;
point.x = p.x;
point.y = p.y;
point.z = p.z;
// point.z = p.z - min;
pc->points.push_back(point);
}
}
}
pc->width = static_cast<int>(pc->points.size());
pc->height = 1;
}

View File

@@ -0,0 +1,43 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_TUTORIALS_PC_VIEWER_H_ // NOLINT
#define MYNTEYE_TUTORIALS_PC_VIEWER_H_
#pragma once
#include <opencv2/core/core.hpp>
#include <pcl/visualization/pcl_visualizer.h>
#include <memory>
class PCViewer {
public:
PCViewer();
~PCViewer();
void Update(const cv::Mat &xyz);
void Update(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc);
bool WasVisual() const;
bool WasStopped() const;
private:
void ConvertMatToPointCloud(
const cv::Mat &xyz, pcl::PointCloud<pcl::PointXYZ>::Ptr pc);
std::shared_ptr<pcl::visualization::PCLVisualizer> viewer_;
};
#endif // MYNTEYE_TUTORIALS_PC_VIEWER_H_ NOLINT

View File

@@ -1,3 +1,17 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
set_outdir(
@@ -12,11 +26,8 @@ include_directories(
## camera_u
add_executable(camera_u camera.cc)
target_link_libraries(camera_u mynteye ${OpenCV_LIBS})
if(OS_WIN)
target_compile_definitions(camera_u
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()
make_executable(camera_u
SRCS camera.cc
LINK_LIBS mynteye ${OpenCV_LIBS}
DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
)

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
@@ -14,8 +27,17 @@
struct frame {
const void *data = nullptr;
std::function<void()> continuation = nullptr;
frame() {
// VLOG(2) << __func__;
}
~frame() {
// VLOG(2) << __func__;
data = nullptr;
if (continuation) {
continuation();
continuation = nullptr;
}
}
};
@@ -28,7 +50,11 @@ int main(int argc, char *argv[]) {
auto context = uvc::create_context();
auto devices = uvc::query_devices(context);
LOG_IF(FATAL, devices.size() <= 0) << "No devices :(";
if (devices.size() <= 0) {
LOG(ERROR) << "No devices :(";
return 1;
}
for (auto &&device : devices) {
auto vid = uvc::get_vendor_id(*device);
// auto pid = uvc::get_product_id(*device);
@@ -41,7 +67,10 @@ int main(int argc, char *argv[]) {
// std::string dashes(80, '-');
size_t n = mynteye_devices.size();
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
if (n <= 0) {
LOG(ERROR) << "No MYNT EYE devices :(";
return 1;
}
LOG(INFO) << "MYNT EYE devices: ";
for (size_t i = 0; i < n; i++) {
@@ -74,18 +103,25 @@ int main(int argc, char *argv[]) {
std::mutex mtx;
std::condition_variable cv;
std::vector<frame> frames;
const auto frame_ready = [&frames]() { return !frames.empty(); };
const auto frame_empty = [&frames]() { return frames.empty(); };
std::shared_ptr<frame> frame = nullptr;
const auto frame_ready = [&frame]() { return frame != nullptr; };
const auto frame_empty = [&frame]() { return frame == nullptr; };
uvc::set_device_mode(
*device, 752, 480, static_cast<int>(Format::YUYV), 25,
[&mtx, &cv, &frames, &frame_ready](const void *data) {
[&mtx, &cv, &frame, &frame_ready](
const void *data, std::function<void()> continuation) {
// reinterpret_cast<const std::uint8_t *>(data);
std::unique_lock<std::mutex> lock(mtx);
frame frame;
frame.data = data; // not copy
frames.push_back(frame);
if (frame == nullptr) {
frame = std::make_shared<struct frame>();
} else {
if (frame->continuation) {
frame->continuation();
}
}
frame->data = data; // not copy here
frame->continuation = continuation;
if (frame_ready())
cv.notify_one();
});
@@ -106,13 +142,12 @@ int main(int argc, char *argv[]) {
throw std::runtime_error("Timeout waiting for frame.");
}
auto frame = frames.back(); // only last one is valid
cv::Mat img(480, 752, CV_8UC2, const_cast<void *>(frame.data));
// only lastest frame is valid
cv::Mat img(480, 752, CV_8UC2, const_cast<void *>(frame->data));
cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2);
cv::imshow("frame", img);
frames.clear();
frame = nullptr;
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
[ -n "${_DETECT_SH_}" ] && return || readonly _DETECT_SH_=1
[ -n "${_VERBOSE_}" ] && echo "-- INCLUDE: detect.sh"

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
[ -n "${_ECHO_SH_}" ] && return || readonly _ECHO_SH_=1
[ -n "${_VERBOSE_}" ] && echo "-- INCLUDE: echo.sh"

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
[ -n "${_HOST_SH_}" ] && return || readonly _HOST_SH_=1
[ -n "${_VERBOSE_}" ] && echo "-- INCLUDE: host.sh"

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
[ -n "${_MKDIR_SH_}" ] && return || readonly _MKDIR_SH_=1
[ -n "${_VERBOSE_}" ] && echo "-- INCLUDE: mkdir.sh"

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
[ -n "${_STRING_SH_}" ] && return || readonly _STRING_SH_=1
[ -n "${_VERBOSE_}" ] && echo "-- INCLUDE: string.sh"

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(realpath "$BASE_DIR/..")

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
FIND="find"

View File

@@ -1,9 +1,22 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
# _VERBOSE_=1
# _FORCE_INSRALL_=1
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(realpath "$BASE_DIR/..")
source "$BASE_DIR/common/echo.sh"
source "$BASE_DIR/common/detect.sh"
@@ -15,16 +28,16 @@ if [ "$HOST_OS" = "Win" ]; then
PYTHON="python2"
fi
_detect curl
_detect $PYTHON
if [ "$HOST_OS" = "Linux" ]; then
_detect_install() {
dpkg -s "$1" > /dev/null
_detect_cmd "$1" || [ $(dpkg-query -W -f='${Status}' "$1" 2> /dev/null \
| grep -c "ok installed") -gt 0 ]
}
elif [ "$HOST_OS" = "Mac" ]; then
_detect_install() {
brew ls --versions "$1" > /dev/null
_detect_cmd "$1" || brew ls --versions "$1" > /dev/null
}
else
_detect_install() {
@@ -61,19 +74,26 @@ if [ "$HOST_OS" = "Linux" ]; then
# detect apt-get
_detect apt-get
# apt-get install
_install_deps "sudo apt-get install" build-essential cmake git clang-format
_install_deps "sudo apt-get install" build-essential curl cmake git clang-format
_install_deps "sudo apt-get install" libv4l-dev
if ! _detect_cmd clang-format; then
# on Ubuntu 14.04, apt-cache search clang-format
_install_deps "sudo apt-get install" clang-format-3.9
sudo ln -sf clang-format-3.9 /usr/bin/clang-format
sudo ln -sf clang-format-diff-3.9 /usr/bin/clang-format-diff
fi
# sudo
SUDO="sudo"
elif [ "$HOST_OS" = "Mac" ]; then
# detect brew
if ! _detect_cmd brew; then
_echo_sn "Install brew"
_detect curl
_detect ruby
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# brew install
_install_deps "brew install" cmake git clang-format
_install_deps "brew install" curl cmake git clang-format
# link clang-format-diff (if not compatible with Python 3, fix it by yourself)
[ -f "/usr/local/bin/clang-format-diff" ] || \
ln -s /usr/local/share/clang/clang-format-diff.py /usr/local/bin/clang-format-diff
@@ -82,7 +102,7 @@ elif [ "$HOST_OS" = "Win" ]; then
# detect pacman on MSYS
_detect pacman
# pacman install (common)
_install_deps "pacman -S" git clang-format
_install_deps "pacman -S" curl git clang-format
if [ "$HOST_NAME" = "MINGW" ]; then
# pacman install (MINGW)
_deps=()
@@ -125,9 +145,40 @@ fi
_echo_d "pip install --upgrade autopep8 cpplint pylint requests"
$SUDO pip install --upgrade autopep8 cpplint pylint requests
## realpath
# detect realpath
if ! _detect_cmd realpath; then
_echo_sn "Install realpath"
if [ "$HOST_OS" = "Linux" ]; then
# How to install realpath on Ubuntu 14.04
# https://www.howtoinstall.co/en/ubuntu/trusty/realpath
sudo apt-get install coreutils realpath
elif [ "$HOST_OS" = "Mac" ]; then
brew install coreutils
elif [ "$HOST_OS" = "Win" ]; then
pacman -S coreutils
else # unexpected
_echo_e "Unknown host os :("
exit 1
fi
fi
ROOT_DIR=$(realpath "$BASE_DIR/..")
## init
_echo_s "Init git hooks"
$PYTHON "$ROOT_DIR/tools/linter/init-git-hooks.py"
## cmake version
_echo_s "Expect cmake version >= 3.0"
cmake --version | head -1
if [ "$HOST_NAME" = "Ubuntu" ]; then
# sudo apt remove cmake
_echo "How to upgrade cmake in Ubuntu"
_echo " https://askubuntu.com/questions/829310/how-to-upgrade-cmake-in-ubuntu"
fi
exit 0

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# 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.
BASE_DIR=$(cd "$(dirname "$0")" && pwd)

432
src/api/api.cc Normal file
View File

@@ -0,0 +1,432 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/api.h"
#ifdef WITH_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
#endif
#include <glog/logging.h>
#include <algorithm>
#include <thread>
#include "mynteye/glog_init.h"
#include "mynteye/utils.h"
#include "api/plugin.h"
#include "api/synthetic.h"
#include "device/device.h"
#include "internal/dl.h"
#if defined(WITH_FILESYSTEM) && defined(WITH_NATIVE_FILESYSTEM)
#if defined(OS_WIN)
#include <windows.h>
#endif
#endif
MYNTEYE_BEGIN_NAMESPACE
namespace {
#if defined(WITH_FILESYSTEM)
#if defined(WITH_BOOST_FILESYSTEM)
namespace fs = boost::filesystem;
bool file_exists(const fs::path &p) {
try {
fs::file_status s = fs::status(p);
return fs::exists(s) && fs::is_regular_file(s);
} catch (fs::filesystem_error &e) {
LOG(ERROR) << e.what();
return false;
}
}
bool dir_exists(const fs::path &p) {
try {
fs::file_status s = fs::status(p);
return fs::exists(s) && fs::is_directory(s);
} catch (fs::filesystem_error &e) {
LOG(ERROR) << e.what();
return false;
}
}
#elif defined(WITH_NATIVE_FILESYSTEM)
#if defined(OS_WIN)
bool file_exists(const std::string &p) {
DWORD attrs = GetFileAttributes(p.c_str());
return (attrs != INVALID_FILE_ATTRIBUTES && !(attrs & FILE_ATTRIBUTE_DIRECTORY));
}
bool dir_exists(const std::string &p) {
DWORD attrs = GetFileAttributes(p.c_str());
return (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY));
}
#else
#error "Unsupported native filesystem"
#endif
#endif
std::vector<std::string> get_plugin_paths() {
std::string info_path(MYNTEYE_SDK_INSTALL_DIR);
info_path.append(OS_SEP "share" OS_SEP "mynteye" OS_SEP "build.info");
cv::FileStorage fs(info_path, cv::FileStorage::READ);
if (!fs.isOpened()) {
LOG(WARNING) << "build.info not found: " << info_path;
return {};
}
auto to_lower = [](std::string &s) { // NOLINT
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
};
std::string host_os = fs["HOST_OS"];
to_lower(host_os);
std::string host_name = fs["HOST_NAME"];
to_lower(host_name);
std::string host_arch = fs["HOST_ARCH"];
to_lower(host_arch);
std::string host_compiler = fs["HOST_COMPILER"];
to_lower(host_compiler);
// std::string compiler_version = fs["COMPILER_VERSION"];
int compiler_version_major = fs["COMPILER_VERSION_MAJOR"];
// int compiler_version_minor = fs["COMPILER_VERSION_MINOR"];
// int compiler_version_patch = fs["COMPILER_VERSION_PATCH"];
// int compiler_version_tweak = fs["COMPILER_VERSION_TWEAK"];
std::string cuda_version = fs["CUDA_VERSION"];
// int cuda_version_major = fs["CUDA_VERSION_MAJOR"];
// int cuda_version_minor = fs["CUDA_VERSION_MINOR"];
// std::string cuda_version_string = fs["CUDA_VERSION_STRING"];
std::string opencv_version = fs["OpenCV_VERSION"];
// int opencv_version_major = fs["OpenCV_VERSION_MAJOR"];
// int opencv_version_minor = fs["OpenCV_VERSION_MINOR"];
// int opencv_version_patch = fs["OpenCV_VERSION_PATCH"];
// int opencv_version_tweak = fs["OpenCV_VERSION_TWEAK"];
// std::string opencv_version_status = fs["OpenCV_VERSION_STATUS"];
std::string opencv_with_world = fs["OpenCV_WITH_WORLD"];
to_lower(opencv_with_world);
std::string mynteye_version = fs["MYNTEYE_VERSION"];
// int mynteye_version_major = fs["MYNTEYE_VERSION_MAJOR"];
// int mynteye_version_minor = fs["MYNTEYE_VERSION_MINOR"];
// int mynteye_version_patch = fs["MYNTEYE_VERSION_PATCH"];
// int mynteye_version_tweak = fs["MYNTEYE_VERSION_TWEAK"];
fs.release();
std::string lib_prefix;
std::string lib_suffix;
if (host_os == "linux") {
if (host_compiler != "gnu" || compiler_version_major < 5)
return {};
lib_prefix = "lib";
lib_suffix = ".so";
} else if (host_os == "win") {
lib_prefix = "";
lib_suffix = ".dll";
} else if (host_os == "mac") {
lib_prefix = "lib";
lib_suffix = ".dylib";
} else {
return {};
}
std::vector<std::string> names;
{
std::vector<std::string> prefixes{
// lib_prefix + "plugin_b_ocl" + ocl_version,
lib_prefix + "plugin_g_cuda" + cuda_version,
};
std::string opencv_name("_opencv" + opencv_version);
if (opencv_with_world == "true") {
opencv_name.append("-world");
}
for (auto &&prefix : prefixes) {
names.push_back(prefix + opencv_name + "_mynteye" + mynteye_version);
names.push_back(prefix + opencv_name);
names.push_back(prefix);
}
for (auto &&name : names) {
name.append(lib_suffix);
}
}
std::vector<std::string> paths;
std::vector<std::string> plats;
if (host_name != host_os) {
plats.push_back(host_name + "-" + host_arch);
}
plats.push_back(host_os + "-" + host_arch);
std::vector<std::string> dirs{MYNTEYE_SDK_ROOT_DIR, MYNTEYE_SDK_INSTALL_DIR};
for (auto &&plat : plats) {
for (auto &&dir : dirs) {
auto &&plat_dir = dir + OS_SEP "plugins" + OS_SEP + plat;
// VLOG(2) << "plat_dir: " << plat_dir;
if (!dir_exists(plat_dir))
continue;
for (auto &&name : names) {
// VLOG(2) << " name: " << name;
auto &&path = plat_dir + OS_SEP + name;
if (!file_exists(path))
continue;
paths.push_back(path);
}
}
}
return paths;
}
#endif
} // namespace
API::API(std::shared_ptr<Device> device)
: device_(device), synthetic_(new Synthetic(this)) {
VLOG(2) << __func__;
}
API::~API() {
VLOG(2) << __func__;
}
std::shared_ptr<API> API::Create() {
return Create(device::select());
}
std::shared_ptr<API> API::Create(std::shared_ptr<Device> device) {
if (!device)
return nullptr;
return std::make_shared<API>(device);
}
std::shared_ptr<API> API::Create(int argc, char *argv[]) {
static glog_init _(argc, argv);
auto &&device = device::select();
if (!device)
return nullptr;
return std::make_shared<API>(device);
}
std::shared_ptr<API> API::Create(
int argc, char *argv[], std::shared_ptr<Device> device) {
static glog_init _(argc, argv);
if (!device)
return nullptr;
return std::make_shared<API>(device);
}
Model API::GetModel() const {
return device_->GetModel();
}
bool API::Supports(const Stream &stream) const {
return synthetic_->Supports(stream);
}
bool API::Supports(const Capabilities &capability) const {
return device_->Supports(capability);
}
bool API::Supports(const Option &option) const {
return device_->Supports(option);
}
bool API::Supports(const AddOns &addon) const {
return device_->Supports(addon);
}
const std::vector<StreamRequest> &API::GetStreamRequests(
const Capabilities &capability) const {
return device_->GetStreamRequests(capability);
}
void API::ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request) {
device_->ConfigStreamRequest(capability, request);
}
std::string API::GetInfo(const Info &info) const {
return device_->GetInfo(info);
}
Intrinsics API::GetIntrinsics(const Stream &stream) const {
return device_->GetIntrinsics(stream);
}
Extrinsics API::GetExtrinsics(const Stream &from, const Stream &to) const {
return device_->GetExtrinsics(from, to);
}
MotionIntrinsics API::GetMotionIntrinsics() const {
return device_->GetMotionIntrinsics();
}
Extrinsics API::GetMotionExtrinsics(const Stream &from) const {
return device_->GetMotionExtrinsics(from);
}
void API::LogOptionInfos() const {
device_->LogOptionInfos();
}
OptionInfo API::GetOptionInfo(const Option &option) const {
return device_->GetOptionInfo(option);
}
std::int32_t API::GetOptionValue(const Option &option) const {
return device_->GetOptionValue(option);
}
void API::SetOptionValue(const Option &option, std::int32_t value) {
device_->SetOptionValue(option, value);
}
bool API::RunOptionAction(const Option &option) const {
return device_->RunOptionAction(option);
}
void API::SetStreamCallback(const Stream &stream, stream_callback_t callback) {
synthetic_->SetStreamCallback(stream, callback);
}
void API::SetMotionCallback(motion_callback_t callback) {
static auto callback_ = callback;
if (callback_) {
device_->SetMotionCallback(
[](const device::MotionData &data) { callback_({data.imu}); }, true);
} else {
device_->SetMotionCallback(nullptr);
}
}
bool API::HasStreamCallback(const Stream &stream) const {
return synthetic_->HasStreamCallback(stream);
}
bool API::HasMotionCallback() const {
return device_->HasMotionCallback();
}
void API::Start(const Source &source) {
if (source == Source::VIDEO_STREAMING) {
#ifdef WITH_FILESYSTEM
if (!synthetic_->HasPlugin()) {
try {
auto &&plugin_paths = get_plugin_paths();
if (plugin_paths.size() > 0) {
EnablePlugin(plugin_paths[0]);
}
} catch (...) {
LOG(WARNING) << "Incorrect yaml format: build.info";
}
}
#endif
synthetic_->StartVideoStreaming();
} else if (source == Source::MOTION_TRACKING) {
device_->StartMotionTracking();
} else if (source == Source::ALL) {
Start(Source::VIDEO_STREAMING);
Start(Source::MOTION_TRACKING);
} else {
LOG(ERROR) << "Unsupported source :(";
}
}
void API::Stop(const Source &source) {
if (source == Source::VIDEO_STREAMING) {
synthetic_->StopVideoStreaming();
} else if (source == Source::MOTION_TRACKING) {
device_->StopMotionTracking();
} else if (source == Source::ALL) {
Stop(Source::MOTION_TRACKING);
// Must stop motion tracking before video streaming and sleep a moment here
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Stop(Source::VIDEO_STREAMING);
} else {
LOG(ERROR) << "Unsupported source :(";
}
}
void API::WaitForStreams() {
synthetic_->WaitForStreams();
}
void API::EnableStreamData(const Stream &stream) {
synthetic_->EnableStreamData(stream);
}
void API::DisableStreamData(const Stream &stream) {
synthetic_->DisableStreamData(stream);
}
api::StreamData API::GetStreamData(const Stream &stream) {
return synthetic_->GetStreamData(stream);
}
std::vector<api::StreamData> API::GetStreamDatas(const Stream &stream) {
return synthetic_->GetStreamDatas(stream);
}
void API::EnableMotionDatas(std::size_t max_size) {
device_->EnableMotionDatas(max_size);
}
std::vector<api::MotionData> API::GetMotionDatas() {
std::vector<api::MotionData> datas;
for (auto &&data : device_->GetMotionDatas()) {
datas.push_back({data.imu});
}
return datas;
}
void API::EnablePlugin(const std::string &path) {
static DL dl;
CHECK(dl.Open(path.c_str())) << "Open plugin failed: " << path;
plugin_version_code_t *plugin_version_code =
dl.Sym<plugin_version_code_t>("plugin_version_code");
LOG(INFO) << "Enable plugin success";
LOG(INFO) << " version code: " << plugin_version_code();
LOG(INFO) << " path: " << path;
plugin_create_t *plugin_create = dl.Sym<plugin_create_t>("plugin_create");
plugin_destroy_t *plugin_destroy = dl.Sym<plugin_destroy_t>("plugin_destroy");
std::shared_ptr<Plugin> plugin(plugin_create(), plugin_destroy);
plugin->OnCreate(this);
synthetic_->SetPlugin(plugin);
}
std::shared_ptr<Device> API::device() {
return device_;
}
MYNTEYE_END_NAMESPACE

283
src/api/api.h Normal file
View File

@@ -0,0 +1,283 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_API_H_ // NOLINT
#define MYNTEYE_API_H_
#pragma once
#include <opencv2/core/core.hpp>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
class Device;
class Synthetic;
namespace device {
class Frame;
} // namespace device
namespace api {
/**
* @ingroup datatypes
* API stream data.
*/
struct MYNTEYE_API StreamData {
/** ImgData. */
std::shared_ptr<ImgData> img;
/** Frame. */
cv::Mat frame;
/** Raw frame. */
std::shared_ptr<device::Frame> frame_raw;
bool operator==(const StreamData &other) const {
if (img && other.img) {
return img->frame_id == other.img->frame_id &&
img->timestamp == other.img->timestamp;
}
return false;
}
};
/**
* @ingroup datatypes
* API motion data.
*/
struct MYNTEYE_API MotionData {
/** ImuData. */
std::shared_ptr<ImuData> imu;
bool operator==(const MotionData &other) const {
if (imu && other.imu) {
return imu->frame_id == other.imu->frame_id &&
imu->timestamp == other.imu->timestamp;
}
return false;
}
};
} // namespace api
/**
* The API class to communicate with MYNT® EYE device.
*/
class MYNTEYE_API API {
public:
/** The api::StreamData callback. */
using stream_callback_t = std::function<void(const api::StreamData &data)>;
/** The api::MotionData callback. */
using motion_callback_t = std::function<void(const api::MotionData &data)>;
explicit API(std::shared_ptr<Device> device);
virtual ~API();
/**
* Create the API instance.
* @return the API instance.
* @note This will call device::select() to select a device.
*/
static std::shared_ptr<API> Create();
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @return the API instance.
* @note This will init glog with args and call device::select() to select a
* device.
*/
static std::shared_ptr<API> Create(int argc, char *argv[]);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @param device the selected device.
* @return the API instance.
* @note This will init glog with args.
*/
static std::shared_ptr<API> Create(
int argc, char *argv[], std::shared_ptr<Device> device);
/**
* Get the model.
*/
Model GetModel() const;
/**
* Supports the stream or not.
*/
bool Supports(const Stream &stream) const;
/**
* Supports the capability or not.
*/
bool Supports(const Capabilities &capability) const;
/**
* Supports the option or not.
*/
bool Supports(const Option &option) const;
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
/**
* Get all stream requests of the capability.
*/
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
/**
* Config the stream request to the capability.
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the device info.
*/
std::string GetInfo(const Info &info) const;
/**
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream) const;
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics() const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
/**
* Log all option infos.
*/
void LogOptionInfos() const;
/**
* Get the option info.
*/
OptionInfo GetOptionInfo(const Option &option) const;
/**
* Get the option value.
*/
std::int32_t GetOptionValue(const Option &option) const;
/**
* Set the option value.
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Run the option action.
*/
bool RunOptionAction(const Option &option) const;
/**
* Set the callback of stream.
*/
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
/**
* Set the callback of motion.
*/
void SetMotionCallback(motion_callback_t callback);
/**
* Has the callback of stream.
*/
bool HasStreamCallback(const Stream &stream) const;
/**
* Has the callback of motion.
*/
bool HasMotionCallback() const;
/**
* Start capturing the source.
*/
void Start(const Source &source);
/**
* Stop capturing the source.
*/
void Stop(const Source &source);
/**
* Wait the streams are ready.
*/
void WaitForStreams();
/**
* Enable the data of stream.
* @note must enable the stream if it's a synthetic one. This means the stream
* in not native, the device has the capability to provide this stream, but
* still support this stream.
*/
void EnableStreamData(const Stream &stream);
/**
* Disable the data of stream.
*/
void DisableStreamData(const Stream &stream);
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
api::StreamData GetStreamData(const Stream &stream);
/**
* Get the latest data of stream.
*/
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
/**
* Enable cache motion datas.
*/
void EnableMotionDatas(
std::size_t max_size = std::numeric_limits<std::size_t>::max());
/**
* Get the motion datas.
*/
std::vector<api::MotionData> GetMotionDatas();
/**
* Enable the plugin.
*/
void EnablePlugin(const std::string &path);
std::shared_ptr<Device> device();
private:
std::shared_ptr<Device> device_;
std::unique_ptr<Synthetic> synthetic_;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_H_ NOLINT

140
src/api/plugin.h Normal file
View File

@@ -0,0 +1,140 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_PLUGIN_H_ // NOLINT
#define MYNTEYE_PLUGIN_H_
#pragma once
#include <opencv2/core/core.hpp>
#include <cstdint>
#include "mynteye/mynteye.h"
#ifndef MYNTEYE_PLUGIN_VERSION_CODE
#define MYNTEYE_PLUGIN_VERSION_CODE 0
#endif
MYNTEYE_BEGIN_NAMESPACE
class API;
struct Object;
/**
* The plugin which could implement processing by yourself.
*/
class MYNTEYE_API Plugin {
public:
Plugin() = default;
virtual ~Plugin() = 0;
/**
* Called when plugin created.
* @param api the API instacne.
*/
virtual void OnCreate(API *api) {
api_ = api;
}
/**
* Called when process rectify.
* @param in input object.
* @param out output object.
* @return `true` if you process rectify.
*/
virtual bool OnRectifyProcess(Object *const in, Object *const out) {
UNUSED(in)
UNUSED(out)
return false;
}
/**
* Called when process disparity.
* @param in input object.
* @param out output object.
* @return `true` if you process disparity.
*/
virtual bool OnDisparityProcess(Object *const in, Object *const out) {
UNUSED(in)
UNUSED(out)
return false;
}
/**
* Called when process normalized disparity.
* @param in input object.
* @param out output object.
* @return `true` if you process normalized disparity.
*/
virtual bool OnDisparityNormalizedProcess(
Object *const in, Object *const out) {
UNUSED(in)
UNUSED(out)
return false;
}
/**
* Called when process points.
* @param in input object.
* @param out output object.
* @return `true` if you process points.
*/
virtual bool OnPointsProcess(Object *const in, Object *const out) {
UNUSED(in)
UNUSED(out)
return false;
}
/**
* Called when process depth.
* @param in input object.
* @param out output object.
* @return `true` if you process depth.
*/
virtual bool OnDepthProcess(Object *const in, Object *const out) {
UNUSED(in)
UNUSED(out)
return false;
}
protected:
API *api_;
};
inline Plugin::~Plugin() = default;
using plugin_version_code_t = std::uint32_t();
using plugin_create_t = Plugin *();
using plugin_destroy_t = void(Plugin *);
MYNTEYE_END_NAMESPACE
extern "C" {
/**
* Get the plugin version code.
*/
MYNTEYE_API std::uint32_t plugin_version_code();
/**
* Create the plugin.
*/
MYNTEYE_API mynteye::Plugin *plugin_create();
/**
* Destroy the plugin.
*/
MYNTEYE_API void plugin_destroy(mynteye::Plugin *plugin);
}
#endif // MYNTEYE_PLUGIN_H_ NOLINT

View File

@@ -0,0 +1,50 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/processor/depth_processor.h"
#include <glog/logging.h>
#include <utility>
MYNTEYE_BEGIN_NAMESPACE
DepthProcessor::DepthProcessor(std::int32_t proc_period)
: Processor(std::move(proc_period)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
}
DepthProcessor::~DepthProcessor() {
VLOG(2) << __func__;
}
std::string DepthProcessor::Name() {
return NAME;
}
Object *DepthProcessor::OnCreateOutput() {
return new ObjMat();
}
bool DepthProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
const ObjMat *input = Object::Cast<ObjMat>(in);
ObjMat *output = Object::Cast<ObjMat>(out);
cv::Mat channels[3 /*input->value.channels()*/];
cv::split(input->value, channels);
channels[2].convertTo(output->value, CV_16UC1);
return true;
}
MYNTEYE_END_NAMESPACE

View File

@@ -0,0 +1,41 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_DEPTH_PROCESSOR_H_ // NOLINT
#define MYNTEYE_DEPTH_PROCESSOR_H_
#pragma once
#include <string>
#include "api/processor/processor.h"
MYNTEYE_BEGIN_NAMESPACE
class DepthProcessor : public Processor {
public:
static constexpr auto &&NAME = "DepthProcessor";
explicit DepthProcessor(std::int32_t proc_period = 0);
virtual ~DepthProcessor();
std::string Name() override;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out, Processor *const parent) override;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DEPTH_PROCESSOR_H_ NOLINT

View File

@@ -0,0 +1,52 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/processor/disparity_normalized_processor.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <glog/logging.h>
#include <utility>
MYNTEYE_BEGIN_NAMESPACE
DisparityNormalizedProcessor::DisparityNormalizedProcessor(
std::int32_t proc_period)
: Processor(std::move(proc_period)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
}
DisparityNormalizedProcessor::~DisparityNormalizedProcessor() {
VLOG(2) << __func__;
}
std::string DisparityNormalizedProcessor::Name() {
return NAME;
}
Object *DisparityNormalizedProcessor::OnCreateOutput() {
return new ObjMat();
}
bool DisparityNormalizedProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
const ObjMat *input = Object::Cast<ObjMat>(in);
ObjMat *output = Object::Cast<ObjMat>(out);
cv::normalize(input->value, output->value, 0, 255, cv::NORM_MINMAX, CV_8UC1);
// cv::normalize maybe return empty ==
return !output->value.empty();
}
MYNTEYE_END_NAMESPACE

View File

@@ -0,0 +1,41 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_DISPARITY_NORMALIZED_PROCESSOR_H_ // NOLINT
#define MYNTEYE_DISPARITY_NORMALIZED_PROCESSOR_H_
#pragma once
#include <string>
#include "api/processor/processor.h"
MYNTEYE_BEGIN_NAMESPACE
class DisparityNormalizedProcessor : public Processor {
public:
static constexpr auto &&NAME = "DisparityNormalizedProcessor";
explicit DisparityNormalizedProcessor(std::int32_t proc_period = 0);
virtual ~DisparityNormalizedProcessor();
std::string Name() override;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out, Processor *const parent) override;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DISPARITY_NORMALIZED_PROCESSOR_H_ NOLINT

View File

@@ -0,0 +1,103 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/processor/disparity_processor.h"
#include <opencv2/calib3d/calib3d.hpp>
#include <glog/logging.h>
#include <utility>
MYNTEYE_BEGIN_NAMESPACE
DisparityProcessor::DisparityProcessor(std::int32_t proc_period)
: Processor(std::move(proc_period)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
int sgbmWinSize = 3;
int numberOfDisparities = 64;
#ifdef USE_OPENCV2
// StereoSGBM
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm
sgbm_ = cv::Ptr<cv::StereoSGBM>(
new cv::StereoSGBM(
0, // minDisparity
numberOfDisparities, // numDisparities
sgbmWinSize, // SADWindowSize
8 * sgbmWinSize * sgbmWinSize, // P1
32 * sgbmWinSize * sgbmWinSize, // P2
1, // disp12MaxDiff
63, // preFilterCap
10, // uniquenessRatio
100, // speckleWindowSize
32, // speckleRange
false)); // fullDP
#else
sgbm_ = cv::StereoSGBM::create(0, 16, 3);
sgbm_->setPreFilterCap(63);
sgbm_->setBlockSize(sgbmWinSize);
sgbm_->setP1(8 * sgbmWinSize * sgbmWinSize);
sgbm_->setP2(32 * sgbmWinSize * sgbmWinSize);
sgbm_->setMinDisparity(0);
sgbm_->setNumDisparities(numberOfDisparities);
sgbm_->setUniquenessRatio(10);
sgbm_->setSpeckleWindowSize(100);
sgbm_->setSpeckleRange(32);
sgbm_->setDisp12MaxDiff(1);
#endif
}
DisparityProcessor::~DisparityProcessor() {
VLOG(2) << __func__;
}
std::string DisparityProcessor::Name() {
return NAME;
}
Object *DisparityProcessor::OnCreateOutput() {
return new ObjMat();
}
bool DisparityProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
ObjMat *output = Object::Cast<ObjMat>(out);
cv::Mat disparity;
#ifdef USE_OPENCV2
// StereoSGBM::operator()
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#stereosgbm-operator
// Output disparity map. It is a 16-bit signed single-channel image of the
// same size as the input image.
// It contains disparity values scaled by 16. So, to get the floating-point
// disparity map,
// you need to divide each disp element by 16.
(*sgbm_)(input->first, input->second, disparity);
#else
// compute()
// http://docs.opencv.org/master/d2/d6e/classcv_1_1StereoMatcher.html
// Output disparity map. It has the same size as the input images.
// Some algorithms, like StereoBM or StereoSGBM compute 16-bit fixed-point
// disparity map
// (where each disparity value has 4 fractional bits),
// whereas other algorithms output 32-bit floating-point disparity map.
sgbm_->compute(input->first, input->second, disparity);
#endif
output->value = disparity / 16 + 1;
return true;
}
MYNTEYE_END_NAMESPACE

View File

@@ -0,0 +1,50 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_DISPARITY_PROCESSOR_H_ // NOLINT
#define MYNTEYE_DISPARITY_PROCESSOR_H_
#pragma once
#include <string>
#include "api/processor/processor.h"
namespace cv {
class StereoSGBM;
} // namespace cv
MYNTEYE_BEGIN_NAMESPACE
class DisparityProcessor : public Processor {
public:
static constexpr auto &&NAME = "DisparityProcessor";
explicit DisparityProcessor(std::int32_t proc_period = 0);
virtual ~DisparityProcessor();
std::string Name() override;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out, Processor *const parent) override;
private:
cv::Ptr<cv::StereoSGBM> sgbm_;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DISPARITY_PROCESSOR_H_ NOLINT

View File

@@ -0,0 +1,87 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_OBJECT_H_ // NOLINT
#define MYNTEYE_OBJECT_H_
#pragma once
#include <opencv2/core/core.hpp>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
/**
* Input & output object.
*/
struct MYNTEYE_API Object {
Object() = default;
virtual ~Object() = default;
virtual Object *Clone() const = 0;
/** Cast the obj to T pointer */
template <typename T>
static T *Cast(Object *obj) {
return dynamic_cast<T *>(obj);
}
/** Cast the obj to const T pointer */
template <typename T>
static const T *Cast(const Object *obj) {
return dynamic_cast<const T *>(obj);
}
};
/**
* Input & output object of one cv::Mat.
*/
struct MYNTEYE_API ObjMat : public Object {
ObjMat() = default;
explicit ObjMat(const cv::Mat &value) : value(value) {}
/** The value */
cv::Mat value;
Object *Clone() const {
ObjMat *mat = new ObjMat;
mat->value = value.clone();
return mat;
}
};
/**
* Input & output object of two cv::Mat.
*/
struct MYNTEYE_API ObjMat2 : public Object {
ObjMat2() = default;
ObjMat2(const cv::Mat &first, const cv::Mat &second)
: first(first), second(second) {}
/** The first value */
cv::Mat first;
/** The second value */
cv::Mat second;
Object *Clone() const {
ObjMat2 *mat2 = new ObjMat2;
mat2->first = first.clone();
mat2->second = second.clone();
return mat2;
}
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_OBJECT_H_ NOLINT

View File

@@ -0,0 +1,50 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/processor/points_processor.h"
#include <opencv2/calib3d/calib3d.hpp>
#include <glog/logging.h>
#include <utility>
MYNTEYE_BEGIN_NAMESPACE
PointsProcessor::PointsProcessor(cv::Mat Q, std::int32_t proc_period)
: Processor(std::move(proc_period)), Q_(std::move(Q)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
}
PointsProcessor::~PointsProcessor() {
VLOG(2) << __func__;
}
std::string PointsProcessor::Name() {
return NAME;
}
Object *PointsProcessor::OnCreateOutput() {
return new ObjMat();
}
bool PointsProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
const ObjMat *input = Object::Cast<ObjMat>(in);
ObjMat *output = Object::Cast<ObjMat>(out);
cv::reprojectImageTo3D(input->value, output->value, Q_, true);
return true;
}
MYNTEYE_END_NAMESPACE

View File

@@ -0,0 +1,46 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_POINTS_PROCESSOR_H_ // NOLINT
#define MYNTEYE_POINTS_PROCESSOR_H_
#pragma once
#include <opencv2/core/core.hpp>
#include <string>
#include "api/processor/processor.h"
MYNTEYE_BEGIN_NAMESPACE
class PointsProcessor : public Processor {
public:
static constexpr auto &&NAME = "PointsProcessor";
explicit PointsProcessor(cv::Mat Q, std::int32_t proc_period = 0);
virtual ~PointsProcessor();
std::string Name() override;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out, Processor *const parent) override;
private:
cv::Mat Q_;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_POINTS_PROCESSOR_H_ NOLINT

View File

@@ -0,0 +1,235 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/processor/processor.h"
#include <glog/logging.h>
#include <utility>
#include "internal/times.h"
MYNTEYE_BEGIN_NAMESPACE
Processor::Processor(std::int32_t proc_period)
: proc_period_(std::move(proc_period)),
activated_(false),
input_ready_(false),
idle_(true),
dropped_count_(0),
input_(nullptr),
output_(nullptr),
output_result_(nullptr),
pre_callback_(nullptr),
post_callback_(nullptr),
callback_(nullptr),
parent_(nullptr) {
VLOG(2) << __func__;
}
Processor::~Processor() {
VLOG(2) << __func__;
Deactivate();
input_.reset(nullptr);
output_.reset(nullptr);
output_result_.reset(nullptr);
childs_.clear();
}
std::string Processor::Name() {
return "Processor";
}
void Processor::AddChild(const std::shared_ptr<Processor> &child) {
child->parent_ = this;
childs_.push_back(child);
}
void Processor::RemoveChild(const std::shared_ptr<Processor> &child) {
childs_.remove(child);
}
std::list<std::shared_ptr<Processor>> Processor::GetChilds() {
return childs_;
}
void Processor::SetPreProcessCallback(PreProcessCallback callback) {
pre_callback_ = std::move(callback);
}
void Processor::SetPostProcessCallback(PostProcessCallback callback) {
post_callback_ = std::move(callback);
}
void Processor::SetProcessCallback(ProcessCallback callback) {
callback_ = std::move(callback);
}
void Processor::Activate(bool parents) {
if (activated_)
return;
if (parents) {
// Activate all parents
Processor *parent = parent_;
while (parent != nullptr) {
parent->Activate();
parent = parent->parent_;
}
}
activated_ = true;
thread_ = std::thread(&Processor::Run, this);
// thread_.detach();
}
void Processor::Deactivate(bool childs) {
if (!activated_)
return;
if (childs) {
// Deactivate all childs
iterate_processors(GetChilds(), [](std::shared_ptr<Processor> proc) {
proc->Deactivate();
});
}
activated_ = false;
{
std::lock_guard<std::mutex> lk(mtx_input_ready_);
input_ready_ = true;
}
cond_input_ready_.notify_all();
thread_.join();
}
bool Processor::IsActivated() {
return activated_;
}
bool Processor::IsIdle() {
std::lock_guard<std::mutex> lk(mtx_state_);
return idle_;
}
bool Processor::Process(const Object &in) {
if (!activated_)
return false;
if (!idle_) {
std::lock_guard<std::mutex> lk(mtx_state_);
if (!idle_) {
++dropped_count_;
return false;
}
}
{
std::lock_guard<std::mutex> lk(mtx_input_ready_);
input_.reset(in.Clone());
input_ready_ = true;
}
cond_input_ready_.notify_all();
return true;
}
Object *Processor::GetOutput() {
std::lock_guard<std::mutex> lk(mtx_result_);
return output_result_.get();
}
std::uint64_t Processor::GetDroppedCount() {
std::lock_guard<std::mutex> lk(mtx_state_);
return dropped_count_;
}
void Processor::Run() {
VLOG(2) << Name() << " thread start";
auto sleep = [this](const times::system_clock::time_point &time_beg) {
if (proc_period_ > 0) {
static times::system_clock::time_point time_prev = time_beg;
auto &&time_elapsed_ms =
times::count<times::milliseconds>(times::now() - time_prev);
time_prev = time_beg;
if (time_elapsed_ms < proc_period_) {
VLOG(2) << Name() << " process cost "
<< times::count<times::milliseconds>(times::now() - time_beg)
<< " ms, sleep " << (proc_period_ - time_elapsed_ms) << " ms";
std::this_thread::sleep_for(
std::chrono::milliseconds(proc_period_ - time_elapsed_ms));
return;
}
}
VLOG(2) << Name() << " process cost "
<< times::count<times::milliseconds>(times::now() - time_beg)
<< " ms";
};
while (true) {
std::unique_lock<std::mutex> lk(mtx_input_ready_);
cond_input_ready_.wait(lk, [this] { return input_ready_; });
auto &&time_beg = times::now();
if (!activated_) {
SetIdle(true);
input_ready_ = false;
break;
}
SetIdle(false);
if (!output_) {
output_.reset(OnCreateOutput());
}
if (pre_callback_) {
pre_callback_(input_.get());
}
bool ok = false;
if (callback_) {
if (callback_(input_.get(), output_.get(), parent_)) {
ok = true;
} else {
ok = OnProcess(input_.get(), output_.get(), parent_);
}
} else {
ok = OnProcess(input_.get(), output_.get(), parent_);
}
if (!ok) {
VLOG(2) << Name() << " process failed";
continue;
}
if (post_callback_) {
post_callback_(output_.get());
}
{
std::unique_lock<std::mutex> lk(mtx_result_);
output_result_.reset(output_->Clone());
}
if (!childs_.empty()) {
for (auto child : childs_) {
child->Process(*output_);
}
}
SetIdle(true);
input_ready_ = false;
sleep(time_beg);
}
VLOG(2) << Name() << " thread end";
}
void Processor::SetIdle(bool idle) {
std::lock_guard<std::mutex> lk(mtx_state_);
idle_ = idle;
}
MYNTEYE_END_NAMESPACE

View File

@@ -0,0 +1,122 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_PROCESSOR_H_ // NOLINT
#define MYNTEYE_PROCESSOR_H_
#pragma once
#include <condition_variable>
#include <cstdint>
#include <functional>
#include <list>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include "mynteye/mynteye.h"
#include "api/processor/object.h"
MYNTEYE_BEGIN_NAMESPACE
class Processor /*: public std::enable_shared_from_this<Processor>*/ {
public:
using PreProcessCallback = std::function<void(Object *const)>;
using PostProcessCallback = std::function<void(Object *const)>;
using ProcessCallback = std::function<bool(
Object *const in, Object *const out, Processor *const parent)>;
explicit Processor(std::int32_t proc_period = 0);
virtual ~Processor();
virtual std::string Name();
void AddChild(const std::shared_ptr<Processor> &child);
void RemoveChild(const std::shared_ptr<Processor> &child);
std::list<std::shared_ptr<Processor>> GetChilds();
void SetPreProcessCallback(PreProcessCallback callback);
void SetPostProcessCallback(PostProcessCallback callback);
void SetProcessCallback(ProcessCallback callback);
void Activate(bool parents = false);
void Deactivate(bool childs = false);
bool IsActivated();
bool IsIdle();
/** Returns dropped or not. */
bool Process(const Object &in);
/**
* Returns the last output.
* @note Returns null if not output now.
*/
Object *GetOutput();
std::uint64_t GetDroppedCount();
protected:
virtual Object *OnCreateOutput() = 0;
virtual bool OnProcess(
Object *const in, Object *const out, Processor *const parent) = 0;
private:
/** Run in standalone thread. */
void Run();
void SetIdle(bool idle);
std::int32_t proc_period_;
bool activated_;
bool input_ready_;
std::mutex mtx_input_ready_;
std::condition_variable cond_input_ready_;
bool idle_;
std::uint64_t dropped_count_;
std::mutex mtx_state_;
std::unique_ptr<Object> input_;
std::unique_ptr<Object> output_;
std::unique_ptr<Object> output_result_;
std::mutex mtx_result_;
PreProcessCallback pre_callback_;
PostProcessCallback post_callback_;
ProcessCallback callback_;
Processor *parent_;
std::list<std::shared_ptr<Processor>> childs_;
std::thread thread_;
};
template <typename T>
void iterate_processors(
const T &processors, std::function<void(std::shared_ptr<Processor>)> fn) {
for (auto &&proc : processors) {
fn(proc);
iterate_processors(proc->GetChilds(), fn);
}
}
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_PROCESSOR_H_ NOLINT

View File

@@ -0,0 +1,95 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/processor/rectify_processor.h"
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <glog/logging.h>
#include <utility>
#include "device/device.h"
MYNTEYE_BEGIN_NAMESPACE
RectifyProcessor::RectifyProcessor(
std::shared_ptr<Device> device, std::int32_t proc_period)
: Processor(std::move(proc_period)) {
VLOG(2) << __func__ << ": proc_period=" << proc_period;
InitParams(
device->GetIntrinsics(Stream::LEFT), device->GetIntrinsics(Stream::RIGHT),
device->GetExtrinsics(Stream::LEFT, Stream::RIGHT));
}
RectifyProcessor::~RectifyProcessor() {
VLOG(2) << __func__;
}
std::string RectifyProcessor::Name() {
return NAME;
}
Object *RectifyProcessor::OnCreateOutput() {
return new ObjMat2();
}
bool RectifyProcessor::OnProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
ObjMat2 *output = Object::Cast<ObjMat2>(out);
cv::remap(input->first, output->first, map11, map12, cv::INTER_LINEAR);
cv::remap(input->second, output->second, map21, map22, cv::INTER_LINEAR);
return true;
}
void RectifyProcessor::InitParams(
Intrinsics in_left, Intrinsics in_right, Extrinsics ex_left_to_right) {
cv::Size size{in_left.width, in_left.height};
cv::Mat M1 =
(cv::Mat_<double>(3, 3) << in_left.fx, 0, in_left.cx, 0, in_left.fy,
in_left.cy, 0, 0, 1);
cv::Mat M2 =
(cv::Mat_<double>(3, 3) << in_right.fx, 0, in_right.cx, 0, in_right.fy,
in_right.cy, 0, 0, 1);
cv::Mat D1(1, 5, CV_64F, in_left.coeffs);
cv::Mat D2(1, 5, CV_64F, in_right.coeffs);
cv::Mat R =
(cv::Mat_<double>(3, 3) << ex_left_to_right.rotation[0][0],
ex_left_to_right.rotation[0][1], ex_left_to_right.rotation[0][2],
ex_left_to_right.rotation[1][0], ex_left_to_right.rotation[1][1],
ex_left_to_right.rotation[1][2], ex_left_to_right.rotation[2][0],
ex_left_to_right.rotation[2][1], ex_left_to_right.rotation[2][2]);
cv::Mat T(3, 1, CV_64F, ex_left_to_right.translation);
VLOG(2) << "InitParams size: " << size;
VLOG(2) << "M1: " << M1;
VLOG(2) << "M2: " << M2;
VLOG(2) << "D1: " << D1;
VLOG(2) << "D2: " << D2;
VLOG(2) << "R: " << R;
VLOG(2) << "T: " << T;
cv::Rect left_roi, right_roi;
cv::stereoRectify(
M1, D1, M2, D2, size, R, T, R1, R2, P1, P2, Q, cv::CALIB_ZERO_DISPARITY,
0, size, &left_roi, &right_roi);
cv::initUndistortRectifyMap(M1, D1, R1, P1, size, CV_16SC2, map11, map12);
cv::initUndistortRectifyMap(M2, D2, R2, P2, size, CV_16SC2, map21, map22);
}
MYNTEYE_END_NAMESPACE

View File

@@ -0,0 +1,55 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_RECTIFY_PROCESSOR_H_ // NOLINT
#define MYNTEYE_RECTIFY_PROCESSOR_H_
#pragma once
#include <opencv2/core/core.hpp>
#include <memory>
#include <string>
#include "api/processor/processor.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
class Device;
class RectifyProcessor : public Processor {
public:
static constexpr auto &&NAME = "RectifyProcessor";
RectifyProcessor(
std::shared_ptr<Device> device, std::int32_t proc_period = 0);
virtual ~RectifyProcessor();
std::string Name() override;
cv::Mat R1, P1, R2, P2, Q;
cv::Mat map11, map12, map21, map22;
protected:
Object *OnCreateOutput() override;
bool OnProcess(
Object *const in, Object *const out, Processor *const parent) override;
private:
void InitParams(
Intrinsics in_left, Intrinsics in_right, Extrinsics ex_left_to_right);
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_RECTIFY_PROCESSOR_H_ NOLINT

587
src/api/synthetic.cc Normal file
View File

@@ -0,0 +1,587 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "api/synthetic.h"
#include <glog/logging.h>
#include <algorithm>
#include <functional>
#include <stdexcept>
#include "api/plugin.h"
#include "api/processor/depth_processor.h"
#include "api/processor/disparity_normalized_processor.h"
#include "api/processor/disparity_processor.h"
#include "api/processor/object.h"
#include "api/processor/points_processor.h"
#include "api/processor/processor.h"
#include "api/processor/rectify_processor.h"
#include "device/device.h"
#define RECTIFY_PROC_PERIOD 0
#define DISPARITY_PROC_PERIOD 0
#define DISPARITY_NORM_PROC_PERIOD 0
#define POINTS_PROC_PERIOD 0
#define DEPTH_PROC_PERIOD 0
MYNTEYE_BEGIN_NAMESPACE
namespace {
cv::Mat frame2mat(const std::shared_ptr<device::Frame> &frame) {
// TODO(JohnZhao) Support different format frame to cv::Mat
CHECK_EQ(frame->format(), Format::GREY);
return cv::Mat(frame->height(), frame->width(), CV_8UC1, frame->data());
}
api::StreamData data2api(const device::StreamData &data) {
return {data.img, frame2mat(data.frame), data.frame};
}
} // namespace
Synthetic::Synthetic(API *api) : api_(api), plugin_(nullptr) {
VLOG(2) << __func__;
CHECK_NOTNULL(api_);
InitStreamSupports();
InitProcessors();
}
Synthetic::~Synthetic() {
VLOG(2) << __func__;
if (processor_) {
processor_->Deactivate(true);
processor_ = nullptr;
}
}
bool Synthetic::Supports(const Stream &stream) const {
return stream_supports_mode_.find(stream) != stream_supports_mode_.end();
}
Synthetic::mode_t Synthetic::SupportsMode(const Stream &stream) const {
try {
return stream_supports_mode_.at(stream);
} catch (const std::out_of_range &e) {
return MODE_LAST;
}
}
void Synthetic::EnableStreamData(const Stream &stream) {
EnableStreamData(stream, 0);
}
void Synthetic::DisableStreamData(const Stream &stream) {
DisableStreamData(stream, 0);
}
bool Synthetic::IsStreamDataEnabled(const Stream &stream) const {
return stream_enabled_mode_.find(stream) != stream_enabled_mode_.end();
}
void Synthetic::SetStreamCallback(
const Stream &stream, stream_callback_t callback) {
if (callback == nullptr) {
stream_callbacks_.erase(stream);
} else {
stream_callbacks_[stream] = callback;
}
}
bool Synthetic::HasStreamCallback(const Stream &stream) const {
return stream_callbacks_.find(stream) != stream_callbacks_.end();
}
void Synthetic::StartVideoStreaming() {
auto &&device = api_->device();
for (auto &&it = stream_supports_mode_.begin();
it != stream_supports_mode_.end(); it++) {
if (it->second == MODE_NATIVE) {
auto &&stream = it->first;
device->SetStreamCallback(
stream,
[this, stream](const device::StreamData &data) {
auto &&stream_data = data2api(data);
ProcessNativeStream(stream, stream_data);
// Need mutex if set callback after start
if (HasStreamCallback(stream)) {
stream_callbacks_.at(stream)(stream_data);
}
},
true);
}
}
device->Start(Source::VIDEO_STREAMING);
}
void Synthetic::StopVideoStreaming() {
auto &&device = api_->device();
for (auto &&it = stream_supports_mode_.begin();
it != stream_supports_mode_.end(); it++) {
if (it->second == MODE_NATIVE) {
device->SetStreamCallback(it->first, nullptr);
}
}
device->Stop(Source::VIDEO_STREAMING);
}
void Synthetic::WaitForStreams() {
api_->device()->WaitForStreams();
}
api::StreamData Synthetic::GetStreamData(const Stream &stream) {
auto &&mode = GetStreamEnabledMode(stream);
if (mode == MODE_NATIVE) {
auto &&device = api_->device();
return data2api(device->GetLatestStreamData(stream));
} else if (mode == MODE_SYNTHETIC) {
switch (stream) {
case Stream::LEFT_RECTIFIED: {
auto &&processor = find_processor<RectifyProcessor>(processor_);
Object *out = processor->GetOutput();
if (out != nullptr) {
ObjMat2 *output = Object::Cast<ObjMat2>(out);
return {nullptr, output->first, nullptr};
}
VLOG(2) << "Rectify not ready now";
} break;
case Stream::RIGHT_RECTIFIED: {
auto &&processor = find_processor<RectifyProcessor>(processor_);
Object *out = processor->GetOutput();
if (out != nullptr) {
ObjMat2 *output = Object::Cast<ObjMat2>(out);
return {nullptr, output->second, nullptr};
}
VLOG(2) << "Rectify not ready now";
} break;
case Stream::DISPARITY: {
auto &&processor = find_processor<DisparityProcessor>(processor_);
Object *out = processor->GetOutput();
if (out != nullptr) {
ObjMat *output = Object::Cast<ObjMat>(out);
return {nullptr, output->value, nullptr};
}
VLOG(2) << "Disparity not ready now";
} break;
case Stream::DISPARITY_NORMALIZED: {
auto &&processor =
find_processor<DisparityNormalizedProcessor>(processor_);
Object *out = processor->GetOutput();
if (out != nullptr) {
ObjMat *output = Object::Cast<ObjMat>(out);
return {nullptr, output->value, nullptr};
}
VLOG(2) << "Disparity normalized not ready now";
} break;
case Stream::POINTS: {
auto &&processor = find_processor<PointsProcessor>(processor_);
Object *out = processor->GetOutput();
if (out != nullptr) {
ObjMat *output = Object::Cast<ObjMat>(out);
return {nullptr, output->value, nullptr};
}
VLOG(2) << "Points not ready now";
} break;
case Stream::DEPTH: {
auto &&processor = find_processor<DepthProcessor>(processor_);
Object *out = processor->GetOutput();
if (out != nullptr) {
ObjMat *output = Object::Cast<ObjMat>(out);
return {nullptr, output->value, nullptr};
}
VLOG(2) << "Depth not ready now";
} break;
default:
break;
}
return {}; // frame.empty() == true
} else {
LOG(ERROR) << "Failed to get stream data of " << stream
<< ", unsupported or disabled";
return {}; // frame.empty() == true
}
}
std::vector<api::StreamData> Synthetic::GetStreamDatas(const Stream &stream) {
auto &&mode = GetStreamEnabledMode(stream);
if (mode == MODE_NATIVE) {
auto &&device = api_->device();
std::vector<api::StreamData> datas;
for (auto &&data : device->GetStreamDatas(stream)) {
datas.push_back(data2api(data));
}
return datas;
} else if (mode == MODE_SYNTHETIC) {
return {GetStreamData(stream)};
} else {
LOG(ERROR) << "Failed to get stream data of " << stream
<< ", unsupported or disabled";
}
return {};
}
void Synthetic::SetPlugin(std::shared_ptr<Plugin> plugin) {
plugin_ = plugin;
}
bool Synthetic::HasPlugin() const {
return plugin_ != nullptr;
}
void Synthetic::InitStreamSupports() {
auto &&device = api_->device();
if (device->Supports(Stream::LEFT) && device->Supports(Stream::RIGHT)) {
stream_supports_mode_[Stream::LEFT] = MODE_NATIVE;
stream_supports_mode_[Stream::RIGHT] = MODE_NATIVE;
std::vector<Stream> stream_chain{
Stream::LEFT_RECTIFIED, Stream::RIGHT_RECTIFIED,
Stream::DISPARITY, Stream::DISPARITY_NORMALIZED,
Stream::POINTS, Stream::DEPTH};
for (auto &&stream : stream_chain) {
if (device->Supports(stream)) {
stream_supports_mode_[stream] = MODE_NATIVE;
} else {
stream_supports_mode_[stream] = MODE_SYNTHETIC;
}
}
}
// Enabled native streams by default
for (auto &&it = stream_supports_mode_.begin();
it != stream_supports_mode_.end(); it++) {
if (it->second == MODE_NATIVE) {
stream_enabled_mode_[it->first] = MODE_NATIVE;
}
}
}
Synthetic::mode_t Synthetic::GetStreamEnabledMode(const Stream &stream) const {
try {
return stream_enabled_mode_.at(stream);
} catch (const std::out_of_range &e) {
return MODE_LAST;
}
}
bool Synthetic::IsStreamEnabledNative(const Stream &stream) const {
return GetStreamEnabledMode(stream) == MODE_NATIVE;
}
bool Synthetic::IsStreamEnabledSynthetic(const Stream &stream) const {
return GetStreamEnabledMode(stream) == MODE_SYNTHETIC;
}
void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) {
if (IsStreamDataEnabled(stream))
return;
// Activate processors of synthetic stream
switch (stream) {
case Stream::LEFT_RECTIFIED: {
if (!IsStreamDataEnabled(Stream::LEFT))
break;
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
CHECK(ActivateProcessor<RectifyProcessor>());
}
return;
case Stream::RIGHT_RECTIFIED: {
if (!IsStreamDataEnabled(Stream::RIGHT))
break;
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
CHECK(ActivateProcessor<RectifyProcessor>());
}
return;
case Stream::DISPARITY: {
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
EnableStreamData(Stream::LEFT_RECTIFIED, depth + 1);
EnableStreamData(Stream::RIGHT_RECTIFIED, depth + 1);
CHECK(ActivateProcessor<DisparityProcessor>());
}
return;
case Stream::DISPARITY_NORMALIZED: {
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
EnableStreamData(Stream::DISPARITY, depth + 1);
CHECK(ActivateProcessor<DisparityNormalizedProcessor>());
}
return;
case Stream::POINTS: {
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
EnableStreamData(Stream::DISPARITY, depth + 1);
CHECK(ActivateProcessor<PointsProcessor>());
}
return;
case Stream::DEPTH: {
stream_enabled_mode_[stream] = MODE_SYNTHETIC;
EnableStreamData(Stream::POINTS, depth + 1);
CHECK(ActivateProcessor<DepthProcessor>());
}
return;
default:
break;
}
if (depth == 0) {
LOG(WARNING) << "Enable stream data of " << stream << " failed";
}
}
void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) {
if (!IsStreamDataEnabled(stream))
return;
// Deactivate processors of synthetic stream
if (stream_enabled_mode_[stream] != MODE_NATIVE) {
stream_enabled_mode_.erase(stream);
switch (stream) {
case Stream::LEFT_RECTIFIED: {
if (IsStreamEnabledSynthetic(Stream::RIGHT_RECTIFIED)) {
DisableStreamData(Stream::RIGHT_RECTIFIED, depth + 1);
}
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
DisableStreamData(Stream::DISPARITY, depth + 1);
}
DeactivateProcessor<RectifyProcessor>();
} break;
case Stream::RIGHT_RECTIFIED: {
if (IsStreamEnabledSynthetic(Stream::LEFT_RECTIFIED)) {
DisableStreamData(Stream::LEFT_RECTIFIED, depth + 1);
}
if (IsStreamEnabledSynthetic(Stream::DISPARITY)) {
DisableStreamData(Stream::DISPARITY, depth + 1);
}
DeactivateProcessor<RectifyProcessor>();
} break;
case Stream::DISPARITY: {
if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) {
DisableStreamData(Stream::DISPARITY_NORMALIZED, depth + 1);
}
if (IsStreamEnabledSynthetic(Stream::POINTS)) {
DisableStreamData(Stream::POINTS, depth + 1);
}
DeactivateProcessor<DisparityProcessor>();
} break;
case Stream::DISPARITY_NORMALIZED: {
DeactivateProcessor<DisparityNormalizedProcessor>();
} break;
case Stream::POINTS: {
if (IsStreamEnabledSynthetic(Stream::DEPTH)) {
DisableStreamData(Stream::DEPTH, depth + 1);
}
DeactivateProcessor<PointsProcessor>();
} break;
case Stream::DEPTH: {
DeactivateProcessor<DepthProcessor>();
} break;
default:
return;
}
if (depth > 0) {
LOG(WARNING) << "Disable synthetic stream data of " << stream << " too";
}
} else if (depth == 0) {
LOG(WARNING) << "Disable native stream data of " << stream << " failed";
}
}
void Synthetic::InitProcessors() {
auto &&rectify_processor =
std::make_shared<RectifyProcessor>(api_->device(), RECTIFY_PROC_PERIOD);
auto &&disparity_processor =
std::make_shared<DisparityProcessor>(DISPARITY_PROC_PERIOD);
auto &&disparitynormalized_processor =
std::make_shared<DisparityNormalizedProcessor>(
DISPARITY_NORM_PROC_PERIOD);
auto &&points_processor = std::make_shared<PointsProcessor>(
rectify_processor->Q, POINTS_PROC_PERIOD);
auto &&depth_processor = std::make_shared<DepthProcessor>(DEPTH_PROC_PERIOD);
using namespace std::placeholders; // NOLINT
rectify_processor->SetProcessCallback(
std::bind(&Synthetic::OnRectifyProcess, this, _1, _2, _3));
disparity_processor->SetProcessCallback(
std::bind(&Synthetic::OnDisparityProcess, this, _1, _2, _3));
disparitynormalized_processor->SetProcessCallback(
std::bind(&Synthetic::OnDisparityNormalizedProcess, this, _1, _2, _3));
points_processor->SetProcessCallback(
std::bind(&Synthetic::OnPointsProcess, this, _1, _2, _3));
depth_processor->SetProcessCallback(
std::bind(&Synthetic::OnDepthProcess, this, _1, _2, _3));
rectify_processor->SetPostProcessCallback(
std::bind(&Synthetic::OnRectifyPostProcess, this, _1));
disparity_processor->SetPostProcessCallback(
std::bind(&Synthetic::OnDisparityPostProcess, this, _1));
disparitynormalized_processor->SetPostProcessCallback(
std::bind(&Synthetic::OnDisparityNormalizedPostProcess, this, _1));
points_processor->SetPostProcessCallback(
std::bind(&Synthetic::OnPointsPostProcess, this, _1));
depth_processor->SetPostProcessCallback(
std::bind(&Synthetic::OnDepthPostProcess, this, _1));
rectify_processor->AddChild(disparity_processor);
disparity_processor->AddChild(disparitynormalized_processor);
disparity_processor->AddChild(points_processor);
points_processor->AddChild(depth_processor);
processor_ = rectify_processor;
}
void Synthetic::ProcessNativeStream(
const Stream &stream, const api::StreamData &data) {
bool done = false;
static api::StreamData left_data, right_data;
if (stream == Stream::LEFT) {
left_data = data;
done = true;
} else if (stream == Stream::RIGHT) {
right_data = data;
done = true;
}
if (done && left_data.img && right_data.img &&
left_data.img->frame_id == right_data.img->frame_id) {
auto &&processor = find_processor<RectifyProcessor>(processor_);
processor->Process(ObjMat2{left_data.frame, right_data.frame});
}
if (done)
return;
auto &&process_childs = [this, &stream](
const std::string &name, const Object &obj) {
auto &&processor = find_processor<Processor>(processor_, name);
for (auto child : processor->GetChilds()) {
child->Process(obj);
}
};
static api::StreamData left_rect_data, right_rect_data;
if (stream == Stream::LEFT_RECTIFIED) {
left_rect_data = data;
done = true;
} else if (stream == Stream::RIGHT_RECTIFIED) {
right_rect_data = data;
done = true;
}
if (done && left_rect_data.img && right_rect_data.img &&
left_rect_data.img->frame_id == right_rect_data.img->frame_id) {
process_childs(
RectifyProcessor::NAME,
ObjMat2{left_rect_data.frame, right_rect_data.frame});
}
if (done)
return;
switch (stream) {
case Stream::DISPARITY: {
process_childs(DisparityProcessor::NAME, ObjMat{data.frame});
} break;
case Stream::DISPARITY_NORMALIZED: {
process_childs(DisparityNormalizedProcessor::NAME, ObjMat{data.frame});
} break;
case Stream::POINTS: {
process_childs(PointsProcessor::NAME, ObjMat{data.frame});
} break;
case Stream::DEPTH: {
process_childs(DepthProcessor::NAME, ObjMat{data.frame});
} break;
default:
break;
}
}
bool Synthetic::OnRectifyProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
if (plugin_ && plugin_->OnRectifyProcess(in, out)) {
return true;
}
return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_SYNTHETIC;
// && GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_SYNTHETIC
}
bool Synthetic::OnDisparityProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
if (plugin_ && plugin_->OnDisparityProcess(in, out)) {
return true;
}
return GetStreamEnabledMode(Stream::DISPARITY) != MODE_SYNTHETIC;
}
bool Synthetic::OnDisparityNormalizedProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
if (plugin_ && plugin_->OnDisparityNormalizedProcess(in, out)) {
return true;
}
return GetStreamEnabledMode(Stream::DISPARITY_NORMALIZED) != MODE_SYNTHETIC;
}
bool Synthetic::OnPointsProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
if (plugin_ && plugin_->OnPointsProcess(in, out)) {
return true;
}
return GetStreamEnabledMode(Stream::POINTS) != MODE_SYNTHETIC;
}
bool Synthetic::OnDepthProcess(
Object *const in, Object *const out, Processor *const parent) {
UNUSED(parent)
if (plugin_ && plugin_->OnDepthProcess(in, out)) {
return true;
}
return GetStreamEnabledMode(Stream::DEPTH) != MODE_SYNTHETIC;
}
void Synthetic::OnRectifyPostProcess(Object *const out) {
const ObjMat2 *output = Object::Cast<ObjMat2>(out);
if (HasStreamCallback(Stream::LEFT_RECTIFIED)) {
stream_callbacks_.at(Stream::LEFT_RECTIFIED)(
{nullptr, output->first, nullptr});
}
if (HasStreamCallback(Stream::RIGHT_RECTIFIED)) {
stream_callbacks_.at(Stream::RIGHT_RECTIFIED)(
{nullptr, output->second, nullptr});
}
}
void Synthetic::OnDisparityPostProcess(Object *const out) {
const ObjMat *output = Object::Cast<ObjMat>(out);
if (HasStreamCallback(Stream::DISPARITY)) {
stream_callbacks_.at(Stream::DISPARITY)({nullptr, output->value, nullptr});
}
}
void Synthetic::OnDisparityNormalizedPostProcess(Object *const out) {
const ObjMat *output = Object::Cast<ObjMat>(out);
if (HasStreamCallback(Stream::DISPARITY_NORMALIZED)) {
stream_callbacks_.at(Stream::DISPARITY_NORMALIZED)(
{nullptr, output->value, nullptr});
}
}
void Synthetic::OnPointsPostProcess(Object *const out) {
const ObjMat *output = Object::Cast<ObjMat>(out);
if (HasStreamCallback(Stream::POINTS)) {
stream_callbacks_.at(Stream::POINTS)({nullptr, output->value, nullptr});
}
}
void Synthetic::OnDepthPostProcess(Object *const out) {
const ObjMat *output = Object::Cast<ObjMat>(out);
if (HasStreamCallback(Stream::DEPTH)) {
stream_callbacks_.at(Stream::DEPTH)({nullptr, output->value, nullptr});
}
}
MYNTEYE_END_NAMESPACE

172
src/api/synthetic.h Normal file
View File

@@ -0,0 +1,172 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_SYNTHETIC_H_ // NOLINT
#define MYNTEYE_SYNTHETIC_H_
#pragma once
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "api/api.h"
MYNTEYE_BEGIN_NAMESPACE
class API;
class Plugin;
class Processor;
struct Object;
class Synthetic {
public:
using stream_callback_t = API::stream_callback_t;
typedef enum Mode {
MODE_NATIVE, // Native stream
MODE_SYNTHETIC, // Synthetic stream
MODE_LAST // Unsupported
} mode_t;
explicit Synthetic(API *api);
~Synthetic();
bool Supports(const Stream &stream) const;
mode_t SupportsMode(const Stream &stream) const;
void EnableStreamData(const Stream &stream);
void DisableStreamData(const Stream &stream);
bool IsStreamDataEnabled(const Stream &stream) const;
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
bool HasStreamCallback(const Stream &stream) const;
void StartVideoStreaming();
void StopVideoStreaming();
void WaitForStreams();
api::StreamData GetStreamData(const Stream &stream);
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
void SetPlugin(std::shared_ptr<Plugin> plugin);
bool HasPlugin() const;
private:
void InitStreamSupports();
mode_t GetStreamEnabledMode(const Stream &stream) const;
bool IsStreamEnabledNative(const Stream &stream) const;
bool IsStreamEnabledSynthetic(const Stream &stream) const;
void EnableStreamData(const Stream &stream, std::uint32_t depth);
void DisableStreamData(const Stream &stream, std::uint32_t depth);
void InitProcessors();
template <class T>
bool ActivateProcessor(bool tree = false);
template <class T>
bool DeactivateProcessor(bool tree = false);
void ProcessNativeStream(const Stream &stream, const api::StreamData &data);
bool OnRectifyProcess(
Object *const in, Object *const out, Processor *const parent);
bool OnDisparityProcess(
Object *const in, Object *const out, Processor *const parent);
bool OnDisparityNormalizedProcess(
Object *const in, Object *const out, Processor *const parent);
bool OnPointsProcess(
Object *const in, Object *const out, Processor *const parent);
bool OnDepthProcess(
Object *const in, Object *const out, Processor *const parent);
void OnRectifyPostProcess(Object *const out);
void OnDisparityPostProcess(Object *const out);
void OnDisparityNormalizedPostProcess(Object *const out);
void OnPointsPostProcess(Object *const out);
void OnDepthPostProcess(Object *const out);
API *api_;
std::map<Stream, mode_t> stream_supports_mode_;
std::map<Stream, mode_t> stream_enabled_mode_;
std::map<Stream, stream_callback_t> stream_callbacks_;
std::shared_ptr<Processor> processor_;
std::shared_ptr<Plugin> plugin_;
};
template <class T, class P>
std::shared_ptr<T> find_processor(const P &processor) {
return find_processor<T>(processor, T::NAME);
}
template <class T, class P>
std::shared_ptr<T> find_processor(const P &processor, const std::string &name) {
if (processor->Name() == name) {
return std::dynamic_pointer_cast<T>(processor);
}
auto &&childs = processor->GetChilds();
return find_processor<T>(std::begin(childs), std::end(childs), name);
}
template <class T, class InputIt>
std::shared_ptr<T> find_processor(
InputIt first, InputIt last, const std::string &name) {
if (first == last)
return nullptr;
for (auto it = first; it != last; ++it) {
if ((*it)->Name() == name) {
return std::dynamic_pointer_cast<T>(*it);
}
}
for (auto it = first; it != last; ++it) {
auto &&childs = (*it)->GetChilds();
if (childs.empty())
continue;
auto &&result =
find_processor<T>(std::begin(childs), std::end(childs), name);
if (result == nullptr)
continue;
return result;
}
return nullptr;
}
template <class T>
bool Synthetic::ActivateProcessor(bool parents) {
auto &&processor = find_processor<T>(processor_);
if (processor == nullptr)
return false;
processor->Activate(parents);
return true;
}
template <class T>
bool Synthetic::DeactivateProcessor(bool childs) {
auto &&processor = find_processor<T>(processor_);
if (processor == nullptr)
return false;
processor->Deactivate(childs);
return true;
}
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_SYNTHETIC_H_ NOLINT

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "device/context.h"
#include <glog/logging.h>

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_CONTEXT_H_ // NOLINT
#define MYNTEYE_CONTEXT_H_
#pragma once
@@ -17,11 +30,18 @@ struct context;
class Device;
class Context {
/**
* The context about devices.
*/
class MYNTEYE_API Context {
public:
Context();
~Context();
/**
* Get all devices now.
* @return a vector of all devices.
*/
std::vector<std::shared_ptr<Device>> devices() const {
return devices_;
}

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "device/device.h"
#include <glog/logging.h>
@@ -7,11 +20,13 @@
#include <utility>
#include "device/device_s.h"
#include "internal/async_callback.h"
#include "internal/channels.h"
#include "internal/config.h"
#include "internal/motions.h"
#include "internal/streams.h"
#include "internal/strings.h"
#include "internal/times.h"
#include "internal/types.h"
#include "uvc/uvc.h"
@@ -91,6 +106,20 @@ bool Device::Supports(const Option &option) const {
return supports.find(option) != supports.end();
}
bool Device::Supports(const AddOns &addon) const {
CHECK_NOTNULL(device_info_);
auto &&hw_flag = device_info_->hardware_version.flag();
switch (addon) {
case AddOns::INFRARED:
return hw_flag[0];
case AddOns::INFRARED2:
return hw_flag[1];
default:
LOG(WARNING) << "Unknown add-on";
return false;
}
}
const std::vector<StreamRequest> &Device::GetStreamRequests(
const Capabilities &capability) const {
if (!Supports(capability)) {
@@ -110,8 +139,9 @@ void Device::ConfigStreamRequest(
auto &&requests = GetStreamRequests(capability);
if (std::find(requests.cbegin(), requests.cend(), request) ==
requests.cend()) {
LOG(FATAL) << "Config stream request of " << capability
<< " is not accpected";
LOG(WARNING) << "Config stream request of " << capability
<< " is not accpected";
return;
}
stream_config_requests_[capability] = request;
}
@@ -123,64 +153,87 @@ std::shared_ptr<DeviceInfo> Device::GetInfo() const {
std::string Device::GetInfo(const Info &info) const {
CHECK_NOTNULL(device_info_);
switch (info) {
case Info::DEVICE_NAME: {
case Info::DEVICE_NAME:
return device_info_->name;
} break;
case Info::SERIAL_NUMBER: {
case Info::SERIAL_NUMBER:
return device_info_->serial_number;
} break;
case Info::FIRMWARE_VERSION: {
case Info::FIRMWARE_VERSION:
return device_info_->firmware_version.to_string();
} break;
case Info::HARDWARE_VERSION: {
case Info::HARDWARE_VERSION:
return device_info_->hardware_version.to_string();
} break;
case Info::SPEC_VERSION: {
case Info::SPEC_VERSION:
return device_info_->spec_version.to_string();
} break;
case Info::LENS_TYPE: {
case Info::LENS_TYPE:
return device_info_->lens_type.to_string();
} break;
case Info::IMU_TYPE: {
case Info::IMU_TYPE:
return device_info_->imu_type.to_string();
} break;
case Info::NOMINAL_BASELINE: {
case Info::NOMINAL_BASELINE:
return std::to_string(device_info_->nominal_baseline);
} break;
default: { LOG(FATAL) << "Unknown device info"; }
default:
LOG(WARNING) << "Unknown device info";
return "";
}
}
ImgIntrinsics Device::GetImgIntrinsics() const {
return img_intrinsics_;
Intrinsics Device::GetIntrinsics(const Stream &stream) const {
try {
return stream_intrinsics_.at(stream);
} catch (const std::out_of_range &e) {
LOG(WARNING) << "Intrinsics of " << stream << " not found";
return {};
}
}
ImgExtrinsics Device::GetImgExtrinsics() const {
return img_extrinsics_;
Extrinsics Device::GetExtrinsics(const Stream &from, const Stream &to) const {
try {
return stream_from_extrinsics_.at(from).at(to);
} catch (const std::out_of_range &e) {
try {
return stream_from_extrinsics_.at(to).at(from).Inverse();
} catch (const std::out_of_range &e) {
LOG(WARNING) << "Extrinsics from " << from << " to " << to
<< " not found";
return {};
}
}
}
void Device::SetImgIntrinsics(const ImgIntrinsics &in) {
img_intrinsics_ = std::move(in);
MotionIntrinsics Device::GetMotionIntrinsics() const {
if (motion_intrinsics_) {
return *motion_intrinsics_;
} else {
LOG(WARNING) << "Motion intrinsics not found";
return {};
}
}
void Device::SetImgExtrinsics(const ImgExtrinsics &ex) {
img_extrinsics_ = std::move(ex);
Extrinsics Device::GetMotionExtrinsics(const Stream &from) const {
try {
return motion_from_extrinsics_.at(from);
} catch (const std::out_of_range &e) {
LOG(WARNING) << "Motion extrinsics from " << from << " not found";
return {};
}
}
ImuIntrinsics Device::GetImuIntrinsics() const {
return imu_intrinsics_;
void Device::SetIntrinsics(const Stream &stream, const Intrinsics &in) {
stream_intrinsics_[stream] = in;
}
ImuExtrinsics Device::GetImuExtrinsics() const {
return imu_extrinsics_;
void Device::SetExtrinsics(
const Stream &from, const Stream &to, const Extrinsics &ex) {
stream_from_extrinsics_[from][to] = ex;
}
void Device::SetImuIntrinsics(const ImuIntrinsics &in) {
imu_intrinsics_ = std::move(in);
void Device::SetMotionIntrinsics(const MotionIntrinsics &in) {
if (motion_intrinsics_ == nullptr) {
motion_intrinsics_ = std::make_shared<MotionIntrinsics>();
}
*motion_intrinsics_ = in;
}
void Device::SetImuExtrinsics(const ImuExtrinsics &ex) {
imu_extrinsics_ = std::move(ex);
void Device::SetMotionExtrinsics(const Stream &from, const Extrinsics &ex) {
motion_from_extrinsics_[from] = ex;
}
void Device::LogOptionInfos() const {
@@ -221,20 +274,32 @@ bool Device::RunOptionAction(const Option &option) const {
}
void Device::SetStreamCallback(
const Stream &stream, stream_callback_t callback) {
const Stream &stream, stream_callback_t callback, bool async) {
if (!Supports(stream)) {
LOG(WARNING) << "Unsupported stream: " << stream;
return;
}
if (callback) {
stream_callbacks_[stream] = callback;
if (async)
stream_async_callbacks_[stream] =
std::make_shared<stream_async_callback_t>(
to_string(stream), callback);
} else {
stream_callbacks_.erase(stream);
stream_async_callbacks_.erase(stream);
}
}
void Device::SetMotionCallback(motion_callback_t callback) {
void Device::SetMotionCallback(motion_callback_t callback, bool async) {
motion_callback_ = callback;
if (callback) {
if (async)
motion_async_callback_ =
std::make_shared<motion_async_callback_t>("motion", callback, true);
} else {
motion_async_callback_ = nullptr;
}
}
bool Device::HasStreamCallback(const Stream &stream) const {
@@ -258,7 +323,7 @@ void Device::Start(const Source &source) {
Start(Source::VIDEO_STREAMING);
Start(Source::MOTION_TRACKING);
} else {
LOG(FATAL) << "Unsupported source :(";
LOG(ERROR) << "Unsupported source :(";
}
}
@@ -273,7 +338,7 @@ void Device::Stop(const Source &source) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Stop(Source::VIDEO_STREAMING);
} else {
LOG(FATAL) << "Unsupported source :(";
LOG(ERROR) << "Unsupported source :(";
}
}
@@ -313,8 +378,8 @@ const StreamRequest &Device::GetStreamRequest(const Capabilities &capability) {
return stream_config_requests_.at(capability);
} catch (const std::out_of_range &e) {
auto &&requests = GetStreamRequests(capability);
if (requests.size() == 1) {
VLOG(2) << "Get the only one stream request of " << capability;
if (requests.size() >= 1) {
VLOG(2) << "Select the first one stream request of " << capability;
return requests[0];
} else {
LOG(FATAL) << "Please config the stream request of " << capability;
@@ -352,27 +417,27 @@ void Device::StartVideoStreaming() {
uvc::set_device_mode(
*device_, stream_request.width, stream_request.height,
static_cast<int>(stream_request.format), stream_request.fps,
[this](const void *data) {
[this](const void *data, std::function<void()> continuation) {
// drop the first stereo stream data
static std::uint8_t drop_count = 1;
if (drop_count > 0) {
--drop_count;
continuation();
return;
}
std::lock_guard<std::mutex> _(mtx_streams_);
streams_->PushStream(Capabilities::STEREO, data);
if (HasStreamCallback(Stream::LEFT)) {
auto &&stream_datas = streams_->stream_datas(Stream::LEFT);
if (stream_datas.size() > 0) {
stream_callbacks_.at(Stream::LEFT)(stream_datas.back());
}
}
if (HasStreamCallback(Stream::RIGHT)) {
auto &&stream_datas = streams_->stream_datas(Stream::RIGHT);
if (stream_datas.size() > 0) {
stream_callbacks_.at(Stream::RIGHT)(stream_datas.back());
// auto &&time_beg = times::now();
{
std::lock_guard<std::mutex> _(mtx_streams_);
if (streams_->PushStream(Capabilities::STEREO, data)) {
CallbackPushedStreamData(Stream::LEFT);
CallbackPushedStreamData(Stream::RIGHT);
}
}
continuation();
OnStereoStreamUpdate();
// VLOG(2) << "Stereo video callback cost "
// << times::count<times::milliseconds>(times::now() - time_beg)
// << " ms";
});
} else {
LOG(FATAL) << "Not any stream capabilities are supported by this device";
@@ -399,12 +464,9 @@ void Device::StartMotionTracking() {
LOG(WARNING) << "Cannot start motion tracking without first stopping it";
return;
}
motions_->SetMotionCallback([this](const device::MotionData &data) {
if (motion_callback_) {
motion_callback_(data);
}
});
motions_->StartMotionTracking();
motions_->SetMotionCallback(
std::bind(&Device::CallbackMotionData, this, std::placeholders::_1));
// motions_->StartMotionTracking();
motion_tracking_ = true;
}
@@ -413,10 +475,12 @@ void Device::StopMotionTracking() {
LOG(WARNING) << "Cannot stop motion tracking without first starting it";
return;
}
motions_->StopMotionTracking();
// motions_->StopMotionTracking();
motion_tracking_ = false;
}
void Device::OnStereoStreamUpdate() {}
void Device::ReadAllInfos() {
device_info_ = std::make_shared<DeviceInfo>();
@@ -424,33 +488,63 @@ void Device::ReadAllInfos() {
Channels::img_params_t img_params;
Channels::imu_params_t imu_params;
if (!channels_->GetFiles(device_info_.get(), &img_params, &imu_params)) {
// LOG(FATAL) << "Read device infos failed :(";
LOG(FATAL) << "Read device infos failed. Please upgrade your firmware to "
"the latest version.";
}
VLOG(2) << "Device info: {name: " << device_info_->name
<< ", serial_number: " << device_info_->serial_number
<< ", firmware_version: "
<< device_info_->firmware_version.to_string()
<< ", hardware_version: "
<< device_info_->hardware_version.to_string()
<< ", spec_version: " << device_info_->spec_version.to_string()
<< ", lens_type: " << device_info_->lens_type.to_string()
<< ", imu_type: " << device_info_->imu_type.to_string()
<< ", nominal_baseline: " << device_info_->nominal_baseline << "}";
device_info_->name = uvc::get_name(*device_);
img_intrinsics_ = img_params.in;
img_extrinsics_ = img_params.ex;
imu_intrinsics_ = imu_params.in;
imu_extrinsics_ = imu_params.ex;
}
void Device::WriteImgParams(
const ImgIntrinsics &intrinsics, const ImgExtrinsics &extrinsics) {
CHECK_NOTNULL(channels_);
Channels::img_params_t img_params{intrinsics, extrinsics};
if (channels_->SetFiles(nullptr, &img_params, nullptr)) {
img_intrinsics_ = intrinsics;
img_extrinsics_ = extrinsics;
if (img_params.ok) {
SetIntrinsics(Stream::LEFT, img_params.in_left);
SetIntrinsics(Stream::RIGHT, img_params.in_right);
SetExtrinsics(Stream::LEFT, Stream::RIGHT, img_params.ex_left_to_right);
VLOG(2) << "Intrinsics left: {" << GetIntrinsics(Stream::LEFT) << "}";
VLOG(2) << "Intrinsics right: {" << GetIntrinsics(Stream::RIGHT) << "}";
VLOG(2) << "Extrinsics left to right: {"
<< GetExtrinsics(Stream::LEFT, Stream::RIGHT) << "}";
} else {
LOG(WARNING) << "Intrinsics & extrinsics not exist";
}
if (imu_params.ok) {
SetMotionIntrinsics({imu_params.in_accel, imu_params.in_gyro});
SetMotionExtrinsics(Stream::LEFT, imu_params.ex_left_to_imu);
VLOG(2) << "Motion intrinsics: {" << GetMotionIntrinsics() << "}";
VLOG(2) << "Motion extrinsics left to imu: {"
<< GetMotionExtrinsics(Stream::LEFT) << "}";
} else {
LOG(WARNING) << "Motion intrinsics & extrinsics not exist";
}
}
void Device::WriteImuParams(
const ImuIntrinsics &intrinsics, const ImuExtrinsics &extrinsics) {
CHECK_NOTNULL(channels_);
Channels::imu_params_t imu_params{intrinsics, extrinsics};
if (channels_->SetFiles(nullptr, nullptr, &imu_params)) {
imu_intrinsics_ = intrinsics;
imu_extrinsics_ = extrinsics;
void Device::CallbackPushedStreamData(const Stream &stream) {
if (HasStreamCallback(stream)) {
auto &&datas = streams_->stream_datas(stream);
// if (datas.size() > 0) {}
auto &&data = datas.back();
if (stream_async_callbacks_.find(stream) != stream_async_callbacks_.end()) {
stream_async_callbacks_.at(stream)->PushData(data);
} else {
stream_callbacks_.at(stream)(data);
}
}
}
void Device::CallbackMotionData(const device::MotionData &data) {
if (HasMotionCallback()) {
if (motion_async_callback_) {
motion_async_callback_->PushData(data);
} else {
motion_callback_(data);
}
}
}

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_DEVICE_H_ // NOLINT
#define MYNTEYE_DEVICE_H_
#pragma once
@@ -9,11 +22,10 @@
#include <string>
#include <vector>
#include "mynteye/callbacks.h"
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
#include "internal/callbacks.h"
MYNTEYE_BEGIN_NAMESPACE
namespace uvc {
@@ -22,75 +34,204 @@ struct device;
} // namespace uvc
namespace tools {
class DeviceWriter;
} // namespace tools
struct DeviceInfo;
class API;
class Channels;
class Motions;
class Streams;
class Device {
template <class Data>
class AsyncCallback;
/**
* The Device class to communicate with MYNT® EYE device.
*/
class MYNTEYE_API Device {
public:
/** The device::StreamData callback. */
using stream_callback_t = device::StreamCallback;
/** The device::MotionData callback. */
using motion_callback_t = device::MotionCallback;
using stream_callbacks_t = std::map<Stream, stream_callback_t>;
using stream_async_callback_t = AsyncCallback<device::StreamData>;
using motion_async_callback_t = AsyncCallback<device::MotionData>;
using stream_async_callback_ptr_t = std::shared_ptr<stream_async_callback_t>;
using motion_async_callback_ptr_t = std::shared_ptr<motion_async_callback_t>;
Device(const Model &model, std::shared_ptr<uvc::device> device);
virtual ~Device();
/**
* Create the Device instance.
* @param name the device name.
* @param device the device from uvc.
* @return the Device instance.
*/
static std::shared_ptr<Device> Create(
const std::string &name, std::shared_ptr<uvc::device> device);
/**
* Get the model.
*/
Model GetModel() const {
return model_;
}
/**
* Supports the stream or not.
*/
bool Supports(const Stream &stream) const;
/**
* Supports the capability or not.
*/
bool Supports(const Capabilities &capability) const;
/**
* Supports the option or not.
*/
bool Supports(const Option &option) const;
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
/**
* Get all stream requests of the capability.
*/
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
/**
* Config the stream request to the capability.
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the device info.
*/
std::shared_ptr<DeviceInfo> GetInfo() const;
/**
* Get the device info of a field.
*/
std::string GetInfo(const Info &info) const;
ImgIntrinsics GetImgIntrinsics() const;
ImgExtrinsics GetImgExtrinsics() const;
void SetImgIntrinsics(const ImgIntrinsics &in);
void SetImgExtrinsics(const ImgExtrinsics &ex);
/**
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream) const;
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics() const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
ImuIntrinsics GetImuIntrinsics() const;
ImuExtrinsics GetImuExtrinsics() const;
void SetImuIntrinsics(const ImuIntrinsics &in);
void SetImuExtrinsics(const ImuExtrinsics &ex);
/**
* Set the intrinsics of stream.
*/
void SetIntrinsics(const Stream &stream, const Intrinsics &in);
/**
* Set the extrinsics from one stream to another.
*/
void SetExtrinsics(
const Stream &from, const Stream &to, const Extrinsics &ex);
/**
* Set the intrinsics of motion.
*/
void SetMotionIntrinsics(const MotionIntrinsics &in);
/**
* Set the extrinsics from one stream to motion.
*/
void SetMotionExtrinsics(const Stream &from, const Extrinsics &ex);
/**
* Log all option infos.
*/
void LogOptionInfos() const;
/**
* Get the option info.
*/
OptionInfo GetOptionInfo(const Option &option) const;
/**
* Get the option value.
*/
std::int32_t GetOptionValue(const Option &option) const;
/**
* Set the option value.
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Run the option action.
*/
bool RunOptionAction(const Option &option) const;
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
void SetMotionCallback(motion_callback_t callback);
/**
* Set the callback of stream.
*/
void SetStreamCallback(
const Stream &stream, stream_callback_t callback, bool async = false);
/**
* Set the callback of motion.
*/
void SetMotionCallback(motion_callback_t callback, bool async = false);
/**
* Has the callback of stream.
*/
bool HasStreamCallback(const Stream &stream) const;
/**
* Has the callback of motion.
*/
bool HasMotionCallback() const;
/**
* Start capturing the source.
*/
virtual void Start(const Source &source);
/**
* Stop capturing the source.
*/
virtual void Stop(const Source &source);
/**
* Wait the streams are ready.
*/
void WaitForStreams();
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
std::vector<device::StreamData> GetStreamDatas(const Stream &stream);
/**
* Get the latest data of stream.
*/
device::StreamData GetLatestStreamData(const Stream &stream);
/**
* Enable cache motion datas.
*/
void EnableMotionDatas(
std::size_t max_size = std::numeric_limits<std::size_t>::max());
/**
* Get the motion datas.
*/
std::vector<device::MotionData> GetMotionDatas();
protected:
@@ -98,8 +239,16 @@ class Device {
return device_;
}
std::shared_ptr<DeviceInfo> device_info() const {
return device_info_;
std::shared_ptr<Streams> streams() const {
return streams_;
}
std::shared_ptr<Channels> channels() const {
return channels_;
}
std::shared_ptr<Motions> motions() const {
return motions_;
}
const StreamRequest &GetStreamRequest(const Capabilities &capability);
@@ -110,6 +259,8 @@ class Device {
virtual void StartMotionTracking();
virtual void StopMotionTracking();
virtual void OnStereoStreamUpdate();
virtual std::vector<Stream> GetKeyStreams() const = 0;
bool video_streaming_;
@@ -120,14 +271,18 @@ class Device {
std::shared_ptr<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_;
ImgIntrinsics img_intrinsics_;
ImgExtrinsics img_extrinsics_;
ImuIntrinsics imu_intrinsics_;
ImuExtrinsics imu_extrinsics_;
std::map<Stream, Intrinsics> stream_intrinsics_;
std::map<Stream, std::map<Stream, Extrinsics>> stream_from_extrinsics_;
std::shared_ptr<MotionIntrinsics> motion_intrinsics_;
std::map<Stream, Extrinsics> motion_from_extrinsics_;
stream_callbacks_t stream_callbacks_;
motion_callback_t motion_callback_;
std::map<Stream, stream_async_callback_ptr_t> stream_async_callbacks_;
motion_async_callback_ptr_t motion_async_callback_;
std::shared_ptr<Streams> streams_;
std::map<Capabilities, StreamRequest> stream_config_requests_;
@@ -140,12 +295,11 @@ class Device {
void ReadAllInfos();
void WriteImgParams(
const ImgIntrinsics &intrinsics, const ImgExtrinsics &extrinsics);
void WriteImuParams(
const ImuIntrinsics &intrinsics, const ImuExtrinsics &extrinsics);
void CallbackPushedStreamData(const Stream &stream);
void CallbackMotionData(const device::MotionData &data);
// friend DeviceWriter;
friend API;
friend tools::DeviceWriter;
};
MYNTEYE_END_NAMESPACE

View File

@@ -1,7 +1,22 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#include "device/device_s.h"
#include <glog/logging.h>
#include "internal/motions.h"
MYNTEYE_BEGIN_NAMESPACE
StandardDevice::StandardDevice(std::shared_ptr<uvc::device> device)
@@ -17,4 +32,11 @@ std::vector<Stream> StandardDevice::GetKeyStreams() const {
return {Stream::LEFT, Stream::RIGHT};
}
void StandardDevice::OnStereoStreamUpdate() {
if (motion_tracking_) {
auto &&motions = this->motions();
motions->DoMotionTrack();
}
}
MYNTEYE_END_NAMESPACE

View File

@@ -1,3 +1,16 @@
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// 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.
#ifndef MYNTEYE_DEVICE_S_H_ // NOLINT
#define MYNTEYE_DEVICE_S_H_
#pragma once
@@ -15,6 +28,8 @@ class StandardDevice : public Device {
virtual ~StandardDevice();
std::vector<Stream> GetKeyStreams() const override;
void OnStereoStreamUpdate() override;
};
MYNTEYE_END_NAMESPACE

Some files were not shown because too many files have changed in this diff Show More