initial commit

This commit is contained in:
Joachim
2020-03-23 11:48:41 +01:00
commit fce6dc35b4
6434 changed files with 2823345 additions and 0 deletions

View File

@ -0,0 +1,97 @@
#!/bin/bash
# This script builds the opencv static libraries for the ESP32 and then copies the library and headers files to the asked folder. It must be runned from the opencv repository root.
# USAGE: ./build_opencv_for_esp32.sh <path-to-toolchain> <path-to-project>
set -e
# dir where the script is, no matter from where it is being called from
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# path to the cmake file containing the toolchain informations
TOOLCHAIN_CMAKE_PATH=$HOME/esp/esp-idf/tools/cmake/toolchain-esp32.cmake
# path where to copy the build libs and headers
LIB_INSTALL_PATH=$SCRIPTDIR/../lib
# list of modules to compile
OPENCV_MODULES_LIST=core,imgproc,imgcodecs
echo "################################################################################"
echo "######################## build_opencv_for_esp32 script #########################"
echo "################################################################################"
## get script arguments ###
if [ -z "$1" ]
then
echo "Using default toolchain cmake file path: ${TOOLCHAIN_CMAKE_PATH}"
else
TOOLCHAIN_PATH=$1
echo "Using toolchain cmake file path: ${TOOLCHAIN_CMAKE_PATH}"
fi
if [ -z "$2" ]
then
echo "Will be installed in default library install path: ${LIB_INSTALL_PATH}/opencv"
else
LIB_INSTALL_PATH=$2
echo "Will be installed in user-defined library install path: ${LIB_INSTALL_PATH}/opencv"
fi
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DESP32=ON -DBUILD_SHARED_LIBS=OFF -DCV_DISABLE_OPTIMIZATION=ON -DWITH_IPP=OFF -DWITH_TBB=OFF -DWITH_OPENMP=OFF -DWITH_PTHREADS_PF=OFF -DWITH_QUIRC=OFF -DWITH_1394=OFF -DWITH_CUDA=OFF -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_JASPER=OFF -DWITH_JPEG=OFF -DWITH_WEBP=OFF -DBUILD_ZLIB=ON -DBUILD_PNG=ON -DWITH_TIFF=OFF -DWITH_V4L=OFF -DWITH_ITT=OFF -DWITH_PROTOBUF=OFF -DWITH_IMGCODEC_HDR=OFF -DWITH_IMGCODEC_SUNRASTER=OFF -DWITH_IMGCODEC_PXM=OFF -DWITH_IMGCODEC_PFM=OFF -DBUILD_LIST=${OPENCV_MODULES_LIST} -DBUILD_JAVA=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_apps=OFF -DBUILD_PACKAGE=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DCV_ENABLE_INTRINSICS=OFF -DCV_TRACE=OFF -DOPENCV_ENABLE_MEMALIGN=OFF -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_CMAKE_PATH}"
### configure and build opencv ###
cd $SCRIPTDIR/../../
rm -rf build/ && mkdir -p build/ && cd build
# configure with cmake
echo "================================================================================"
echo "Configuring with cmake ${CMAKE_ARGS} :"
echo "================================================================================"
cmake $CMAKE_ARGS ..
read -p "Don't forget to check the cmake summary! Continue ? [y/N]" prompt
if [ "${prompt}" != "y" ]; then
echo "aborted."
exit 1
fi
# fix of the generated file alloc.c
cp $SCRIPTDIR/resources/alloc_fix.cpp ./3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp
# compiling with all power!
echo "================================================================================"
echo "Compiling with make -j"
echo "================================================================================"
make -j
### installing in output directory ###
echo "================================================================================"
echo "Installing in ${LIB_INSTALL_PATH}"
echo "================================================================================"
# copying opencv modules libs
mkdir -p $LIB_INSTALL_PATH/opencv
cp lib/* $LIB_INSTALL_PATH/opencv
# copying 3rdparty libs
mkdir -p $LIB_INSTALL_PATH/opencv/3rdparty
cp 3rdparty/lib/* $LIB_INSTALL_PATH/opencv/3rdparty
# copying headers
mkdir -p $LIB_INSTALL_PATH/opencv/opencv2
cp opencv2/* $LIB_INSTALL_PATH/opencv/opencv2
cp ../include/opencv2/opencv.hpp $LIB_INSTALL_PATH/opencv/opencv2/
IFS=',' read -r -a modules <<< "$OPENCV_MODULES_LIST"
for elt in "${modules[@]}"
do
echo "Module ${elt}"
cp -r "../modules/${elt}/include/opencv2" $LIB_INSTALL_PATH/opencv
done
echo "installation done."

View File

@ -0,0 +1,39 @@
#!/bin/bash
# This script downloads the esp32 toolchain and compile it.
# USAGE: ./install_esp32_toolchain.sh <path-to-install>
# Default installation is in $HOME/esp/
# Installation instructions from https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html
set -e
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # dir from where this script is run
CROSSTOOLNGVERSION=2019r2
DEFAULTINSTALLDIR=$HOME/esp/
### install some dependencies ###
sudo apt-get install -y git wget libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools ninja-build ccache libffi-dev libssl-dev
sudo apt-get install -y gawk gperf grep gettext python python-dev automake bison flex texinfo help2man libtool libtool-bin make git
## get and install esp-idf tools ###
if [ -z "$1" ]
then
INSTALLDIR = $DEFAULTINSTALLDIR
else
INSTALLDIR = $1
fi
mkdir -p $INSTALLDIR && cd $INSTALLDIR
git clone --recursive https://github.com/espressif/esp-idf.git
cd esp-idf/
export IDF_TOOLS_PATH=$HOME/esp/
./install.sh
export IDF_PATH=$INSTALLDIR/esp-idf
. $INSTALLDIR/esp-idf/export.sh
# after that, the path modifications can be added to the terminal configuration file so that the tools are available after reboot

View File

@ -0,0 +1,46 @@
// Copyright (C) 2018 Intel Corporation
//
//
// SPDX-License-Identifier: Apache-2.0
//
#include "ade/memory/alloc.hpp"
#if defined(_WIN32) || defined(__ANDROID__) || defined(ANDROID) || defined(ESP32)
#include <malloc.h>
#else
#include <algorithm>
#include <stdlib.h>
#endif
#include "ade/util/math.hpp"
#include "ade/util/assert.hpp"
namespace ade
{
void* aligned_alloc(std::size_t size, std::size_t alignment)
{
ADE_ASSERT(util::is_pow2(alignment));
#if defined(_WIN32)
return _aligned_malloc(size, alignment);
#elif defined(__ANDROID__) || defined(ANDROID) || defined(ESP32)
return memalign(alignment, size);
#else
void* ret = nullptr;
auto res = posix_memalign(&ret, std::max(sizeof(void*), alignment), size);
(void)res;
return ret;
#endif
}
void aligned_free(void* ptr)
{
#if defined(_WIN32)
return _aligned_free(ptr);
#else
return free(ptr);
#endif
}
}

View File

@ -0,0 +1,13 @@
set(CMAKE_SYSTEM_NAME Generic)
set( ESP32 True )
set(CMAKE_C_COMPILER xtensa-esp32-elf-gcc)
set(CMAKE_CXX_COMPILER xtensa-esp32-elf-g++)
set(CMAKE_ASM_COMPILER xtensa-esp32-elf-gcc)
set(CMAKE_C_FLAGS "-mlongcalls -Wno-frame-address" CACHE STRING "C Compiler Base Flags")
set(CMAKE_CXX_FLAGS "-mlongcalls -Wno-frame-address" CACHE STRING "C++ Compiler Base Flags")
# Can be removed after gcc 5.2.0 support is removed (ref GCC_NOT_5_2_0)
set(CMAKE_EXE_LINKER_FLAGS "-nostdlib" CACHE STRING "Linker Base Flags")