1:系统环境搭建
要准备好交叉编译环境 见http://blog.csdn.net/xiabodan/article/details/22717175
2:下载cmake
CmakeLists.txt。Cmake 并不直接建构出最终的软件,而是产生标准的建构档(如 Unix 的 Makefile 或 Windows Visual C++ 的 projects/workspaces),然后再依一般的建构方式使用。这使得熟悉某个集成开发环境(IDE)的开发者可以用标准的方式建构他的软件,这种可以使用各平台的原生建构系统的能力是
CMake 和 SCons 等其他类似系统的区别之处。
3:下载opencv原码
官方:http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/
我的:http://download.csdn.net/detail/xiabodan/7176253
解压 tar -xvjf Opencv-2.3.1.tar.bz2 -C ./
4:配置cmake
gedit toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-g++)
set(CMAKE_FIND_ROOT_PATH /linux/OpenCV/OpenCV-2.3.1/build/)
接下来生成makefile文件
cmake -D CMAKE_TOOLCHAIN_FILE=toolchain.cmake -D CMAKE_INSTALL_PREFIX=/linux/OpenCV/OpenCV-2.3.1/install ../
接着再ccmake ./进行配置,配置的内容是所有的以WITH开头的选项全部选成OFF,(除了WITH_V4L 选为ON)因为这些需要第三方库支持的,要是选择这些的话就需要安装第三方库了。按c配置,按g生成并保存
ccmake /linux/OpenCv/.....
5:Opencv 编译与安装
安装记录1:
ubuntu首次安装,也就是干净纯系统只是安装了 apt-get install cmake cmake-curses-gui 然后直接是 cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake ./
ccmake ./没有关闭任何配置选项
成功编译OPENCV2.4.3 ------------- 100%
安装记录2:
然后试着安装
apt-get install
build-essential
libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev
libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
编译报错:关掉FFMPEG IEEE1394,V4l1同样报错,总结:应该是我安装了各种库后就不能用opencv里面的库,所以要关闭OPENCV自带的选项,而用我们刚才安装的库来编译
安装记录3:
安装记录4:OPencv-2.4.9
查看信息,得到如下信息:
file
libopencv_calib3d.so.2.3.1libopencv_calib3d.so.2.3.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xb0d34a38b76b0bbe88511635df3bde46c281bb56, not stripped
6:移植
cp * -a /media/16c3144a-3f71-434e-8bac-eecefae50d4c/usr/local/share/
cp * -a /media/16c3144a-3f71-434e-8bac-eecefae50d4c/usr/local/bin/
cp * -a /media/16c3144a-3f71-434e-8bac-eecefae50d4c/usr/local/lib/
cp * -a /media/16c3144a-3f71-434e-8bac-eecefae50d4c/usr/local/include/
cp edge_detection.o edge_detection_arm /media/16c3144a-3f71-434e-8bac-eecefae50d4c/
7:安装依赖库
sudo apt-get install libjpeg-dev build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
apt-get install libtiff4-dev ffmpeg
8:编译源文件
arm-xilinx-linux-gnueabi-g++ -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann ./edge_detection.cpp -o ./opencv_test_arm.o
9:在zedboard中运行
./edge_detection_arm.o ./lena.bmp ./lena_edge.bmp
运行成功后就会在当前目录下生成一个lena_edge.bmp的图像