Skip to content

Commit

Permalink
refactor: 移除rc相关设施,仅保留link嵌入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
GengGode committed Aug 30, 2024
1 parent 740185a commit 47ede07
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/[email protected]
with:
# Artifact name
name: libocr
name: libocr-shared_${{ matrix.shared_type }}
path: ${{github.workspace}}/build/libocr-${{ steps.get_version.outputs._version }}.zip

release:
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_TARGET_NAME libocr CACHE STRING "Build target_name" FORCE)
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs")
set(BUILD_TEST OFF CACHE BOOL "Build test")
set(ENABLE_RC OFF CACHE BOOL "embed rc file")
set(ENABLE_LINKEDRESOURCE "not embed file" CACHE STRING "embed file status")
#=======================================================================================================================
set(include_dir ${CMAKE_SOURCE_DIR}/include)
Expand Down Expand Up @@ -83,7 +82,6 @@ message(STATUS " BUILD_TARGET_NAME : ${BUILD_TARGET_NAME}")
message(STATUS " BUILD_SHARED_LIBS : ${BUILD_SHARED_LIBS}")
message(STATUS " BUILD_TEST : ${BUILD_TEST}")
message(STATUS "Model : ")
message(STATUS " enable rc : ${ENABLE_RC}")
message(STATUS " enable linked resource : ${ENABLE_LINKEDRESOURCE}")
message(STATUS " model_rec_file : ${model_rec_file}")
message(STATUS " model_cls_file : ${model_cls_file}")
Expand Down
77 changes: 0 additions & 77 deletions resource/resource_model.rc

This file was deleted.

2 changes: 1 addition & 1 deletion resource/version.ver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.126
0.3.131
2 changes: 1 addition & 1 deletion resource/version_hash.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93be619
740185a
6 changes: 0 additions & 6 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ target_compile_options(${BUILD_TARGET_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/M
# rc文件
set(version_rc_file "${CMAKE_BINARY_DIR}/resource_version.rc")
configure_file("${CMAKE_SOURCE_DIR}/resource/resource_version.rc.in" "${version_rc_file}")
if (BUILD_SHARED_LIBS)
set(model_rc_file "${CMAKE_SOURCE_DIR}/resource/resource_model.rc")
list(APPEND resource_files "${version_rc_file}" "${model_rc_file}")
set(ENABLE_RC ON CACHE INTERNAL "embed rc file")
endif()

# cpp文件
file(GLOB_RECURSE source_files "*.cpp" "*.h" "*.hpp" "*.c" "*.cc" "*.cxx" "*.hxx")
Expand All @@ -29,7 +24,6 @@ list(APPEND source_files ${resource_files})

target_include_directories(${BUILD_TARGET_NAME} PUBLIC ${include_dir})
target_compile_definitions(${BUILD_TARGET_NAME} PRIVATE LIBOCR_EXPORTS)
target_compile_definitions(${BUILD_TARGET_NAME} PRIVATE LIBOCR_NAME="${BUILD_TARGET_NAME}.dll")
if (BUILD_SHARED_LIBS)
target_compile_definitions(${BUILD_TARGET_NAME} PRIVATE _LIB)
endif()
Expand Down
61 changes: 0 additions & 61 deletions source/onnx/onnx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define LIBOCR_ONNX_H
#include <onnxruntime_cxx_api.h>
#include <opencv2/opencv.hpp>
#include <windows.h>

#include "embed_resource.h"

Expand Down Expand Up @@ -49,66 +48,6 @@ namespace libocr::onnx
auto res_data = libocr::from_resource_load_file(file_name);
return { res_data.data, res_data.size };
}
#ifndef _LIB
res_data_ptr from_resource_load_onnx(int idr)
{
// Initialize session from Resource idr
#ifdef _LIB
auto h_module = GetModuleHandle(NULL);
#else
#ifdef _UNICODE
auto h_module = GetModuleHandle(L LIBOCR_NAME);
#else
auto h_module = GetModuleHandle(LIBOCR_NAME);
#endif
#endif

#ifdef _UNICODE
HRSRC h_res = FindResource(h_module, MAKEINTRESOURCE(idr), L"Onnx");
#else
HRSRC h_res = FindResource(h_module, MAKEINTRESOURCE(idr), "Onnx");
#endif
if (h_res == 0)
return res_data_ptr();
HGLOBAL h_mem = LoadResource(h_module, h_res);
if (h_mem == 0)
return res_data_ptr();

DWORD dw_size = SizeofResource(h_module, h_res);
LPVOID lp_data = LockResource(h_mem);

return { lp_data, dw_size };
}

res_data_ptr from_resource_load_det_txt(int idr)
{
// Initialize txt from Resource idr
#ifdef _LIB
auto h_module = GetModuleHandle(NULL);
#else
#ifdef _UNICODE
auto h_module = GetModuleHandle(L LIBOCR_NAME);
#else
auto h_module = GetModuleHandle(LIBOCR_NAME);
#endif
#endif
#ifdef _UNICODE
HRSRC h_res = FindResource(h_module, MAKEINTRESOURCE(idr), L"Txt");
#else
HRSRC h_res = FindResource(h_module, MAKEINTRESOURCE(idr), "Txt");
#endif
if (h_res == 0)
return res_data_ptr();
HGLOBAL h_mem = LoadResource(h_module, h_res);
if (h_mem == 0)
return res_data_ptr();

DWORD dw_size = SizeofResource(h_module, h_res);
LPVOID lp_data = LockResource(h_mem);

return { lp_data, dw_size };
}
#endif
private:
std::string get_input_name(Ort::Session* session)
{
Expand Down
6 changes: 0 additions & 6 deletions source/onnx/text_detector/text_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
//

#include "text_detector.h"
#include "../../resource/resource.h"

libocr::onnx::text_detector::text_detector()
{
set_options();
#if 0
//===== this set model resource IDR ONNX MODEL =====
auto model = onnx::from_resource_load_onnx(IDR_ONNX_DET);
#else
//===== this set model resource file ONNX MODEL =====
auto model = onnx::from_resource_load_file("model_det.onnx");
#endif
session = std::make_shared<Ort::Session>(env, model.data, model.data_length, session_options);

init_model();
Expand Down
11 changes: 0 additions & 11 deletions source/onnx/text_recognizer/text_recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,16 @@
//

#include "text_recognizer.h"
#include "../../resource/resource.h"

libocr::onnx::text_recognizer::text_recognizer()
{
set_options();
#if 0
//===== this set model resource IDR ONNX MODEL =====
auto model = onnx::from_resource_load_onnx(IDR_ONNX_CHT_REC);
#else
//===== this set model resource file ONNX MODEL =====
auto model = onnx::from_resource_load_file("model_rec.onnx");
#endif
session = std::make_shared<Ort::Session>(env, model.data, model.data_length, session_options);

#if 0
//===== this set keys resource IDR Txt =====
auto dict = onnx::from_resource_load_det_txt(IDR_TXT_CHT_DICT);
#else
//===== this set keys resource file Txt =====
auto dict = onnx::from_resource_load_file("model_rec_dict.txt");
#endif
{
auto dict_string = std::string((char*)dict.data, dict.data_length);
std::istringstream in(dict_string);
Expand Down
27 changes: 0 additions & 27 deletions source/resource/resource.h

This file was deleted.

0 comments on commit 47ede07

Please sign in to comment.