Skip to content

Commit

Permalink
Merge pull request #3 from yowidin/feature/windows-support
Browse files Browse the repository at this point in the history
Cleanup + Windows builds
  • Loading branch information
yowidin authored Jun 17, 2023
2 parents b5e270d + a6c4823 commit c3ceb8d
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 113 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
max-parallel: 3
matrix:
os:
# - windows-2022
- windows-2022
- ubuntu-22.04
- macos-12

Expand All @@ -38,8 +38,17 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
- name: Install conan
if: ${{ !startsWith(matrix.os, 'windows') }}
run: |
pip install conan
- name: Install conan (Windows)
if: startsWith(matrix.os, 'windows')
run: |
pip install conan==1.60.1
- name: Configure conan
run: |
conan --version
Expand All @@ -62,16 +71,35 @@ jobs:
mesa-common-dev libegl-dev
- name: Build
if: ${{ !startsWith(matrix.os, 'windows') }}
run: |
python .ci/build.py
- name: Build (Windows)
if: startsWith(matrix.os, 'windows')
run: |
mkdir build
cd build
conan install -b missing -s compiler.cppstd=17 -s build_type=Release ..
conan build ..
cpack -G ZIP
- name: Upload artifact
if: ${{ !startsWith(matrix.os, 'windows') }}
uses: actions/upload-artifact@v2
with:
name: ocr-suite-${{ matrix.os }}
path: ${{ github.workspace }}/build/release/ocr-suite-*.zip
if-no-files-found: error

- name: Upload artifact (Windows)
if: ${{ startsWith(matrix.os, 'windows') }}
uses: actions/upload-artifact@v2
with:
name: ocr-suite-${{ matrix.os }}
path: ${{ github.workspace }}/build/ocr-suite-*.zip
if-no-files-found: error


deploy:
if: startsWith(github.ref, 'refs/tags/')
Expand Down
72 changes: 40 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.6)
project(ocr_suite VERSION 0.1.0 LANGUAGES CXX)
project(ocr_suite VERSION 0.2.0 LANGUAGES CXX)

#################################################################################
### Setup platform-specific flags
Expand All @@ -26,31 +26,20 @@ configure_file(cmake/config.h.in ${OCS_GENERATED_CONFIG_HEADER} @ONLY)

################################################################################
### Dependencies
find_package(Tesseract CONFIG REQUIRED)
find_package(ffmpeg CONFIG REQUIRED)
find_package(PNG CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(lyra CONFIG REQUIRED)
find_package(SQLiteBurrito CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED COMPONENTS filesystem date_time)
set(
common_libs

Tesseract::libtesseract ffmpeg::ffmpeg PNG::PNG
spdlog::spdlog bfg::lyra SQLiteBurrito::library
Boost::filesystem Boost::date_time
)

################################################################################
### FFMPEG helper
add_library(
ffmpeg_helper STATIC

add_library(ffmpeg_helper STATIC
src/ffmpeg/decoder.cpp
src/ffmpeg/traits.cpp
)

target_link_libraries(ffmpeg_helper PUBLIC ${common_libs})
target_link_libraries(ffmpeg_helper
PUBLIC
ffmpeg::ffmpeg spdlog::spdlog
)

target_include_directories(
ffmpeg_helper
Expand All @@ -71,29 +60,32 @@ set_target_properties(

################################################################################
### Library
add_library(
ocr_lib STATIC
find_package(SQLiteBurrito CONFIG REQUIRED)

src/recognition/video.cpp
src/recognition/bmp.cpp
src/recognition/ocr.cpp
add_library(
ocr_common STATIC

src/database.cpp
src/common/database.cpp
src/common/video.cpp
)

target_link_libraries(ocr_lib PUBLIC ${common_libs} ffmpeg_helper)
target_link_libraries(ocr_common
PUBLIC
ffmpeg_helper
spdlog::spdlog SQLiteBurrito::library
)

target_include_directories(
ocr_lib
ocr_common

PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
PUBLIC $<BUILD_INTERFACE:${OCS_GENERATED_INCLUDE_DIR}>
)

set_target_properties(
ocr_lib PROPERTIES
ocr_common PROPERTIES

OUTPUT_NAME ocr-lib
OUTPUT_NAME ocr-common

CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
Expand All @@ -102,18 +94,30 @@ set_target_properties(

################################################################################
### Main Tool
find_package(PNG CONFIG REQUIRED)
find_package(Tesseract CONFIG REQUIRED)
find_package(lyra CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED COMPONENTS filesystem date_time)
find_package(indicators CONFIG REQUIRED)
set(main_libs indicators::indicators)

add_executable(
ocr_suite

src/recognition/main.cpp
src/recognition/bmp.cpp
src/recognition/ocr.cpp

src/recognition/speed_meter.cpp
src/recognition/options.cpp

src/recognition/main.cpp
)

target_link_libraries(ocr_suite PRIVATE ocr_lib ${main_libs})
target_link_libraries(ocr_suite
PRIVATE
ocr_common
indicators::indicators Tesseract::libtesseract bfg::lyra
Boost::filesystem
)

set_target_properties(
ocr_suite PROPERTIES
Expand Down Expand Up @@ -145,7 +149,6 @@ find_package(SDL2 CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(OpenGL REQUIRED)
set(ui_libs SDL2::SDL2-static SDL2::SDL2main imgui::imgui glad::glad OpenGL::GL)

add_executable(
ocr_suite_viewer
Expand Down Expand Up @@ -176,7 +179,12 @@ add_executable(
${CMAKE_CURRENT_BINARY_DIR}/bindings/imgui_impl_sdl.cpp
)

target_link_libraries(ocr_suite_viewer PRIVATE ocr_lib ${ui_libs})
target_link_libraries(ocr_suite_viewer
PRIVATE
ocr_common
SDL2::SDL2-static SDL2::SDL2main imgui::imgui glad::glad OpenGL::GL
Boost::date_time Boost::filesystem bfg::lyra
)

target_include_directories(
ocr_suite_viewer PUBLIC
Expand Down
10 changes: 6 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Recipe(ConanFile):
name = 'ocr-suite'
version = '0.1.0'
version = '0.2.0'

description = 'OCR Suite'
settings = 'os', 'arch', 'compiler', 'build_type'
Expand Down Expand Up @@ -49,7 +49,7 @@ def configure(self):
self.options['ffmpeg'].with_libx264 = False
self.options['ffmpeg'].with_libx265 = False
self.options['ffmpeg'].with_openjpeg = False
self.options['ffmpeg'].with_pulse = False


self.options['tesseract'].with_auto_optimize = True
self.options['tesseract'].with_march_native = False
Expand All @@ -59,8 +59,10 @@ def configure(self):
self.options['glad'].gl_profile = 'core'
self.options['glad'].gl_version = '3.2'

# SDL settings
self.options['sdl'].pulse = False
# Turn off the Pulse Audio support for non-windows OSs
if self.settings.os != 'Windows':
self.options['ffmpeg'].with_pulse = False
self.options['sdl'].pulse = False

if self.settings.os == 'Macos':
self.options['boost'].with_stacktrace_backtrace = False
Expand Down
6 changes: 3 additions & 3 deletions include/ocs/database.h → include/ocs/common/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include <ocs/recognition/ocr.h>
#include <ocs/common/ocr_result.h>

#include <sqlite-burrito/versioned_database.h>

Expand All @@ -13,7 +13,7 @@

struct sqlite3;

namespace ocs {
namespace ocs::common {

//! A class for storing the results of the OCR process in a sqlite3 database.
class database {
Expand All @@ -34,7 +34,7 @@ class database {
database(std::string db_path, bool read_only = false);

public:
void store(const ocs::recognition::ocr::ocr_result &result);
void store(const ocr_result &result);

std::int64_t get_starting_frame_number();
bool is_frame_processed(std::int64_t frame_num);
Expand Down
26 changes: 26 additions & 0 deletions include/ocs/common/ocr_result.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by Dennis Sitelew on 17.06.2023.
//

#ifndef OCS_COMMON_OCR_RESULT_H
#define OCS_COMMON_OCR_RESULT_H

#include <string>
#include <vector>

namespace ocs::common {

struct text_entry {
int left, top, right, bottom;
float confidence;
std::string text;
};

struct ocr_result {
std::int64_t frame_number{};
std::vector<text_entry> entries{};
};

} // namespace ocs::common

#endif // OCR_SUITE_OCR_RESULT_H
2 changes: 1 addition & 1 deletion include/ocs/util.h → include/ocs/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <algorithm>
#include <string>

namespace ocs::util {
namespace ocs::common::util {

// trim from start (in place)
inline void ltrim(std::string &s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <optional>
#include <vector>

namespace ocs::recognition {
namespace ocs::common {

/**
* Holds a limited list of value pointers, allowing a single producer to generate values and multiple consumers to
Expand Down Expand Up @@ -166,4 +166,4 @@ std::size_t value_queue<T>::get_remaining_consumer_values() const {
return consumer_values_.size();
}

} // namespace ocs::recognition
} // namespace ocs::common
12 changes: 7 additions & 5 deletions include/ocs/recognition/video.h → include/ocs/common/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#pragma once

#include <ocs/recognition/options.h>
#include <ocs/recognition/value_queue.h>
#include <ocs/common/value_queue.h>

#include <ocs/ffmpeg/decoder.h>

Expand All @@ -15,7 +14,7 @@
#include <string>
#include <vector>

namespace ocs::recognition {
namespace ocs::common {

//! Class for getting frames from a video file, using the ffmpeg library.
class video {
Expand All @@ -24,7 +23,10 @@ class video {
using queue_ptr_t = std::shared_ptr<queue_t>;

public:
video(const options &opts, queue_ptr_t queue, std::int64_t starting_frame = 0);
video(const std::string &path,
ffmpeg::decoder::frame_filter filter,
queue_ptr_t queue,
std::int64_t starting_frame = 0);

public:
void start();
Expand All @@ -42,4 +44,4 @@ class video {
ffmpeg::decoder decoder_;
};

} // namespace ocs::recognition
} // namespace ocs::common
21 changes: 6 additions & 15 deletions include/ocs/recognition/ocr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#pragma once

#include <ocs/common/ocr_result.h>

#include <ocs/recognition/options.h>
#include <ocs/recognition/video.h>
#include <ocs/common/video.h>

#include <functional>
#include <string>
Expand All @@ -17,22 +19,11 @@ namespace ocs::recognition {

class ocr {
public:
using value_queue_t = video::queue_t;
using value_queue_ptr_t = video::queue_ptr_t;
using value_queue_t = common::video::queue_t;
using value_queue_ptr_t = common::video::queue_ptr_t;
using frame_t = value_queue_t::value_ptr_t;

struct text_entry {
int left, top, right, bottom;
float confidence;
std::string text;
};

struct ocr_result {
std::int64_t frame_number{};
std::vector<text_entry> entries{};
};

using ocr_result_cb_t = std::function<void(const ocr_result &)>;
using ocr_result_cb_t = std::function<void(const common::ocr_result &)>;
using ocr_filter_cb_t = std::function<bool(std::int64_t)>;

public:
Expand Down
Loading

0 comments on commit c3ceb8d

Please sign in to comment.