Skip to content

Commit

Permalink
Initial import of the host source code
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-luxonis committed Mar 6, 2020
1 parent 0d1d29c commit 9fb1571
Show file tree
Hide file tree
Showing 71 changed files with 5,277 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Microsoft Visual Studio Code
.project
.vscode/

# Auto-generated
shared/version.hpp
16 changes: 16 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[submodule "host/py_module/3rdparty/pybind11"]
path = host/py_module/3rdparty/pybind11
url = https://github.com/pybind/pybind11.git
branch = stable
[submodule "host/core/3rdparty/loguru"]
path = host/core/3rdparty/loguru
url = https://github.com/emilk/loguru.git
[submodule "shared/3rdparty/dldt"]
path = shared/3rdparty/dldt
url = https://github.com/opencv/dldt.git
[submodule "shared/3rdparty/json"]
path = shared/3rdparty/json
url = https://github.com/nlohmann/json.git
[submodule "shared/3rdparty/json-schema-validator"]
path = shared/3rdparty/json-schema-validator
url = https://github.com/pboettch/json-schema-validator.git
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# depthai-api

Host-side DepthAI source code

## Content description

- **host** - contains the code which runs on the host computer (Raspberry Pi or a PC that has a DepthAI device connected). This part has:

- **py_module** - python module (made only with C++ code with `pybind11`). Builds an `.so` libray that can be imported with python.
- **app** - C++ app for easier debugging and development.
- **core** - main functionality of the host, which is used in `py_module` and `app`.

- **shared** - code that is shared between host and DepthAI device. This code gets also into the firmware binary `depthai.cmd`

## Tested platforms

- Ubuntu 16.04;
- Ubuntu 18.04;
- Raspbian 10;

## Setup

- Install development environement dependencies:

sudo apt-get install -y git python-pip cmake cmake-gui libusb-1.0-0-dev

- After cloning the repo, update the third-party libraries used:

./install_dependencies.sh


## Build and run

- **host/py_module**

cd host/py_module
mkdir -p build
cd build
cmake ..
make -j
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`:
- `./build_py_module.sh`
first it does a full build, then at subsequent runs compiles only the modified source files.
- `./build_py_module.sh --clean`
cleans up the build folder and does a full rebuild.


- **host/app**
(Note: this is currently outdated and doesn't run properly)
`DEPTHAI_EXTRAS_PATH` in `main.cpp` may have to be adjusted first.

cd host/app
mkdir -p build
cd build
cmake ..
make -j
./depthai_app


31 changes: 31 additions & 0 deletions build_py_module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

INITIAL_DIR=`pwd`
SOURCE_DIR=$(dirname "$0")
BUILD_DIR=build
NUM_CORES=`nproc`

print_exec() {
REL_PATH="realpath --relative-to=$INITIAL_DIR `pwd`"
echo "[BUILD `$REL_PATH`] $@"
"$@"
}

cd "$SOURCE_DIR/host/py_module"

if [[ $1 = "--clean" ]]; then
print_exec rm -r $BUILD_DIR
fi

mkdir -p $BUILD_DIR
cd $BUILD_DIR

if [ ! -f Makefile ]; then
print_exec cmake ..
fi

print_exec make -j$NUM_CORES

DEPTHAI_LIB=(*.so)
print_exec cp ${DEPTHAI_LIB[0]} ../../../../

1 change: 1 addition & 0 deletions host/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
120 changes: 120 additions & 0 deletions host/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
set(APP_NAME depthai_app)

set(dldt_dir ../../shared/3rdparty/dldt)

cmake_minimum_required(VERSION 2.8.12)

project(${APP_NAME})


add_definitions(-D__PC__)
add_definitions(-DUSE_USB_VSC) # for XLink communication
# add_definitions(-DXLINK_USB_DATA_TIMEOUT=0)
# add_definitions(-DXLINK_COMMON_TIMEOUT_MSEC=0)

if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")
message(STATUS "optional:-std=c++17")
endif(CMAKE_COMPILER_IS_GNUCXX)


# find_package(OpenCV REQUIRED )
# find_package(PythonLibs 3 REQUIRED)

include(${dldt_dir}/inference-engine/thirdparty/movidius/XLink/XLink.cmake)

include_directories(
./
../core/
../../shared/
${XLINK_INCLUDE_DIRECTORIES}
)



# if(DEFINED BUILD_FOR_PYTHON)
# message("building for python")
# add_subdirectory(pybind11)
# pybind11_add_module(
# ${APP_NAME}
# wrapper.cpp
# program_raw_options.cpp
# ../core/pipeline/host_pipeline.cpp
# ../../shared/xlink/xlink_wrapper.cpp
# ${XLINK_SOURCES}
# )
# else(DEFINED BUILD_FOR_PYTHON)
message("building for direct")
add_executable( ${APP_NAME}
main.cpp
program_raw_options.cpp
../../shared/logger/logs_writer.cpp
../../host/core/3rdparty/loguru/loguru.cpp
../../shared/general/data_writer.cpp
../../shared/json_helper.cpp
host_logs_writer.cpp
../core/pipeline/host_pipeline.cpp
../core/pipeline/host_pipeline_config.cpp
../core/pipeline/cnn_host_pipeline.cpp
../../shared/stream/stream_info.cpp
../../shared/xlink/xlink_wrapper.cpp
../core/types.cpp
../core/host_json_helper.cpp
../core/host_data_reader.cpp
../core/host_data_reader.cpp
../core/disparity_stream_post_processor.cpp
../../shared/disparity_luts.cpp
${XLINK_SOURCES}
)
# endif(DEFINED BUILD_FOR_PYTHON)



# nlohman JSON
set(nlohmann_json_DIR ../../shared/3rdparty/json)

include_directories(${nlohmann_json_DIR}/include/)
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${nlohmann_json_DIR} ${CMAKE_CURRENT_BINARY_DIR}/json)


# nlohman JSON validator
set(BUILD_TESTS OFF CACHE INTERNAL "")
set(BUILD_EXAMPLES OFF CACHE INTERNAL "")

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../shared/3rdparty/json-schema-validator/ ${CMAKE_CURRENT_BINARY_DIR}/json-schema-validator)



# for commit hash
# TODO: maybe we shoud add it into another .cmake and than include here?
find_package(Git)

set(commit_version "unknown")

if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${local_dir}"
OUTPUT_VARIABLE commit_version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
message(STATUS "GIT module not found")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../shared/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/../../shared/version.hpp @ONLY)



# link libraries
target_link_libraries(
${APP_NAME}
PRIVATE
-lusb-1.0
-lpthread
-ldl
nlohmann_json::nlohmann_json
nlohmann_json_schema_validator
)
54 changes: 54 additions & 0 deletions host/app/host_logs_writer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <assert.h>

#include <iostream>
#include <array>


#include "../../host/core/3rdparty/loguru/loguru.hpp"
#include <host_logs_writer.hpp>

HostLogsWriter* HostLogsWriter::createInstanse()
{
if(instance) { std::cout << "HostLogsWriter instannce has already been created" << std::endl; }
else { instance = new HostLogsWriter; };
}

bool HostLogsWriter::init
(
LogType log_type,
bool logs_to_file,
bool logs_to_screen,
const std::string& file_path
)
{
loguru::g_preamble_uptime = false;
loguru::g_preamble_thread = false;
loguru::g_preamble_file = false;


std::array<loguru::Verbosity, 4> loguru_log_level =
{
loguru::Verbosity_FATAL,
loguru::Verbosity_ERROR,
loguru::Verbosity_WARNING,
loguru::Verbosity_INFO
};

assert(log_type < loguru_log_level.size());
loguru::g_stderr_verbosity = loguru_log_level[log_type];

if (logs_to_file) { loguru::add_file(file_path.c_str(), loguru::Append, loguru_log_level[log_type]); };

}

void HostLogsWriter::log
(
LogType log_type,
const std::string& msg
)
{
if (log_type == 0) { LOG_F(FATAL, msg.c_str()); }
else if (log_type == 1) { LOG_F(ERROR, msg.c_str()); }
else if (log_type == 2) { LOG_F(WARNING, msg.c_str()); }
else if (log_type == 3) { LOG_F(INFO, msg.c_str()); }
}
15 changes: 15 additions & 0 deletions host/app/host_logs_writer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>

#include <../../shared/logger/logs_writer.hpp>

class HostLogsWriter
: public LogsWriter
{
protected:
HostLogsWriter () {}
virtual ~HostLogsWriter() {}
public:
bool init (LogType log_type, bool logs_to_file, bool logs_to_screen, const std::string& file_path) override;
void log (LogType log_type, const std::string& msg) override;
static HostLogsWriter* createInstanse();
};
Loading

0 comments on commit 9fb1571

Please sign in to comment.