Quantcast
Channel: Intel Developer Zone Articles
Viewing all articles
Browse latest Browse all 3384

OpenCV 3.0.0 ( IPP & TBB enabled ) on Yocto with Intel® Edison with new Yocto image release

$
0
0

For OpenCV 3.0.0 - Beta , please see this article

The following article is for OpenCV 3.0.0 and Intel(R) Edison with the latest (ww25) Yocto Image.

< Overview >

 This article is a tutorial for setting up OpenCV 3.0.0 on Yocto with Intel® Edison. We will build OpenCV 3.0.0 on Edison Breakout/Expansion Board using a Windows/Linux host machine.

 In this article, we will enable Intel® Integrated Performance Primitives ( IPP ) and Intel® Threading Building Blocks ( TBB ) to optimize and parallelize some OpenCV functions. For example, cvHaarDetectObjects(...) , an OpenCV function that detects objects of different sizes in the input image, is parallelized with the TBB library. By doing this, we can fully utilize the dual-core of Edison.

1. Prepare the new Yocto image for your Edison

   Go to Intel(R) Edison downloads and download 'Release 2.1 Yocto* complete image' and 'Flash Tool Lite' that matches your OS. Then refer Flash Tool Lite User Manual for Edison to flash the new image. Using this new release, you don't need to manually enable UVC for Webcams and will have enough storage space for OpenCV 3.0.0. Additionally, CMake is already included. To enable UVC by customizing the Linux Kernel and change partition setting for different space configuration, refer the past article's step 2 and 3. 

2. Setup root password and WiFi for ssh and FTP

  Follow Edison Getting Started to connect your host and Edison as you want.

  Setup any FTP method for transferring files from your host to your Edison. ( For an easy file transfer, MobaXterm is recommended for Windows hosts )

3. OpenCV 3.0.0

 When you check your space with 'df -h', you will see a very similar result with the following. 

  Go to OpenCV Official Page and download OpenCV on your host machine. When download is done, copy the zip file to your Edison through FTP. It is recommended to copy the OpenCV to '/home/<User>' and work it out there. Since '/home' has more than 1G.

 Unzip the downloaded file by typing 'unzip opencv-3.0.0.zip' and check if your opencv folder is created.

 go to <OpenCV DIR> and type 'cmake .' and take a look what kind of options are there.

 We will enable IPP and TBB for better performance. The library to enable IPP and TBB will be downloaded automatically when the flag is turned on. 

 Now, on Edison, go to <OpenCV DIR> and type ( do not forget '.' at the end of the command line )

 root@edison:<OpenCV DIR># cmake -D WITH_IPP=ON -D WITH_TBB=ON -D BUILD_TBB=ON -D WITH_CUDA=OFF -D WITH_OPENCL=OFF -D BUILD_SHARED_LIBS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF .

 which turns on IPP & TBB flags and turns off irrelevant features to make it simple. With 'BUILD_SHARED_LIBS=OFF' , your Edison will make the executables able to run without OpenCV installed in case of distribution. ( If you don't want IPP & TBB, go with WITH_TBB=OFF and WITH_IPP=OFF )

 In the configuration result, you should see IPP and TBB are enabled.

If you observe no problems, then type

 root@edison:<OpenCV DIR># make -j2

 It will take a while to complete the building. ( 30mins ~ 1hour )

 If you encounter 'undefined reference to symbol 'v4l2_munmap' ... libv4l2.so.0 : error adding symbols: DSO missing from command line' error while building OpenCV or OpenCV samples later, we need to add ‘-lv4l2’ after ‘-lv4l1’ in the corresponding configuration files. This error could happen for more than 50+ files so it’s better to add them all with a line of command instead.

root@edison:<OpenCV DIR># grep -rl -- -lv4l1 samples/* modules/* | xargs sed -i ‘s/-lv4l1/-lv4l1 -lv4l2/g’

 

 When building is done, install what is made by typing

 root@edison:<OpenCV DIR># make install

 

4. Making applications with OpenCV 3.0.0

 

 The easiest way to make a simple OpenCV application is using the sample came along with the package. Go to '<OpenCV DIR>/samples' and type

 root@edison:<OpenCV DIR>/samples# cmake .

 then it will configure and get ready to compile and link the samples. Now you can replace one of the sample code file in 'samples/cpp' and build it using cmake. For example, we can replace 'facedetect.cpp'  with our own code. Now at '<OpenCV DIR>/samples' type

 root@edison:<OpenCV DIR>/samples# make example_facedetect

 then it will automatically get the building done and output file will be placed in 'samples/cpp'

If you encounter 'undefined reference to symbol 'v4l2_munmap' ... libv4l2.so.0 : error adding symbols: DSO missing from command line' error while building OpenCV or OpenCV samples later, we need to add ‘-lv4l2’ after ‘-lv4l1’ in the corresponding configuration files. This error could happen for more than 50+ files so it’s better to add them all with a line of command instead.

root@edison:<OpenCV DIR># grep -rl -- -lv4l1 samples/* modules/* | xargs sed -i ‘s/-lv4l1/-lv4l1 -lv4l2/g’

 

One more thing, since Edison does not have a video out, an error will occur as you call functions related to 'display on the screen' such as 'imshow' which creates and displays an image or a video on the screen. Therefore, before you build samples or examples that include those functions, you need to comment them out. 

 

 

 

 


Viewing all articles
Browse latest Browse all 3384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>