forked from openai/retro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import code for optical flow in the browser
- Loading branch information
1 parent
75d79f5
commit 4bd5f62
Showing
5 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
################################################################################ | ||
# | ||
# Copyright (C) 2020-2023 retro.ai | ||
# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See the file LICENSE.md for more information. | ||
# | ||
################################################################################ | ||
|
||
################################################################################ | ||
# | ||
# Build system for C++ libraries | ||
# | ||
# Required CMake variables: | ||
# | ||
# CMAKE_FIND_ROOT_PATH - Point this to dependencies compiled with Emscripten | ||
# CMAKE_INSTALL_PREFIX - Point this to the "public" folder | ||
# | ||
################################################################################ | ||
|
||
################################################################################ | ||
# | ||
# Project settings | ||
# | ||
################################################################################ | ||
|
||
project(retroai) | ||
|
||
cmake_minimum_required(VERSION 3.0.0) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
################################################################################ | ||
# | ||
# Dependencies | ||
# | ||
################################################################################ | ||
|
||
find_package(Ceres REQUIRED) | ||
find_package(Eigen3 REQUIRED) | ||
find_package(Glog REQUIRED) | ||
find_package(OpenCV REQUIRED) | ||
|
||
add_definitions(-DCERES_FOUND=1) | ||
|
||
################################################################################ | ||
# | ||
# Define sources | ||
# | ||
################################################################################ | ||
|
||
# | ||
# Motion tracker | ||
# | ||
|
||
set(MOTION_TRACKER_SOURCES | ||
api/imgproc.cpp | ||
api/reconstruction.cpp | ||
api/scene.cpp | ||
api/video.cpp | ||
kernels/cpu/cpu_imgproc.cpp | ||
kernels/cpu/cpu_reconstruction.cpp | ||
kernels/cpu/cpu_scene.cpp | ||
kernels/cpu/cpu_video.cpp | ||
motion_tracker/motion_tracker.cpp | ||
motion_tracker/motion_tracker_embinder.cpp | ||
motion_tracker/vision_graph.cpp | ||
utils/emscripten_utils.cpp | ||
utils/frame_pool.cpp | ||
utils/image_utils.cpp | ||
utils/math_utils.cpp | ||
) | ||
|
||
################################################################################ | ||
# | ||
# Build libraries | ||
# | ||
# TODO: | ||
# | ||
# * Build properly instead of shelling out | ||
# * Could refactor this into macros | ||
# | ||
################################################################################ | ||
|
||
include_directories( | ||
${CMAKE_SOURCE_DIR} | ||
) | ||
|
||
string(APPEND EMSCRIPTEN_LINK_FLAGS | ||
"--bind " | ||
# "-o dist/engine.js " | ||
# " -std=c++11 " | ||
# " -O2 " | ||
# " --preload-file textures " | ||
# " --preload-file shaders " | ||
# " --preload-file fonts " | ||
# " --pre-js pre-module.j " | ||
# " --post-js post-module.j " | ||
"-s ALLOW_MEMORY_GROWTH=1 " | ||
"-s ASSERTIONS=1 " | ||
# " -s DEMANGLE_SUPPORT=1 " | ||
# " -s DISABLE_EXCEPTION_CATCHING=0 " | ||
"-s ERROR_ON_UNDEFINED_SYMBOLS=0 " | ||
# " -s FULL_ES3=1 " | ||
# " -s GL_ASSERTIONS=1 " | ||
# " -s GL_UNSAFE_OPTS=0 " | ||
# " -s INVOKE_RUN=0 " | ||
# " -s LEGACY_GL_EMULATION=0 " | ||
#"-s LLD_REPORT_UNDEFINED " | ||
# " -s OFFSCREENCANVAS_SUPPORT=1 " | ||
# " -s SAFE_HEAP=1 " | ||
#"-s TOTAL_MEMORY=67108864 " | ||
# " -s USE_FREETYPE=1 " | ||
# " -s USE_GLFW=3 " | ||
# " -s USE_WEBGL2=1 " | ||
"-s USE_ZLIB=1 " | ||
# " -s WASM=1 " | ||
) | ||
|
||
# | ||
# Motion tracker | ||
# | ||
|
||
add_executable(motion_tracker | ||
${MOTION_TRACKER_SOURCES} | ||
) | ||
|
||
target_include_directories(motion_tracker PRIVATE | ||
${OpenCV_INCLUDE_DIRS} | ||
) | ||
|
||
target_link_libraries(motion_tracker PRIVATE | ||
${OpenCV_LIBS} | ||
) | ||
|
||
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") | ||
set_target_properties(motion_tracker PROPERTIES | ||
COMPILE_FLAGS " \ | ||
-O0 \ | ||
-g4 \ | ||
-s DISABLE_EXCEPTION_CATCHING=0 \ | ||
-s INITIAL_MEMORY=26214400 \ | ||
" | ||
# 26214400 is 25 MiB | ||
LINK_FLAGS " \ | ||
--bind \ | ||
--source-map-base https://retro.ai/ \ | ||
-O0 \ | ||
-g4 \ | ||
-s DISABLE_EXCEPTION_CATCHING=0 \ | ||
-s INITIAL_MEMORY=26214400 \ | ||
" | ||
) | ||
endif () | ||
|
||
################################################################################ | ||
# | ||
# Install libraries | ||
# | ||
################################################################################ | ||
|
||
# | ||
# Motion tracker | ||
# | ||
|
||
INSTALL( | ||
FILES | ||
"${CMAKE_BINARY_DIR}/motion_tracker.js" | ||
"${CMAKE_BINARY_DIR}/motion_tracker.wasm" | ||
"${CMAKE_BINARY_DIR}/motion_tracker.wasm.map" | ||
DESTINATION | ||
motion_tracker | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
################################################################################ | ||
# | ||
# Copyright (C) 2000-2023 retro.ai | ||
# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See the file LICENSE.md for more information. | ||
# | ||
################################################################################ | ||
|
||
################################################################################ | ||
# | ||
# Helper for CI infrastructure. Sets the appropriate paths and calls CMake. | ||
# | ||
################################################################################ | ||
|
||
# Enable strict shell mode | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
# | ||
# Environment paths | ||
# | ||
|
||
# Get the absolute path to this script | ||
SOURCE_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# Directory of the depends build system | ||
TOOL_DIRECTORY="${SOURCE_DIRECTORY}/../tools" | ||
|
||
# Directory for intermediate build files | ||
BUILD_DIRECTORY="${TOOL_DIRECTORY}/build/cpp-libs" | ||
|
||
# Directory of the Emscripten SDK | ||
EMSDK_DIRECTORY="${TOOL_DIRECTORY}/repos/emsdk" | ||
|
||
# Directory of the installed dependency files | ||
DEPENDS_DIRECTORY="${TOOL_DIRECTORY}/dist" | ||
|
||
# Directory to place the generated libraries | ||
INSTALL_DIRECTORY="${SOURCE_DIRECTORY}/../frontend/public" | ||
|
||
# Ensure directories exist | ||
mkdir -p "${BUILD_DIRECTORY}" | ||
mkdir -p "${INSTALL_DIRECTORY}" | ||
|
||
# | ||
# Setup environment | ||
# | ||
|
||
source "${EMSDK_DIRECTORY}/emsdk_set_env.sh" | ||
|
||
# | ||
# Call CMake | ||
# | ||
|
||
cd "${BUILD_DIRECTORY}" | ||
|
||
emcmake cmake \ | ||
"${SOURCE_DIRECTORY}" \ | ||
-DCMAKE_FIND_ROOT_PATH="${DEPENDS_DIRECTORY}" \ | ||
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIRECTORY}" \ | ||
$(! command -v ccache &> /dev/null || echo "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache") \ | ||
|
||
cmake --build "${BUILD_DIRECTORY}" -j$(shell getconf _NPROCESSORS_ONLN) --target install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters