yge58 / scene_text_ocr

Detect and recognise text from scene
Other
3 stars 1 forks source link

OpenCV Error: Bad argument (Default classifier file not found!) in ERClassifierNM1, file #1

Closed wanghaisheng closed 7 years ago

wanghaisheng commented 7 years ago
➜  scene_text_ocr git:(master) ✗ cmake . 
-- The C compiler identification is AppleClang 9.0.0.9000037
-- The CXX compiler identification is AppleClang 9.0.0.9000037
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
-- Found OpenCV: /usr/local (found version "3.3.0") 
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2") 
-- Checking for one of the modules 'tesseract'
-- Checking for one of the modules 'lept'
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/wanghaisheng/workspace/OCR/binarization-experiments/scene_text_ocr
➜  scene_text_ocr git:(master) ✗ make 
Scanning dependencies of target ocr4real
[ 50%] Building CXX object CMakeFiles/ocr4real.dir/main.cpp.o
[100%] Linking CXX executable ocr4real
[100%] Built target ocr4real
➜  scene_text_ocr git:(master) ✗ ./ocr4real ../IMG_20170922_142015.jpg  
Usage:
[no arg]    -- press space to capture image using webcam
[arg 1]     -- input image and press space to see text
>>>>>>>>>   Camera initialization is done! 
OpenCV Error: Bad argument (Default classifier file not found!) in ERClassifierNM1, file /tmp/opencv-20170825-90583-1pdhamg/opencv-3.3.0/opencv_contrib/modules/text/src/erfilter.cpp, line 1024
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20170825-90583-1pdhamg/opencv-3.3.0/opencv_contrib/modules/text/src/erfilter.cpp:1024: error: (-5) Default classifier file not found! in function ERClassifierNM1

[1]    20920 abort      ./ocr4real ../IMG_20170922_142015.jpg
yge58 commented 7 years ago

Hi,

First, thank you for trying to use my demo program.

Have you put "trained_classifierNM1.xml" into "build" directory?

Basically, when you execute "ocr4real", the runtime is looking for "trained_classifierNM1.xml" which is located in the same directory as "ocr4real".

Please let me know if it works out.

wanghaisheng commented 7 years ago

as you can see ,

➜  scene_text_ocr git:(master) ✗ ll build 
total 1304
-rw-r--r--   1 wanghaisheng  staff   23356  9 23 18:40 CMakeCache.txt
drwxr-xr-x  15 wanghaisheng  staff     510  9 23 18:40 CMakeFiles
-rw-r--r--   1 wanghaisheng  staff    4839  9 23 18:40 Makefile
-rw-r--r--   1 wanghaisheng  staff   31713  9 23 18:40 OCRHMM_transitions_table.xml
-rw-r--r--   1 wanghaisheng  staff    1403  9 23 18:40 cmake_install.cmake
-rw-r--r--   1 wanghaisheng  staff  189432  9 23 18:40 ocr4real
-rw-r--r--   1 wanghaisheng  staff   97100  9 23 18:40 scenetext01.jpg
-rw-r--r--   1 wanghaisheng  staff   95135  9 23 18:40 scenetext02.jpg
-rw-r--r--   1 wanghaisheng  staff   60751  9 23 18:40 scenetext03.jpg
-rw-r--r--   1 wanghaisheng  staff   47846  9 23 18:40 trained_classifierNM1.xml
-rw-r--r--   1 wanghaisheng  staff   47830  9 23 18:40 trained_classifierNM2.xml
-rw-r--r--   1 wanghaisheng  staff   48181  9 23 18:40 trained_classifier_erGrouping.xml

but i dont get what you mean by "hen you execute "ocr4real", the runtime is looking for "trained_classifierNM1.xml" which is located in the same directory as "ocr4real""

ocr4real is here

➜  scene_text_ocr git:(master) ✗ ll .
total 512
-rw-r--r--   1 wanghaisheng  staff   19323  9 23 18:50 CMakeCache.txt
drwxr-xr-x  16 wanghaisheng  staff     544  9 23 18:52 CMakeFiles
-rw-r--r--   1 wanghaisheng  staff     938  9 23 18:40 CMakeLists.txt
-rw-r--r--   1 wanghaisheng  staff    1980  9 23 18:40 LICENSE
-rw-r--r--   1 wanghaisheng  staff    5073  9 23 18:50 Makefile
-rw-r--r--   1 wanghaisheng  staff     492  9 23 18:40 README.md
drwxr-xr-x  14 wanghaisheng  staff     476  9 23 18:40 build
-rw-r--r--   1 wanghaisheng  staff    1318  9 23 18:50 cmake_install.cmake
drwxr-xr-x  31 wanghaisheng  staff    1054  9 23 18:40 data
drwxr-xr-x   8 wanghaisheng  staff     272  9 23 18:40 demo
-rw-r--r--   1 wanghaisheng  staff   12912  9 23 18:40 main.cpp
-rwxr-xr-x   1 wanghaisheng  staff  164676  9 23 18:52 ocr4real
-rw-r--r--   1 wanghaisheng  staff   13769  9 23 18:40 openMP_sceneTextOCR.cpp
-rw-r--r--   1 wanghaisheng  staff   12612  9 23 18:40 sceneTextOCR.cpp
drwxr-xr-x   8 wanghaisheng  staff     272  9 23 18:40 test
wanghaisheng commented 7 years ago

how to setup and run test against these cpp files

➜  binarization-experiments git clone https://github.com/yge58/scene_text_ocr
Cloning into 'scene_text_ocr'...
remote: Counting objects: 146, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 146 (delta 0), reused 0 (delta 0), pack-reused 144
Receiving objects: 100% (146/146), 7.84 MiB | 522.00 KiB/s, done.
Resolving deltas: 100% (49/49), done.
➜  binarization-experiments cd scene_text_ocr 
➜  scene_text_ocr git:(master) cmake .
-- The C compiler identification is AppleClang 9.0.0.9000037
-- The CXX compiler identification is AppleClang 9.0.0.9000037
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
-- Found OpenCV: /usr/local (found version "3.3.0") 
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2") 
-- Checking for one of the modules 'tesseract'
-- Checking for one of the modules 'lept'
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/wanghaisheng/workspace/OCR/binarization-experiments/scene_text_ocr
➜  scene_text_ocr git:(master) ✗ make
Scanning dependencies of target ocr4real
[ 50%] Building CXX object CMakeFiles/ocr4real.dir/main.cpp.o
[100%] Linking CXX executable ocr4real
[100%] Built target ocr4real
yge58 commented 7 years ago

"When you execute "ocr4real", the runtime is looking for "trained_classifierNM1.xml" which is located in the same directory as "ocr4real"

The executable "ocr4real" and pre-trained file "trained_classifierNM1.xml" are meant to be in the same directory, as you can see they are both in "build" directory.

Please let me know if it works out.

yge58 commented 7 years ago

As for the "test" files, they are the previous version including the original copy of OpenCV. My entire project is based on OpenCV original. I try to speed up the original, as you can see the text detection part is pretty time-consuming.

ML and CNN gives good accuracy, correct me if I am wrong, they are slow and memory consuming. And they need to a GPU to run at normal speed >_<!

So, please disregard those "test" files.

yge58 commented 7 years ago

In build directory, delete everything other than these 3 files, trained_classifierNM1.xml trained_classifierNM2.xml
trained_classifier_erGrouping.xml

then in build cmake .. make

finally, within build directory, run the "ocr4real".

Good luck.

wanghaisheng commented 7 years ago

@yge58 when i throw no arg ocr4real use cam as input source, but why explicitly feed image it still start cam ?

(py2.7) ➜  build git:(master) ✗ ./ocr4real ../demo/Screenshot\ from\ 2017-08-16\ 09-10-02.png 
Usage:
[no arg]    -- press space to capture image using webcam
[arg 1]     -- input image and press space to see text
yge58 commented 7 years ago

Good point! And you are correct.

Initially, I just want no input argument.

The input image is for debugging, to extract image, read text and recognise it.

If I have time, I would definitely not add [arg 1], ie. not feed image at all, only raw images from camera.

The project is open source, and I would be thankful if you can help me correct it.

I am currently with another project right now.

The code is pretty much 90% percent finished, bugs, fixes, I intend not to maintain. Sorry.

Thank you again for pointing thta out

wanghaisheng commented 7 years ago

definitely i want to help ,i have barely no knowledge about C/C++。。。

yge58 commented 7 years ago

My dear friend,

It took me long, to study c/c++, cmake and all that openCV basics.

But dont be afraid, the openCV tutorial is well-written and documented.

You may start learning c++ from using openCV. And you learn CV and C++ at the same time.

Best luck.