Skip to content

Commit 9fb1571

Browse files
committed
Initial import of the host source code
1 parent 0d1d29c commit 9fb1571

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5277
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Microsoft Visual Studio Code
2+
.project
3+
.vscode/
4+
5+
# Auto-generated
6+
shared/version.hpp

.gitmodules

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[submodule "host/py_module/3rdparty/pybind11"]
2+
path = host/py_module/3rdparty/pybind11
3+
url = https://github.com/pybind/pybind11.git
4+
branch = stable
5+
[submodule "host/core/3rdparty/loguru"]
6+
path = host/core/3rdparty/loguru
7+
url = https://github.com/emilk/loguru.git
8+
[submodule "shared/3rdparty/dldt"]
9+
path = shared/3rdparty/dldt
10+
url = https://github.com/opencv/dldt.git
11+
[submodule "shared/3rdparty/json"]
12+
path = shared/3rdparty/json
13+
url = https://github.com/nlohmann/json.git
14+
[submodule "shared/3rdparty/json-schema-validator"]
15+
path = shared/3rdparty/json-schema-validator
16+
url = https://github.com/pboettch/json-schema-validator.git

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# depthai-api
2+
3+
Host-side DepthAI source code
4+
5+
## Content description
6+
7+
- **host** - contains the code which runs on the host computer (Raspberry Pi or a PC that has a DepthAI device connected). This part has:
8+
9+
- **py_module** - python module (made only with C++ code with `pybind11`). Builds an `.so` libray that can be imported with python.
10+
- **app** - C++ app for easier debugging and development.
11+
- **core** - main functionality of the host, which is used in `py_module` and `app`.
12+
13+
- **shared** - code that is shared between host and DepthAI device. This code gets also into the firmware binary `depthai.cmd`
14+
15+
## Tested platforms
16+
17+
- Ubuntu 16.04;
18+
- Ubuntu 18.04;
19+
- Raspbian 10;
20+
21+
## Setup
22+
23+
- Install development environement dependencies:
24+
25+
sudo apt-get install -y git python-pip cmake cmake-gui libusb-1.0-0-dev
26+
27+
- After cloning the repo, update the third-party libraries used:
28+
29+
./install_dependencies.sh
30+
31+
32+
## Build and run
33+
34+
- **host/py_module**
35+
36+
cd host/py_module
37+
mkdir -p build
38+
cd build
39+
cmake ..
40+
make -j
41+
Alternatively, when this repo is used as a submodule in https://github.com/luxonis/depthai-python-extras, the build process can be automated with the script below, that is also copying the generated `.so` back to `depthai-python-extras`:
42+
- `./build_py_module.sh`
43+
first it does a full build, then at subsequent runs compiles only the modified source files.
44+
- `./build_py_module.sh --clean`
45+
cleans up the build folder and does a full rebuild.
46+
47+
48+
- **host/app**
49+
(Note: this is currently outdated and doesn't run properly)
50+
`DEPTHAI_EXTRAS_PATH` in `main.cpp` may have to be adjusted first.
51+
52+
cd host/app
53+
mkdir -p build
54+
cd build
55+
cmake ..
56+
make -j
57+
./depthai_app
58+
59+

build_py_module.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
INITIAL_DIR=`pwd`
4+
SOURCE_DIR=$(dirname "$0")
5+
BUILD_DIR=build
6+
NUM_CORES=`nproc`
7+
8+
print_exec() {
9+
REL_PATH="realpath --relative-to=$INITIAL_DIR `pwd`"
10+
echo "[BUILD `$REL_PATH`] $@"
11+
"$@"
12+
}
13+
14+
cd "$SOURCE_DIR/host/py_module"
15+
16+
if [[ $1 = "--clean" ]]; then
17+
print_exec rm -r $BUILD_DIR
18+
fi
19+
20+
mkdir -p $BUILD_DIR
21+
cd $BUILD_DIR
22+
23+
if [ ! -f Makefile ]; then
24+
print_exec cmake ..
25+
fi
26+
27+
print_exec make -j$NUM_CORES
28+
29+
DEPTHAI_LIB=(*.so)
30+
print_exec cp ${DEPTHAI_LIB[0]} ../../../../
31+

host/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

host/app/CMakeLists.txt

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
set(APP_NAME depthai_app)
2+
3+
set(dldt_dir ../../shared/3rdparty/dldt)
4+
5+
cmake_minimum_required(VERSION 2.8.12)
6+
7+
project(${APP_NAME})
8+
9+
10+
add_definitions(-D__PC__)
11+
add_definitions(-DUSE_USB_VSC) # for XLink communication
12+
# add_definitions(-DXLINK_USB_DATA_TIMEOUT=0)
13+
# add_definitions(-DXLINK_COMMON_TIMEOUT_MSEC=0)
14+
15+
if(CMAKE_COMPILER_IS_GNUCXX)
16+
set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")
17+
message(STATUS "optional:-std=c++17")
18+
endif(CMAKE_COMPILER_IS_GNUCXX)
19+
20+
21+
# find_package(OpenCV REQUIRED )
22+
# find_package(PythonLibs 3 REQUIRED)
23+
24+
include(${dldt_dir}/inference-engine/thirdparty/movidius/XLink/XLink.cmake)
25+
26+
include_directories(
27+
./
28+
../core/
29+
../../shared/
30+
${XLINK_INCLUDE_DIRECTORIES}
31+
)
32+
33+
34+
35+
# if(DEFINED BUILD_FOR_PYTHON)
36+
# message("building for python")
37+
# add_subdirectory(pybind11)
38+
# pybind11_add_module(
39+
# ${APP_NAME}
40+
# wrapper.cpp
41+
# program_raw_options.cpp
42+
# ../core/pipeline/host_pipeline.cpp
43+
# ../../shared/xlink/xlink_wrapper.cpp
44+
# ${XLINK_SOURCES}
45+
# )
46+
# else(DEFINED BUILD_FOR_PYTHON)
47+
message("building for direct")
48+
add_executable( ${APP_NAME}
49+
main.cpp
50+
program_raw_options.cpp
51+
../../shared/logger/logs_writer.cpp
52+
../../host/core/3rdparty/loguru/loguru.cpp
53+
../../shared/general/data_writer.cpp
54+
../../shared/json_helper.cpp
55+
host_logs_writer.cpp
56+
../core/pipeline/host_pipeline.cpp
57+
../core/pipeline/host_pipeline_config.cpp
58+
../core/pipeline/cnn_host_pipeline.cpp
59+
../../shared/stream/stream_info.cpp
60+
../../shared/xlink/xlink_wrapper.cpp
61+
../core/types.cpp
62+
../core/host_json_helper.cpp
63+
../core/host_data_reader.cpp
64+
../core/host_data_reader.cpp
65+
../core/disparity_stream_post_processor.cpp
66+
../../shared/disparity_luts.cpp
67+
${XLINK_SOURCES}
68+
)
69+
# endif(DEFINED BUILD_FOR_PYTHON)
70+
71+
72+
73+
# nlohman JSON
74+
set(nlohmann_json_DIR ../../shared/3rdparty/json)
75+
76+
include_directories(${nlohmann_json_DIR}/include/)
77+
set(JSON_BuildTests OFF CACHE INTERNAL "")
78+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${nlohmann_json_DIR} ${CMAKE_CURRENT_BINARY_DIR}/json)
79+
80+
81+
# nlohman JSON validator
82+
set(BUILD_TESTS OFF CACHE INTERNAL "")
83+
set(BUILD_EXAMPLES OFF CACHE INTERNAL "")
84+
85+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../shared/3rdparty/json-schema-validator/ ${CMAKE_CURRENT_BINARY_DIR}/json-schema-validator)
86+
87+
88+
89+
# for commit hash
90+
# TODO: maybe we shoud add it into another .cmake and than include here?
91+
find_package(Git)
92+
93+
set(commit_version "unknown")
94+
95+
if(GIT_FOUND)
96+
execute_process(
97+
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
98+
WORKING_DIRECTORY "${local_dir}"
99+
OUTPUT_VARIABLE commit_version
100+
ERROR_QUIET
101+
OUTPUT_STRIP_TRAILING_WHITESPACE
102+
)
103+
else()
104+
message(STATUS "GIT module not found")
105+
endif()
106+
107+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../shared/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/../../shared/version.hpp @ONLY)
108+
109+
110+
111+
# link libraries
112+
target_link_libraries(
113+
${APP_NAME}
114+
PRIVATE
115+
-lusb-1.0
116+
-lpthread
117+
-ldl
118+
nlohmann_json::nlohmann_json
119+
nlohmann_json_schema_validator
120+
)

host/app/host_logs_writer.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <assert.h>
2+
3+
#include <iostream>
4+
#include <array>
5+
6+
7+
#include "../../host/core/3rdparty/loguru/loguru.hpp"
8+
#include <host_logs_writer.hpp>
9+
10+
HostLogsWriter* HostLogsWriter::createInstanse()
11+
{
12+
if(instance) { std::cout << "HostLogsWriter instannce has already been created" << std::endl; }
13+
else { instance = new HostLogsWriter; };
14+
}
15+
16+
bool HostLogsWriter::init
17+
(
18+
LogType log_type,
19+
bool logs_to_file,
20+
bool logs_to_screen,
21+
const std::string& file_path
22+
)
23+
{
24+
loguru::g_preamble_uptime = false;
25+
loguru::g_preamble_thread = false;
26+
loguru::g_preamble_file = false;
27+
28+
29+
std::array<loguru::Verbosity, 4> loguru_log_level =
30+
{
31+
loguru::Verbosity_FATAL,
32+
loguru::Verbosity_ERROR,
33+
loguru::Verbosity_WARNING,
34+
loguru::Verbosity_INFO
35+
};
36+
37+
assert(log_type < loguru_log_level.size());
38+
loguru::g_stderr_verbosity = loguru_log_level[log_type];
39+
40+
if (logs_to_file) { loguru::add_file(file_path.c_str(), loguru::Append, loguru_log_level[log_type]); };
41+
42+
}
43+
44+
void HostLogsWriter::log
45+
(
46+
LogType log_type,
47+
const std::string& msg
48+
)
49+
{
50+
if (log_type == 0) { LOG_F(FATAL, msg.c_str()); }
51+
else if (log_type == 1) { LOG_F(ERROR, msg.c_str()); }
52+
else if (log_type == 2) { LOG_F(WARNING, msg.c_str()); }
53+
else if (log_type == 3) { LOG_F(INFO, msg.c_str()); }
54+
}

host/app/host_logs_writer.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
3+
#include <../../shared/logger/logs_writer.hpp>
4+
5+
class HostLogsWriter
6+
: public LogsWriter
7+
{
8+
protected:
9+
HostLogsWriter () {}
10+
virtual ~HostLogsWriter() {}
11+
public:
12+
bool init (LogType log_type, bool logs_to_file, bool logs_to_screen, const std::string& file_path) override;
13+
void log (LogType log_type, const std::string& msg) override;
14+
static HostLogsWriter* createInstanse();
15+
};

0 commit comments

Comments
 (0)