1. Make sure Ubuntu has access to the Internet
2. Installing CMake
Code: Select All
sudo apt-get install Cmake-gui
3. Download the opencv2.4.9 Linux version of the source code, do not use the latest 3.0.0
Http://opencv.org/downloads.html
4. Decompression OpenCV Source code
Code: Select All
Unzip Opencv-2.4.9.zip
5. Create a build directory for compilation and an output directory to hold the OpenCV of the Silo platform after the compilation is completed:
Code: Select All
xlab@xlab-dev:~/zhouhua/opencv/opencv-2.4.9$ ls
3rdparty LICENSE apps data include modules samples
CMakeLists.txt readme.md CMake Doc Index.rst Platforms
xlab@xlab-dev:~/zhouhua/opencv/opencv-2.4.9$ CD.
xlab@xlab-dev:~/zhouhua/opencv$ ls
Build opencv-2.4.9 opencv-2.4.9.zip Output
xlab@xlab-dev:~/zhouhua/opencv$ mkdir Build
xlab@xlab-dev:~/zhouhua/opencv$ mkdir Output
6. Executive Cmake-gui
Code: Select All
xlab@xlab-dev:~/zhouhua/opencv/opencv-2.4.9$ Cmake-gui
Click Browse Source to select ~/zhouhua/opencv/opencv-2.4.9
Click Browse Build to select ~/zhouhua/opencv/build
Then click Configure
The dialog box that appears now selects the last item: Specify options for Cross-compiling
Next
Operating System Fill Arm-hisiv100nptl-linux
C Fill in ARM-HISIV100NPTL-LINUX-GCC
C + + Fill arm-hisiv100nptl-linux-g++
Next, and then wait for configuration done
Then, in the list that appears, modify Cmake_install_prefix to ~/zhouhua/opencv/output
Then click Generate
Wait generation done
You can turn off the CMake software.
7. Go to the build directory to execute make
Code: Select All
xlab@xlab-dev:~/zhouhua/opencv/build$ make
Prompt error:
Code: Select All
.. /.. /lib/libopencv_core.so:undefined reference to ' pthread_once '
.. /.. /lib/libopencv_core.so:undefined reference to ' Pthread_spin_lock '
.. /.. /lib/libopencv_core.so:undefined reference to ' Pthread_spin_unlock '
.. /.. /lib/libopencv_core.so:undefined reference to ' Pthread_spin_init '
.. /.. /lib/libopencv_core.so:undefined reference to ' Pthread_spin_trylock '
.. /.. /lib/libopencv_core.so:undefined reference to ' Pthread_spin_destroy '
Modify CMakeCache.txt at approximately 200 lines
Flags used by the linker.
cmake_exe_linker_flags:string=-LPTHREAD-LRT
Continue make
The following error may occur
Code: Select All
CMake Error at/home/xlab/zhouhua/opencv/opencv-2.4.9/cmake/cl2cpp.cmake:50 (String):
String does not recognize Sub-command MD5
MAKE[2]: * * * [modules/ocl/opencl_kernels.cpp] Error 1
MAKE[1]: * * * [Modules/ocl/cmakefiles/opencv_ocl.dir/all] Error 2
Make: * * * [ALL] Error 2
Delete the contents of line 50th of/home/xlab/zhouhua/opencv/opencv-2.4.9/cmake/cl2cpp.cmake.
Continue make
Execute make install after completion
Code: Select All
xlab@xlab-dev:~/zhouhua/opencv/output$ ls
LICENSE bin include Lib share
8. Get the Include and LIB directories to write programs, to try the most commonly used vehicle detection bar
Write the following code
Code: Select All[CPP] View plain copy #include "cv.h" #include "highgui.h" #include "stdio.h" /********** fortime mesurement*************************/ #include <sys/time.h> structtimeval tpstart,tpend; unsigned longtimeuses; VoidtimeRec () { gettimeofday (&tpstart,0); } Int timeRep () { gettimeofday (&tpend,0); Timeuses= (tpend.tv_sec-tpstart.tv_sec) *1000000+tpend.tv_usec-tpstart.tv_usec; printf ("use time:%uus\n", timeuses); return timeuses; } /********************end**************************************/ Int main ( Intargc, char* argv[]) { iplimage* img= null; cvmemstorage* storage =cvcreatememstorage (0); Cvhaarclassifiercascade*cascade = cvloadhaarclassifiercascade ("./model.xml", CvSize (24,24)); //cvhaarclassifiercascade* cascade = (cvhaarclassifiercascade*) cvLoad ("./ Lbpcascade_frontalface.xml ", 0,0, 0); CvSeq* faces; //Loading Images img = cvloadimage (argv[1], 0); printf ("img w=%d h=%d\n", Img->width, img->height); //detection and Timing timerec (); faces = cvhaardetectobjects (Img,cascade, storage, 1.1, 3, 0, Cvsize (24,24) ); timerep (); if (Faces->total == 0) { printf ("no face!\n "); } printf (" car= %d\n ", faces->total) ; //free Memory cvreleaseimage (&img); printf ("car detected! car.jpg!\n"); }
For convenience, copy the library and header files directly to the compiler directory.
Code: Select All
xlab@xlab-dev:~/zhouhua/opencv/mytest$ sudo cp. /output/lib/*/opt/hisi-linux-nptl/arm-hisiv100-linux/arm-hisiv100-linux-uclibcgnueabi/lib/
Xlab@xlab-dev:~/zhouhua/opencv/mytest$sudo CP. /output/include/*/opt/hisi-linux-nptl/arm-hisiv100-linux/arm-hisiv100-linux-uclibcgnueabi/include/-R
Then compile: (because the version is relatively high, the OPENCV2 header file is used, so an additional-I parameter is required to specify the header file directory)
Code: Select All
arm-hisiv100nptl-linux-g++ face.cpp-i/home/xlab/zhouhua/opencv/output/include/opencv-lopencv_highgui-lopencv_ Core-lopencv_imgproc-lpthread-lrt-lopencv_objdetect-o face
Will prompt some warning, no tube.
Compile successfully and then copy the vehicle classifier file over.
Look for another picture, I'll use car.jpg here.
Libopencv_imgproc.so, libopencv_objdetect.so, libopencv_highgui.so, and libopencv_ under the/root/jiang/opencv/output/lib The core.so is copied to the U-disk and the 4 dynamic libraries in the U disk are made into a soft connection library to the/lib directory.
Code: Select All
Ln-s/mnt/udisk/libopencv_imgproc.so/lib/libopencv_imgproc.so
Ln-s/mnt/udisk/libopencv_objdetect.so/lib/libopencv_objdetect.so
Ln-s/mnt/udisk/libopencv_highgui.so/lib/libopencv_highgui.so
Ln-s/mnt/udisk/libopencv_core.so/lib/libopencv_core.so
Note:
To delete a soft link:
rm-rf/lib/libopencv_core.so Note not rm-rf/lib/libopencv_core.so/.
Then go to the/mnt/udisk directory where the car is located to execute:
#./car car.jpg
IMG w=686h=398
Use Time:18323188us
Car = 5
cardetected! In car.jpg!