2015年8月25日 星期二

[OpenCV]  FAQ

此處收集自己使用 OpenCV時遇到的問題與解決方法


1. 沒有 link zlib,錯誤訊息如下
persistence.cpp:(.text.cvOpenFileStorage+0x4a8): undefined reference to `gzrewind'
persistence.cpp:(.text.cvOpenFileStorage+0x844): undefined reference to `gzopen'
persistence.cpp:(.text.cvOpenFileStorage+0xa98): undefined reference to `gzclose'
persistence.cpp:(.text.cvOpenFileStorage+0xcee): undefined reference to `gzgets' 
解法: 自行編譯compile zlib 或是找到可用的 zlib,之後加上 -lzlib 再次編譯即可



2. undefined reference to `cv::imread(cv::String const&, int)'
解法:
加上 -lopencv_imgcodecs -llibjpeg -lIlmImf -llibjasper

3. undefined reference to `uncompress'
解法:
$ sudo apt-get install zlib1g-dev
編譯時加上 -lz


4. undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
解法:
加上 -lopencv_imgproc

5. undefined reference to `cvCbrt'
解法:
`cvCbrt' 存在於 libopencv_core.a (/core/src/mathfuncs.cpp) 內,但會因為 link path 順序導致問題,此點很奇怪.... 改成以下順序可以正常編譯
-lopencv_imgproc -lopencv_imgcodecs -lopencv_core


6. arm-none-eabi-g++: error: unrecognized option '-rdynamic'
解法:
        revise toochain.cmake
        set(CMAKE_SYSTEM_NAME Generic)
     
7. CMake fails to deterimine the bitness of target platform.
可參考 https://github.com/Itseez/opencv/blob/master/CMakeLists.txt

8. CMake Error at /usr/share/cmake-2.8/Modules/TestBigEndian.cmake:44 (message): no suitable type found
參考這兩篇  
https://github.com/kripken/emscripten/issues/1106https://github.com/kripken/emscripten/issues/400
 
9. sync_fetch_and_add_4 fail
可參考
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46563 
https://vilimpoc.org/blog/2013/10/04/mucking-around-with-libc-on-android/   
摘要: 
a. 若編譯Shared library,link flags 加入 -shared 
b. 若編譯Static library,記得在 CMAKE-GUI中,取消 BUIlD_SHARED_LIBS。
10.  R_ARM_THM_MOVW_ABS_NC,訊息如下
relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC 
解法:
set CMAKE_CXX_FLAGS = -fPIC
set CMAKE_C_FLAGS = -fPIC

11. 找不到 ../../lib/libopencv_core.so,訊息如下
/usr/local/linaro-multilib-2014.06-gcc4.9/bin/../lib/gcc/arm-linux-gnueabihf/4.9.1/../../../../arm-linux-gnueabihf/bin/ld: warning: ../../lib/libopencv_core.so, needed by /usr/local/opencvForS2/lib/libopencv_imgproc.so, not found (try using -rpath or -rpath-link) 
解法: 將 *.so 複製到 /lib 即可

12. videocapture 無法打開檔案,問題可能是沒有ffmpeg
可參考 http://stackoverflow.com/questions/11444926/videocapture-is-not-working-in-opencv-2-4-2