Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat: add referee ocr project to the wolfengine (#429)
Browse files Browse the repository at this point in the history
* ci: update files

issue #417

* ci: update files

issue #417

* ci: update files

issue #417

* feat; use wolf engine policy in new codes

issue #417

* ci: update files

issue #417

* ci: improve cmake for linux

issue #417

* ci: update ci workflow to add sw

issue #417

* ci: change tesseract cmake

issue #417

* ci: update files

issue #417

* ci: update analyze ignore targets

issue #417

---------

Co-authored-by: Bagher Salahshoor <[email protected]>
  • Loading branch information
MBSM110 and Bagher Salahshoor authored Feb 13, 2023
1 parent c80cd1b commit 8ba1653
Show file tree
Hide file tree
Showing 21 changed files with 6,621 additions and 11 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ name: Microsoft C++ Code Analysis

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]
schedule:
- cron: '41 16 * * 1'
- cron: "41 16 * * 1"

env:
# Path to the CMake build directory.
build: '${{ github.workspace }}/build'
build: "${{ github.workspace }}/build"

permissions:
contents: read
Expand All @@ -36,15 +36,23 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Get SW
uses: egorpugin/sw-action@master

- name: SW setup and add to PATH
run: |
./sw setup
echo "D:\a\WolfEngine\WolfEngine" >> $env:GITHUB_PATH
- name: Setup OpenCppCoverage and add to PATh
id: setup_opencppcoverage
run: |
choco install OpenCppCoverage -y
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- name: Configure CMake
run: cmake -B ${{ env.build }}

# Build is not required for MSVC Code Analysis and will be used for Codecov
- name: Build CMake
run: cmake --build ${{ env.build }}
Expand All @@ -57,8 +65,8 @@ jobs:
cmakeBuildDirectory: ${{ env.build }}
# Ruleset file that will determine what checks will be run
ruleset: NativeRecommendedRules.ruleset
ignoredPaths: build/_deps
ignoredTargetPaths: ${{ env.build }}/_deps/boost_chrono-src;${{ env.build }}/_deps/boost_context-src;${{ env.build }}/_deps/boost_coroutine-src;${{ env.build }}/_deps/boost_date_time-src;${{ env.build }}/_deps/boost_exception-src;${{ env.build }}/_deps/fmt-src;${{ env.build }}/_deps/boost_container-src;${{ env.build }}/_deps/opencv-src;${{ env.build }}/_deps/rapidjson-src;${{ env.build }}/_deps/tesseract-src

- name: Generate Codecov Report
id: generate_test_report
shell: cmd
Expand All @@ -69,7 +77,7 @@ jobs:
files: ./WolfCov.xml
fail_ci_if_error: true
functionalities: fix

# Upload SARIF file to GitHub Code Scanning Alerts
#- name: Upload SARIF to GitHub
# uses: github/codeql-action/upload-sarif@v2
Expand All @@ -80,5 +88,5 @@ jobs:
- name: Upload SARIF as an Artifact
uses: actions/upload-artifact@v3
with:
name: sarif-file
path: ${{ steps.run-analysis.outputs.sarif }}
name: sarif-file
path: ${{ steps.run-analysis.outputs.sarif }}
18 changes: 18 additions & 0 deletions wolf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ message("CXX Compiler ID is ${CMAKE_CXX_COMPILER_ID}")
# set the options and enviroment variables
set(WEBRTC_SRC $ENV{WEBRTC_ROOT} CACHE STRING "path to the root folder of webrtc folder")

# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})

# check the OS
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if (WIN32)
Expand Down Expand Up @@ -96,6 +99,10 @@ option(WOLF_SYSTEM_POSTGRESQL "Enable postgresql database client" OFF)
#option(WOLF_SYSTEM_WASM3 "Enable WebAssembly interpreter" OFF)
#option(WOLF_SYSTEM_ZLIB "Enable zlib for compression" OFF)

# machine learing modules
option(WOLF_ML_OCR "Enable machine learning referee ocr" ON)
option(WOLF_ML_NUDITY_DETECTION "Enable machine learning nudity detection" OFF)

#option(WOLF_ENABLE_LTO "Enable cross language linking time optimization" OFF)
option(WOLF_TEST "Enable tests" ON)
if (NOT MSVC)
Expand Down Expand Up @@ -186,6 +193,8 @@ include(cmake/media.cmake)
include(cmake/rust.cmake)
include(cmake/system.cmake)
include(cmake/stream.cmake)
include(cmake/ml.cmake)


if (WOLF_ENABLE_ASAN)
set(ENABLE_ASAN TRUE)
Expand Down Expand Up @@ -300,6 +309,9 @@ source_group("system" FILES ${WOLF_SYSTEM_SRC})
source_group("media/test" FILES ${WOLF_MEDIA_TEST_SRC})
source_group("media/ffmpeg" FILES ${WOLF_MEDIA_FFMPEG_SRC})
source_group("media" FILES ${WOLF_MEDIA_OPENAL_SRC} ${WOLF_MEDIA_STB_SRC})
source_group("ml/referee_ocr" FILES ${WOLF_ML_OCR_SRC})

# file(COPY ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE} DESTINATION ${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE})

# add compile options
if (NOT WIN32)
Expand All @@ -324,3 +336,9 @@ if (WOLF_TEST)
include(CTest)
add_test(NAME ${TEST_PROJECT_NAME} COMMAND ${TEST_PROJECT_NAME})
endif()

if(WOLF_ML_OCR AND WIN64)
add_custom_command(TARGET ${TEST_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}
)
endif()
157 changes: 157 additions & 0 deletions wolf/cmake/ml.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
if(WOLF_ML_OCR)

if(LINUX)
# fetch leptonica
message("fetching https://github.com/DanBloomberg/leptonica.git")
FetchContent_Declare(
leptonica
GIT_REPOSITORY https://github.com/DanBloomberg/leptonica.git
GIT_TAG 1.80.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_Populate(leptonica)

add_custom_command(OUTPUT lept_config.out COMMAND cmake -B ${leptonica_BINARY_DIR} -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX:PATH=${leptonica_BINARY_DIR}/install ${leptonica_SOURCE_DIR} )
add_custom_target(lept_config ALL DEPENDS lept_config.out)
add_custom_command(OUTPUT lept_build.out COMMAND cmake --build ${leptonica_BINARY_DIR} --target install )
add_custom_target(lept_build ALL DEPENDS lept_build.out)
endif()

# fetch tesseract
message("fetching https://github.com/tesseract-ocr/tesseract.git")
FetchContent_Declare(
tesseract
GIT_REPOSITORY https://github.com/tesseract-ocr/tesseract.git
GIT_TAG main

GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)

if(WIN64)
set(FETCHCONTENT_QUIET OFF)

set(BUILD_TESTS OFF CACHE BOOL "BUILD_TESTS")
set(BUILD_TRAINING_TOOLS OFF CACHE BOOL "BUILD_TRAINING_TOOLS")
set(DISABLE_ARCHIVE ON CACHE BOOL "DISABLE_ARCHIVE")
set(DISABLE_CURL ON CACHE BOOL "DISABLE_CURL")
set(FAST_FLOAT ON CACHE BOOL "FAST_FLOAT")
set(GRAPHICS_DISABLED ON CACHE BOOL "GRAPHICS_DISABLED")
set(INSTALL_CONFIGS OFF CACHE BOOL "INSTALL_CONFIGS")
set(SW_BUILD ON CACHE BOOL "SW_BUILD")

FetchContent_MakeAvailable(tesseract)
list(APPEND INCLUDES
${tesseract_SOURCE_DIR}/include
${tesseract_BINARY_DIR}/include
)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(DEBUG_LIB_EXTENTION "d")
else()
set(DEBUG_LIB_EXTENTION "")
endif()

list(APPEND LIBS
${tesseract_BINARY_DIR}/${CMAKE_BUILD_TYPE}/tesseract53${DEBUG_LIB_EXTENTION}.lib
)
elseif(LINUX)
FetchContent_Populate(tesseract)

list(APPEND INCLUDES
${tesseract_SOURCE_DIR}/include
${tesseract_BINARY_DIR}/install/include
)

link_directories(${tesseract_BINARY_DIR}/install/lib)
list(APPEND LIBS
tesseract
)

add_custom_command(OUTPUT tess_config.out COMMAND cmake -B ${tesseract_BINARY_DIR} -DBUILD_TESTS=OFF -DBUILD_TRAINING_TOOLS=OFF -DDISABLE_ARCHIVE=ON -DDISABLE_CURL=ON -DFAST_FLOAT=ON -DGRAPHICS_DISABLED=ON -DINSTALL_CONFIGS=OFF -DLeptonica_DIR=${leptonica_BINARY_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${tesseract_BINARY_DIR}/install ${tesseract_SOURCE_DIR} )
add_custom_target(tess_config ALL DEPENDS tess_config.out)
add_custom_command(OUTPUT tess_build.out COMMAND cmake --build ${tesseract_BINARY_DIR} --target install )
add_custom_target(tess_build ALL DEPENDS tess_build.out)
endif()

# fetch opencv
message("fetching https://github.com/opencv/opencv.git")
FetchContent_Declare(
opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 4.5.4
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)

if(WIN64)
FetchContent_GetProperties(opencv)

set(BUILD_LIST core,highgui,videoio CACHE STRING "BUILD_LIST")
set(WITH_IPP OFF CACHE BOOL "WITH_IPP")
set(BUILD_EXAMPLES OFF CACHE BOOL "BUILD_EXAMPLES")
set(OPENCV_GENERATE_PKGCONFIG ON CACHE BOOL "OPENCV_GENERATE_PKGCONFIG")

FetchContent_MakeAvailable(opencv)

list(APPEND INCLUDES
${CMAKE_BINARY_DIR}
${opencv_SOURCE_DIR}/include
${opencv_SOURCE_DIR}/modules/core/include
${opencv_SOURCE_DIR}/modules/highgui/include
${opencv_SOURCE_DIR}/modules/imgcodecs/include
${opencv_SOURCE_DIR}/modules/imgproc/include
${opencv_SOURCE_DIR}/modules/videoio/include
)
list(APPEND LIBS
${opencv_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/opencv_core454${DEBUG_LIB_EXTENTION}.lib
${opencv_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/opencv_highgui454${DEBUG_LIB_EXTENTION}.lib
${opencv_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/opencv_imgcodecs454${DEBUG_LIB_EXTENTION}.lib
${opencv_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/opencv_imgproc454${DEBUG_LIB_EXTENTION}.lib
${opencv_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/opencv_videoio454${DEBUG_LIB_EXTENTION}.lib
)
elseif(LINUX)
FetchContent_Populate(opencv)

list(APPEND INCLUDES
${opencv_BINARY_DIR}/install/include/opencv4
)
list(APPEND LIBS
${opencv_BINARY_DIR}/install/lib/libopencv_core.so
${opencv_BINARY_DIR}/install/lib/libopencv_highgui.so
${opencv_BINARY_DIR}/install/lib/libopencv_imgcodecs.so
${opencv_BINARY_DIR}/install/lib/libopencv_imgproc.so
${opencv_BINARY_DIR}/install/lib/libopencv_videoio.so
)

add_custom_command(OUTPUT opencv_config.out COMMAND cmake -B ${opencv_BINARY_DIR} -DBUILD_LIST=core,highgui,videoio -DBUILD_opencv_python3=OFF -DWITH_IPP=OFF -DBUILD_EXAMPLES=OFF -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX:PATH=${opencv_BINARY_DIR}/install ${opencv_SOURCE_DIR} )
add_custom_target(opencv_config ALL DEPENDS opencv_config.out)
add_custom_command(OUTPUT opencv_build.out COMMAND cmake --build ${opencv_BINARY_DIR} --target install )
add_custom_target(opencv_build ALL DEPENDS opencv_build.out)
endif()

# fetch rapidjson
message("fetching https://github.com/Tencent/rapidjson.git")
FetchContent_Declare(
rapidjson
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git

GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)

FetchContent_Populate(rapidjson)

list(APPEND INCLUDES
${rapidjson_SOURCE_DIR}/include
)

file(GLOB_RECURSE WOLF_ML_OCR_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/ml/referee_ocr/*"
)

list(APPEND SRCS
${WOLF_ML_OCR_SRC}
)
endif()
Loading

0 comments on commit 8ba1653

Please sign in to comment.