Skip to content

Commit

Permalink
Add OpenCV from aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
tunmx committed May 7, 2024
1 parent 1ae5290 commit ab354a8
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/built_release_from_docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Build and Release SDKs
on:
push:
tags:
- "v*"
- "x*"

# Set the global GitHub token environment variable
env:
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/linux-ubuntu-x86.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build Linux-Ubuntu-x86

# Trigger the workflow when pushing tags that match the pattern "v*"
#on:
# push:
# tags:
# - "v*"

#on:
# push:
# branches: ["master"]
# pull_request:
# branches: ["master"]

on:
push:
branches: ["feature/aarch64"]

# Set the global GitHub token environment variable
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

jobs:
build:
name: Compile and Package SDKs
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v4

# Step 2: Synchronize and update submodules recursively
- name: Update submodules
run: |
git submodule sync --recursive # Ensure submodule paths are up-to-date
git submodule update --init --recursive # Initialize and update all submodules
# Step 3: Extract the version number from the tag (e.g., "v1.2.3" becomes "1.2.3")
- name: Extract Version Number
id: extract_version
run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/} | sed 's/^v//')" >> $GITHUB_ENV

# Step 4: Install necessary dependencies for building the CMake project
- name: Install Dependencies
run: |
sudo apt-get update # Update package lists
# Install build tools and required libraries for video processing
sudo apt-get install -y build-essential libgtk-3-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev
# Step 5: Start building the SDK
- name: Start Building the InspireFace-Linux-x86
run: |
bash command/build_linux_ubuntu18.sh
ls build
2 changes: 1 addition & 1 deletion 3rdparty/inspireface-precompile
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ else()
set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/share/OpenCV)
set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/include/)
elseif(ISF_BUILD_LINUX_AARCH64)
# TODO
set(PLAT linux-aarch64)
message("The OpenCV that builds the gnueabihf version depends on is specialized!")
set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/opencv/3.4.5/opencv-linux-aarch64/share/OpenCV)
set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/inspireface-precompile/opencv/3.4.5/opencv-linux-aarch64/include/)
endif()
endif()
else ()
Expand Down
58 changes: 58 additions & 0 deletions command/build_cross_aarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Reusable function to handle 'install' directory operations
move_install_files() {
local root_dir="$1"
local install_dir="$root_dir/install"

# Step 1: Check if the 'install' directory exists
if [ ! -d "$install_dir" ]; then
echo "Error: 'install' directory does not exist in $root_dir"
exit 1
fi

# Step 2: Delete all other files/folders except 'install'
find "$root_dir" -mindepth 1 -maxdepth 1 -not -name "install" -exec rm -rf {} +

# Step 3: Move all files from 'install' to the root directory
mv "$install_dir"/* "$root_dir" 2>/dev/null

# Step 4: Remove the empty 'install' directory
rmdir "$install_dir"

echo "Files from 'install' moved to $root_dir, and 'install' directory deleted."
}

if [ -n "$VERSION" ]; then
TAG="-$VERSION"
else
TAG=""
fi

SCRIPT_DIR=$(pwd) # Project dir
BUILD_FOLDER_PATH="build/inspireface-linux-aarch64${TAG}"

mkdir -p ${BUILD_FOLDER_PATH}
# shellcheck disable=SC2164
cd ${BUILD_FOLDER_PATH}
# export cross_compile_toolchain=/home/jingyuyan/software/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu
cmake -DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_VERSION=1 \
-DCMAKE_SYSTEM_PROCESSOR=armv7 \
-DCMAKE_C_COMPILER=$ARM_CROSS_COMPILE_TOOLCHAIN/bin/arm-linux-gnueabihf-gcc \
-DCMAKE_CXX_COMPILER=$ARM_CROSS_COMPILE_TOOLCHAIN/bin/arm-linux-gnueabihf-g++ \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -flax-vector-conversions" \
-DTARGET_PLATFORM=armlinux \
-DISF_BUILD_LINUX_ARM7=ON \
-DISF_BUILD_WITH_SAMPLE=OFF \
-DISF_BUILD_WITH_TEST=OFF \
-DISF_ENABLE_BENCHMARK=OFF \
-DISF_ENABLE_USE_LFW_DATA=OFF \
-DISF_ENABLE_TEST_EVALUATION=OFF \
-DISF_BUILD_SHARED_LIBS=ON ${SCRIPT_DIR}

make -j4
make install

move_install_files "$(pwd)"
8 changes: 3 additions & 5 deletions cpp/inspireface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ string(CONCAT INSPIRE_FACE_VERSION_PATCH_STR ${INSPIRE_FACE_VERSION_PATCH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/information.h.in ${CMAKE_CURRENT_SOURCE_DIR}/information.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/version.txt)



option(ISF_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." ON)

file(GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
Expand All @@ -34,8 +32,8 @@ endif()
# OpenCV
set(LINK_THIRD_LIBS ${OpenCV_LIBS} ${MNN_LIBS})

# sqlite3
set(SOURCE_FILES ${SOURCE_FILES} ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/sqlite/sqlite3.c) # Add C_API file
# SQLite3
set(SOURCE_FILES ${SOURCE_FILES} ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/sqlite/sqlite3.c) # Add SQLite3 C_API file
set(SQLITE_INCLUDE ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/sqlite/)

if (ISF_ENABLE_RKNN)
Expand Down Expand Up @@ -70,7 +68,7 @@ set(NEED_INCLUDE . ${MNN_INCLUDE_DIRS})
if (ISF_ENABLE_RKNN)
set(NEED_INCLUDE ${NEED_INCLUDE} ${ISF_RKNN_API_INCLUDE_DIRS})
endif ()
if (ISF_BUILD_LINUX_ARM7)
if (ISF_BUILD_LINUX_ARM7 OR ISF_BUILD_LINUX_AARCH64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
set(NEED_INCLUDE ${NEED_INCLUDE} ${OpenCV_STATIC_INCLUDE_DIR})
endif ()
Expand Down
36 changes: 36 additions & 0 deletions docker/Dockerfile.arm-linux-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use Ubuntu 18.04 as the base image
FROM ubuntu:18.04

# Update the package list and install basic development tools
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
software-properties-common \
wget \
curl \
git

# Install CMake
RUN apt-get install -y --no-install-recommends cmake

# Set the URL and installation path for the Linaro toolchain
ARG LINARO_URL="https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/aarch64-linux-gnu/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.xz"
ARG TOOLCHAIN_PATH="/opt/linaro-toolchain"

# Create the installation path, download, and extract the Linaro toolchain
RUN mkdir -p ${TOOLCHAIN_PATH} && \
wget -qO- ${LINARO_URL} | tar -xJ -C ${TOOLCHAIN_PATH} --strip-components=1

# Set environment variables to point to the toolchain directory
ENV ARM_CROSS_COMPILE_TOOLCHAIN=${TOOLCHAIN_PATH}
ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}"

# Clean temporary files to reduce image size
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /workspace

# Default to running Bash
CMD ["/bin/bash"]

0 comments on commit ab354a8

Please sign in to comment.