DoubangoTelecom / ultimateMRZ-SDK

Machine-readable zone/travel document (MRZ / MRTD) detector and recognizer using deep learning
https://www.doubango.org/webapps/mrz/
Other
174 stars 49 forks source link

Exception when initializing from C# example #57

Closed dbardelas closed 2 years ago

dbardelas commented 2 years ago

I got the following exception message: "BadImageFormatException: tried to load program with incorrect format. (Excepción de HRESULT: 0x8007000B)" at this code:

  public static UltMrzSdkResult init(string jsonConfig) {
    UltMrzSdkResult ret = new UltMrzSdkResult(ultimateMrzSdkPINVOKE.UltMrzSdkEngine_init__SWIG_0(jsonConfig), true);
    return ret;
  }

jsonConfig has the following value:

{
    "debug_level": "info",
    "debug_write_input_image_enabled": false,
    "debug_internal_data_path": ".",
    "num_threads": -1,
    "gpgpu_enabled": true,
    "gpgpu_workload_balancing_enabled": false,
    "backpropagation_enabled": true,
    "ielcd_enabled": true,
    "segmenter_accuracy": "high",
    "interpolation": "bilinear",
    "min_num_lines": 2,
    "roi": [
        0,
        0,
        0,
        0
    ],
    "min_score": 0,
    "assets_folder": "",
    "license_token_data": ""
}

If execute recognizer.exe --image "path_to_my_image" got the following output:

[ULTMRZ_SDK INFO]: Initialization... [COMPV INFO]: [UltMrzSdkEngine] Call: ultimateMrzSdk::UltMrzSdkEngine::init [COMPV INFO]: [UltMrzSdkEngine] jsonConfig: {"debug_level": "info","debug_write_input_image_enabled": false,"debug_internal_data_path": ".","num_threads": -1,"gpgpu_enabled": true,"gpgpu_workload_balancing_enabled": false,"segmenter_accuracy": "high","gamma": -1,"interpolation": "bilinear","min_num_lines": 2,"roi": [0, 0, 0, 0],"min_score": 0.0,"backpropagation_enabled": true,"ielcd_enabled": true} [COMPV INFO]: [UltMrzSdkEngine] Copyright (C) 2011-2021 Doubango Telecom https://www.doubango.org ultimateMRZ-SDK https://github.com/DoubangoTelecom/ultimateMRZ-SDK version 2.8.0

[COMPV INFO]: [CompVBase] Initializing [base] modules (v 1.0.0, nt -1)... [COMPV INFO]: [CompVBase] sizeof(compv_scalar_t)= #8 [COMPV INFO]: [CompVBase] sizeof(float)= #4 [COMPV INFO]: [CompVBase] Windows dwMajorVersion=6, dwMinorVersion=2 [COMPV INFO]: Initializing window registery [COMPV INFO]: [ImageDecoder] Initializing image decoder... [COMPV INFO]: [CompVCpu] H: 'GenuineIntel', S: '', M: '', MN: '' [COMPV INFO]: [CompVBase] CPU features: (intel);[x86];[x64];mmx;sse;sse2;sse3;ssse3;sse41;sse42;avx;avx2;fma3;erms;bmi1;bmi2;popcnt;cmov;aes;rdrand;avx512_f;avx512_cd;avx512_vl;avx512_bw;avx512_dq;avx512_ifma;avx512_vbmi; [COMPV INFO]: [CompVBase] CPU cores: #8 [COMPV INFO]: [CompVBase] CPU cache1: line size: #64B, size :#48KB [COMPV INFO]: [CompVBase] CPU Phys RAM size: #7881GB [COMPV INFO]: [CompVBase] CPU endianness: LITTLE [COMPV INFO]: [CompVBase] Binary type: X86_64 [COMPV INFO]: [CompVBase] Intrinsic enabled [COMPV INFO]: [CompVBase] Assembler enabled [COMPV INFO]: [CompVBase] OS name: Windows [COMPV INFO]: [CompVBase] Math Fast Trig.: true [COMPV INFO]: [CompVBase] Math Fixed Point: true [COMPV INFO]: [CompVMathExp] Init [COMPV INFO]: [CompVBase] Default alignment: #64 [COMPV INFO]: [CompVBase] Best alignment: #64 [COMPV INFO]: [CompVBase] Heap limit: #403507KB (#394MB) [COMPV INFO]: [CompVParallel] Initializing [parallel] module... [COMPV INFO]: /!\ Code in file 'compv_mem.cxx' in function 'compv::CompVMemZero_C' starting at line #508: Not optimized -> No SIMD implementation found [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=0,set=useless, threadId:0000000000002D54, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVThreadDispatcher] Thread dispatcher created with #8 threads/#8 cores [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=5,set=useless, threadId:0000000000007164, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=3,set=useless, threadId:0000000000007764, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=1,set=useless, threadId:0000000000004934, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=2,set=useless, threadId:0000000000007D04, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=6,set=useless, threadId:0000000000000FA8, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=7,set=useless, threadId:00000000000044B8, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVAsyncTask11] compv::CompVAsyncTask11::run(coreId:requested=4,set=useless, threadId:0000000000001338, kThreadSetAffinity:false) - ENTER [COMPV INFO]: [CompVParallel] [Parallel] module initialized [COMPV INFO]: [CompVBase] [Base] modules initialized [COMPV INFO]: [CompVCore] Initializing [core] module (v 1.0.0)... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 1 and name = 'FAST (Features from Accelerated Segment Test)'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 8 and name = 'ORB (Oriented FAST and Rotated BRIEF)'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 27 and name = 'Sobel edge detector'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 28 and name = 'Scharr edge detector'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 29 and name = 'Prewitt edge detector'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 20 and name = 'Canny edge detector'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 30 and name = 'Hough standard (STD)'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 31 and name = 'Kernel-based Hough transform (KHT)'... [COMPV INFO]: [CompVFeature] Registering feature factory with id = 41 and name = 'Standard Histogram of oriented gradients (S-HOG)'... [COMPV INFO]: [CompVMatcher] Registering matcher factory with id = 0 and name = 'Brute force matcher'... [COMPV INFO]: [CompVConnectedComponentLabeling] Registering connected component labeling factory with id = 1 and name = 'PLSL (Parallel Light Speed Labeling)'... [COMPV INFO]: [CompVConnectedComponentLabeling] Registering connected component labeling factory with id = 19 and name = 'LMSER (Linear Time Maximally Stable Extremal Regions)'... [COMPV INFO]: [CompVGL] Initializing [gl] module (v 1.0.0)... [COMPV INFO]: [CompVGL] GL module initialized [COMPV INFO]: [CompVGpu] Initializing [gpu] module (v 1.0.0)... [COMPV INFO]: [CompVCamera] Initializing [camera] module (v 1.0.0)... [COMPV INFO]: [CompVCamera] Camera plugin path: C:\Users\Ictel\Downloads\ultimateMRZ-SDK-master\binaries\windows\x86_64\CompVPluginMFoundation.dll [COMPV INFO]: [CompVDrawing] Initializing [drawing] module (v 1.0.0)... [COMPV INFO]: [CompVDrawing] /!\ No jpeg decoder found [COMPV INFO]: [CompVDrawing] Drawing module initialized [COMPV INFO]: [CompVGpu] GPU enabled: true [COMPV INFO]: /!\ Code in file 'source\ultimate_base_engine.cxx' in function 'ultimateBase::UltBaseEngine::init' starting at line #75: Not optimized for GPU -> GPGPU computing not enabled or deactivated [COMPV INFO]: [UltBaseOpenCL] Trying to load [OpenCL.dll] [COMPV INFO]: [UltBaseOpenCL] Loaded [OpenCL.dll], looksLikeValid: yes... [COMPV INFO]: [UltBaseOpenCLUtils] Selected platform vendor: Intel(R) Corporation [COMPV INFO]: [UltBaseOpenCLUtils] deviceCount=1 [COMPV INFO]: [UltBaseOpenCLUtils] Device -> name: Intel(R) UHD Graphics, id: 000001E1E7E4D270 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT=1 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE=1 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_MAX_COMPUTE_UNITS=32 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS=3 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_MAX_WORK_ITEM_SIZES=256, 256, 256, [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_MAX_WORK_GROUP_SIZE=256 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_MAX_CLOCK_FREQUENCY=1050 MHz [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE=64 B [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_GLOBAL_MEM_SIZE=3305529344 B (3152 MB) [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_LOCAL_MEM_SIZE=65536 B (64 KB) [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_MAX_MEM_ALLOC_SIZE=1576 MB [COMPV INFO]: [UltBaseOpenCLUtils] CL_PLATFORM_VERSION=OpenCL 2.1 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_VERSION=OpenCL 2.1 NEO [COMPV INFO]: [UltBaseOpenCLUtils] CL_DRIVER_VERSION=26.20.100.7926 [COMPV INFO]: [UltBaseOpenCLUtils] CL_DEVICE_OPENCL_C_VERSION=OpenCL C 2.0 [COMPV ERROR]: function: "ultimateBase::UltBaseOpenCLUtils::init()" file: "source\opencl\ultimate_base_opencl_utils.cxx" line: "96" message: [UltBaseOpenCLUtils] OpenCL operation failed (-30 -> CL_INVALID_VALUE) -> [COMPV ERROR]: function: "ultimateBase::UltBaseOpenCLUtils::init()" file: "source\opencl\ultimate_base_opencl_utils.cxx" line: "106" message: Operation Failed (COMPV_ERROR_CODE_E_UNKNOWN) -> [COMPV INFO]: [UltBaseOpenCL] Failed to hook functions using [OpenCL.dll] library [COMPV INFO]: [UltMrzSdkEnginePrivate] Copyright (C) 2011-2021 Doubango Telecom https://www.doubango.org You're using an unlicensed version of ultimateMRZ-SDK https://github.com/DoubangoTelecom/ultimateMRZ-SDK without the rights to include the SDK in any form of commercial product. [COMPV INFO]: [CompVCpu] Enabling asm code [COMPV INFO]: [CompVCpu] Enabling intrinsic code [COMPV INFO]: [UltLstmNetwork] Old local: C, new local: C [COMPV INFO]: [UltLstmNetwork] Create LSTM engine for thread 1 [COMPV INFO]: [UltLstmNetwork] Create LSTM engine for thread 2 [COMPV INFO]: [UltLstmNetwork] Create LSTM engine for thread 0 Error opening data file C:/Projects/GitHub/ultimate/ultimateLstm/models/light/mrz.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Error opening data file C:/Projects/GitHub/ultimate/ultimateLstm/models/light/mrz.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language 'mrz' Failed loading language 'mrz' Tesseract couldn't load any languages! *[COMPV ERROR]: function: "ultimateLstm::UltLstmNetworkThreadData::UltLstmNetworkThreadData()" file: "source\ultimate_lstm_network.cxx" line: "70" message: Operation Failed (COMPV_ERROR_CODE_E_THIRD_PARTY_LIB) -> Failed to initialize Tesseract **[COMPV FATAL]: function: "ultimateLstm::UltLstmNetworkThreadData::UltLstmNetworkThreadData()" file: "source\ultimate_lstm_network.cxx" line: "70" message: Assertion failed! Tesseract couldn't load any languages!

DoubangoTelecom commented 2 years ago

Add --assets option to the command in addition to --image. https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#testing-examples

For the bad image, you're running the csharp app as mixed arch.

Both issues you have reported were already reported, please take time to browse the issue tracker before opening a ticket.

DoubangoTelecom commented 2 years ago

Additional note, on windows just run recognizer.bat to make your life easier as explained at https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#pre-built-binaries

dbardelas commented 2 years ago

Additional note, on windows just run recognizer.bat to make your life easier as explained at https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#pre-built-binaries

Thank you for the support. I tried recognizer.bat and is working perfectly, but with CSharp example I'm still getting the same exception and now I'm passing --assets arg and also --backprop and --ielcd (I have the same args than in the .bat file). Not sure what I'm doing wrong...

DoubangoTelecom commented 2 years ago

Additional note, on windows just run recognizer.bat to make your life easier as explained at https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#pre-built-binaries

Thank you for the support. I tried recognizer.bat and is working perfectly, but with CSharp example I'm still getting the same exception and now I'm passing --assets arg and also --backprop and --ielcd (I have the same args than in the .bat file). Not sure what I'm doing wrong...

You had 2 different issues. The CSharp issue is that you didn't build the application as x64 and has nothing to do with --assets arg. I'm confused. For CSharp you had BadImageFormatException error while for C++ you had Error opening data file C:/Projects/GitHub/ultimate/ultimateLstm/models/light/mrz.traineddata, now you say I'm still getting the same exception . What exception do you have for CSharp? Make sure you have selected x64 as target platform for CSharp, that's what causing the BadImageFormatException error. It's about the binaries image.

dbardelas commented 2 years ago

Additional note, on windows just run recognizer.bat to make your life easier as explained at https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#pre-built-binaries

Thank you for the support. I tried recognizer.bat and is working perfectly, but with CSharp example I'm still getting the same exception and now I'm passing --assets arg and also --backprop and --ielcd (I have the same args than in the .bat file). Not sure what I'm doing wrong...

You had 2 different issues. The CSharp issue is that you didn't build the application as x64 and has nothing to do with --assets arg. I'm confused. For CSharp you had BadImageFormatException error while for C++ you had Error opening data file C:/Projects/GitHub/ultimate/ultimateLstm/models/light/mrz.traineddata, now you say I'm still getting the same exception . What exception do you have for CSharp? Make sure you have selected x64 as target platform for CSharp, that's what causing the BadImageFormatException error. It's about the binaries image.

Now there is only one issue with CSharp (the other one is resolved because I used recognizer.bat).

I've tested right now your Chsarp recognizer.csproj example and it's working fine and the target selected in that project is AnyCPU, not x64. With that in mind, what I have done is copied all the code from your recognizer.csproj and paste it into another project I'm working on. I've also pasted manually the ultimateMRZ-SDK.dll file in the ..\bin\debug folder of my project, where is the place where I'm getting the exception: "BadImageFormatException: tried to load program with incorrect format. (Exception of HRESULT: 0x8007000B)" (I have the feeling that is something related with the DLL file)

I can not change to x64 in the project I'm working on because if I did I get a lot of errors after compiling.

DoubangoTelecom commented 2 years ago

Additional note, on windows just run recognizer.bat to make your life easier as explained at https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#pre-built-binaries

Thank you for the support. I tried recognizer.bat and is working perfectly, but with CSharp example I'm still getting the same exception and now I'm passing --assets arg and also --backprop and --ielcd (I have the same args than in the .bat file). Not sure what I'm doing wrong...

You had 2 different issues. The CSharp issue is that you didn't build the application as x64 and has nothing to do with --assets arg. I'm confused. For CSharp you had BadImageFormatException error while for C++ you had Error opening data file C:/Projects/GitHub/ultimate/ultimateLstm/models/light/mrz.traineddata, now you say I'm still getting the same exception . What exception do you have for CSharp? Make sure you have selected x64 as target platform for CSharp, that's what causing the BadImageFormatException error. It's about the binaries image.

Now there is only one issue with CSharp (the other one is resolved because I used recognizer.bat).

I've tested right now your Chsarp recognizer.csproj example and it's working fine and the target selected in that project is AnyCPU, not x64. With that in mind, what I have done is copied all the code from your recognizer.csproj and paste it into another project I'm working on. I've also pasted manually the ultimateMRZ-SDK.dll file in the ..\bin\debug folder of my project, where is the place where I'm getting the exception: "BadImageFormatException: tried to load program with incorrect format. (Exception of HRESULT: 0x8007000B)" (I have the feeling that is something related with the DLL file)

I can not change to x64 in the project I'm working on because if I did I get a lot of errors after compiling.

It must be x64 target, that's the only format supported. We do not support 32-bit.

dbardelas commented 2 years ago

Additional note, on windows just run recognizer.bat to make your life easier as explained at https://github.com/DoubangoTelecom/ultimateMRZ-SDK/tree/master/samples/c%2B%2B/recognizer#pre-built-binaries

Thank you for the support. I tried recognizer.bat and is working perfectly, but with CSharp example I'm still getting the same exception and now I'm passing --assets arg and also --backprop and --ielcd (I have the same args than in the .bat file). Not sure what I'm doing wrong...

You had 2 different issues. The CSharp issue is that you didn't build the application as x64 and has nothing to do with --assets arg. I'm confused. For CSharp you had BadImageFormatException error while for C++ you had Error opening data file C:/Projects/GitHub/ultimate/ultimateLstm/models/light/mrz.traineddata, now you say I'm still getting the same exception . What exception do you have for CSharp? Make sure you have selected x64 as target platform for CSharp, that's what causing the BadImageFormatException error. It's about the binaries image.

Now there is only one issue with CSharp (the other one is resolved because I used recognizer.bat). I've tested right now your Chsarp recognizer.csproj example and it's working fine and the target selected in that project is AnyCPU, not x64. With that in mind, what I have done is copied all the code from your recognizer.csproj and paste it into another project I'm working on. I've also pasted manually the ultimateMRZ-SDK.dll file in the ..\bin\debug folder of my project, where is the place where I'm getting the exception: "BadImageFormatException: tried to load program with incorrect format. (Exception of HRESULT: 0x8007000B)" (I have the feeling that is something related with the DLL file) I can not change to x64 in the project I'm working on because if I did I get a lot of errors after compiling.

It must be x64 target, that's the only format supported. We do not support 32-bit.

Ok, understood. In fact, I've run your recognizer.csproj with x86 target and I'm getting the same exception. If I select x64 it runs correctly. Thank you for helping me.