天天看點

移植Opencv到arm tq2440

移植opencv到tq2440

一、下載下傳opencv及cmake
1,download opencv_2.3.1
OpenCV-2.3.1a.tar.bz2  
下載下傳連結:http://opencv.org/downloads.html
2,download cmake 
//cmake-3.1.0.tar.gz //without gui
cmake-3.1.0-Linux-i386.sh
下載下傳連結:http://www.cmake.org/cmake/resources/software.html

二、将下載下傳檔案放入linux下
1,cmake
檔案路徑
/opt/EmbedSky/cmake/cmake-3.1.0
解壓
[[email protected] cmake-3.1.0]# tar -xzvf cmake-3.1.0.tar.gz -C ./
2,opencv
檔案路徑
where is the source code:
/opt/EmbedSky/opencv_2_3_1/OpenCV-2.3.1

where to build the binaries:
/opt/EmbedSky/opencv_2_3_1/opencv_forArm

#./cmake-3.1.0-Linux-i386.sh

#cd cmake-3.1.0-Linux-i386

#cd bin

#./cmake-gui

where is the source code:/opt/EmbedSky/opencv_2_3_1/OpenCV-2.3.1

where to build the binaries:/opt/EmbedSky/opencv_2_3_1/opencv_forArm

然後,點選Configure,保持generator為Unix Makefiles,選擇Specify options for cross-compiling,點選Next
Operating System填寫arm-linux 或者 Linux 注意L是大寫(我用的是這個,ok的)
C Compilers填寫/opt/EmbedSky/4.3.3/bin/arm-linux-gcc
C++ Compilers填寫/opt/EmbedSky/4.3.3/bin/arm-linux-g++
Target Root填寫/opt/EmbedSky/4.3.3
點選finish
///
err1:
System is unknown to cmake, create:
Platform/arm-linux to use this system, please send your config file to cmak[email protected] so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please send that file to [email protected].
Extracting svn version, please wait...
SVNVERSION: exported
Detected version of GNU GCC: 20091 (200901)
Could NOT find PythonLibs (missing:  PYTHON_INCLUDE_DIRS) 
Unknown option: -B
usage: /usr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

Unknown option: -B
usage: /usr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

CUDA_TOOLKIT_ROOT_DIR not found or specified
CMake Error at /opt/EmbedSky/cmake/cmake-3.1.0-Linux-i386/share/cmake-3.1/Modules/FindCUDA.cmake:616 (if):
  if given arguments:

    "CUDA_VERSION" "VERSION_GREATER" "5.0" "AND" "CMAKE_CROSSCOMPILING" "AND" "MATCHES" "arm" "AND" "EXISTS" "CUDA_TOOLKIT_ROOT_DIR-NOTFOUND/targets/armv7-linux-gnueabihf"

  Unknown arguments specified
Call Stack (most recent call first):
  CMakeLists.txt:958 (find_package)


Configuring incomplete, errors occurred!
See also "/opt/EmbedSky/opencv_2_3_1/opencv_forArm/CMakeFiles/CMakeOutput.log".
anwser:将 WITH_CUDA的鈎去掉

//
err2:
CMake Warning (dev) at CMakeLists.txt:1508 (add_custom_target):
  Policy CMP0037 is not set: Target names should not be reserved and should
  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  The target name "package_source" is reserved or not valid for certain CMake
  features, such as generator expressions, and may result in undefined
  behavior.
This warning is for project developers.  Use -Wno-dev to suppress it.
anwser2:WITH_TIFF去掉



System is unknown to cmake, create:
Platform/arm-linux to use this system, please send your config file to [email protected] so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please send that file to [email protected].
Extracting svn version, please wait...
SVNVERSION: exported
Detected version of GNU GCC: 20091 (200901)
Could NOT find PythonLibs (missing:  PYTHON_INCLUDE_DIRS) 
Unknown option: -B
usage: /usr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

Unknown option: -B
usage: /usr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

Parsing 'cvconfig.h.cmake'
CMake Warning (dev) at CMakeLists.txt:1508 (add_custom_target):
  Policy CMP0037 is not set: Target names should not be reserved and should
  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  The target name "package_source" is reserved or not valid for certain CMake
  features, such as generator expressions, and may result in undefined
  behavior.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_calib3d".
  Use the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

Call Stack (most recent call first):
  modules/calib3d/CMakeLists.txt:1 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_core".
  Use the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

Call Stack (most recent call first):
  modules/core/CMakeLists.txt:8 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target
  "opencv_test_features2d".  Use the target name directly with
  add_custom_command, or use the generator expression $<TARGET_FILE>, as
  appropriate.

Call Stack (most recent call first):
  modules/features2d/CMakeLists.txt:1 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at modules/highgui/CMakeLists.txt:418 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_highgui".
  Use the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at modules/highgui/CMakeLists.txt:418 (get_target_property):
  Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
  interface.  Run "cmake --help-policy CMP0022" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "opencv_highgui" has an INTERFACE_LINK_LIBRARIES property which
  differs from its LINK_INTERFACE_LIBRARIES properties.

  INTERFACE_LINK_LIBRARIES:

    opencv_core;opencv_imgproc;zlib;libjpeg;libpng;libjasper

  LINK_INTERFACE_LIBRARIES:

    

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_imgproc".
  Use the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

Call Stack (most recent call first):
  modules/imgproc/CMakeLists.txt:1 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_ml".  Use
  the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

Call Stack (most recent call first):
  modules/ml/CMakeLists.txt:1 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target
  "opencv_test_objdetect".  Use the target name directly with
  add_custom_command, or use the generator expression $<TARGET_FILE>, as
  appropriate.

Call Stack (most recent call first):
  modules/objdetect/CMakeLists.txt:1 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at OpenCVModule.cmake:158 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_video".
  Use the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

Call Stack (most recent call first):
  modules/video/CMakeLists.txt:1 (define_opencv_module)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at modules/gpu/CMakeLists.txt:213 (get_target_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "opencv_test_gpu".
  Use the target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at modules/gpu/CMakeLists.txt:88 (add_library):
  Policy CMP0038 is not set: Targets may not link directly to themselves.
  Run "cmake --help-policy CMP0038" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  Target "opencv_gpu" links to itself.
This warning is for project developers.  Use -Wno-dev to suppress it.


General configuration for opencv 2.3.1 =====================================

    Built as dynamic libs?:     YES
    Compiler:                   /opt/EmbedSky/4.3.3/bin/arm-linux-g++
    C++ flags (Release):          -Wall -ffunction-sections  -O3 -DNDEBUG  -fomit-frame-pointer -DNDEBUG 
    C++ flags (Debug):            -Wall -ffunction-sections  -g  -O0 -DDEBUG -D_DEBUG -ggdb3 
    Linker flags (Release):
    Linker flags (Debug):

  GUI: 
    GTK+ 2.x:                   NO
    GThread:                    NO

  Media I/O: 
    ZLib:                       build
    JPEG:                       build
    PNG:                        build
    TIFF:                       
    JPEG 2000:                  build
    OpenEXR:                    NO
    OpenNI:                     NO
    OpenNI PrimeSensor Modules: NO
    XIMEA:                      NO


  Other third-party libraries:
    Use IPP:                    NO
    Use TBB:                    NO
    Use Cuda:                   NO
    Use Eigen:                  NO

  Interfaces:
    Python:                     YES
    Python interpreter:         /usr/bin/python -B (ver 2.5)
    Python numpy:               NO (Python wrappers will not be generated)
    Java:                       NO

  Documentation:
    Sphinx:                     NO
    PdfLaTeX compiler:          /usr/bin/pdflatex
    Build Documentation:        NO

  Tests and samples:
    Tests:                      YES
    Examples:                   NO

  Install path:                 /usr/local

  cvconfig.h is in:             /opt/EmbedSky/opencv_2_3_1/opencv_forArm
-----------------------------------------------------------------

Configuring done
有些警告忽略了

#make
/usr/lib/libImath.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so] 錯誤 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] 錯誤 2
make: *** [all] 錯誤 2

answer:
remove BUILD_OPENEXR options

#make
....
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/main.o
Linking CXX executable ../../bin/opencv_stitching
[100%] Built target opencv_stitching

參考:
http://blog.sina.com.cn/s/blog_92942dba0101d1wj.html
http://blog.csdn.net/embeddedman/article/details/7416934
http://blog.csdn.net/chenaini119/article/details/39079965
http://blog.csdn.net/eagelangel/article/details/7232364
http://lbn321.blog.163.com/blog/static/227841017201422491245680/
http://blog.csdn.net/b5w2p0/article/details/39211013
<span style="color:#FF0000;">
小的總結
以上是用CMAKE編譯OPENCV2.3.1,需要主要幾個問題:

1,下載下傳cmake和opencv,解壓到linux下,這步很簡單不會有什麼問題

2,怎麼去config cmake,最關鍵的
參考:http://blog.csdn.net/luotuo44/article/details/8958990

3,修改CMakeCache.txt  添加-lpthread -ldl -lrt
//Flags used by the linker.
CMAKE_EXE_LINKER_FLAGS:STRING=-lpthread -lrt -ldl

4,make && make install

5,測試應用程式

6,移植到arm

我認為如果沒有必要用更高opencv的話,比如opencv2.3.1
就用opencv2.0.0
為什麼推薦opencv2.0呢,很簡單,
1,沒有cmake,直接config...就可以了;
2,節約時間;
3,最頭痛的是 遇到一大推BUG,比如出現找不到連結庫,最老火的是,那庫就在那兒,它還說找不到,
哈哈,如果懂修改工具鍊會得到解決,我遇到這個問題,網上也有人遇到這個問題
/opt/EmbedSky/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld: 
warning: ../../lib/libopencv_imgproc.so, needed by 
/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/lib/libopencv_highgui.so, 
not found (try using -rpath or -rpath-link)
/opt/EmbedSky/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld: 
warning: ../../lib/libopencv_core.so, needed by 
/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/lib/libopencv_highgui.so, 
not found (try using -rpath or -rpath-link)

下面介紹一下移植opencv2.0.0
1,下載下傳及解壓

2,生成opencv編譯後的目錄,友善管理
</span><h3><pre name="code" class="cpp"><span style="color:#FF0000;">#mkdir -p /opt/arm/opencv 
#mkdir -p /opt/arm/opencv/lib 
#mkdir -p /opt/arm/opencv/include</span>
           

3,執行config

#./configure --host=arm-linux --without-gtk --without-carbon --without-quicktime --without-1394libs --without-ffmpeg --without-python --without-swig --enable-static --enable-shared --disable-apps CXX=arm-linux-g++ CPPFLAGS=-I/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/include LDFLAGS=-L/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/libc/lib --with-v4l2 --prefix=/opt/arm/opencv --libdir=/opt/arm/opencv/lib -includedir=/opt/arm/opencv/include

分析一下指令:還是比較簡單的,在執行上述指令前需要生成3個目錄,見2

./configure

--host=arm-linux

--without-gtk

--without-carbon

--without-quicktime

--without-1394libs

--without-ffmpeg

--without-python

--without-swig

--enable-static

--enable-shared

--disable-apps

CXX=arm-linux-g++

CPPFLAGS=-I/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/include

LDFLAGS=-L/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/libc/lib

--with-v4l2

--prefix=/opt/arm/opencv

--libdir=/opt/arm/opencv/lib

-includedir=/opt/arm/opencv/include

<span style="color:#FF0000;">4,找到opencv/include/opencv目錄下的cxtypes.h 
   第240的
“return (int)lrint(value);
”改為“return (int)(value + 0.5)即可。</span>
           

5,寫測試應用程式,下面這個很通用,我也是在網上找的

//test.c

#include <cv.h>

#include <cxcore.h>

#include <highgui.h>

int main( int argc, char** argv )

{

  //聲明IplImage指針

  IplImage* pFrame = NULL;

 //擷取攝像頭

  CvCapture* pCapture = cvCreateCameraCapture(-1);

  //建立視窗

  cvNamedWindow("video", 1);

  //顯示視屏

  while(1)

  {

      pFrame=cvQueryFrame( pCapture );

      if(!pFrame)break;

      cvShowImage("video",pFrame);

      char c=cvWaitKey(33);

      if(c==27)break;

  }

  cvReleaseCapture(&pCapture);

  cvDestroyWindow("video");

}

6,//編譯

#arm-linux-gcc test.c -o test-arm  -I/opt/arm/opencv/include/opencv -L/opt/arm/opencv/lib -lml -lcvaux -lhighgui -lcv -lcxcore  -lpthread -lrt

分析:

arm-linux-gcc test.c -o test-arm 

-I/opt/arm/opencv/include/opencv

-L/opt/arm/opencv/lib

-lml -lcvaux -lhighgui -lcv -lcxcore  -lpthread -lrt

7,移植到arm,将lib下的*.so.x,重命名後,拷貝到arm下的lib中

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

繼續閱讀