VS2013 OpenCV3.0 TBB IPP 非GPU
发布日期:2021-11-13 20:27:58 浏览次数:2 分类:技术文章

本文共 10682 字,大约阅读时间需要 35 分钟。

OPENCV 3.0.0-BETA ( IPP & TBB ENABLED ) ON YOCTO WITH INTEL® EDISON

There's updated article for OpenCV 3.0.0 with the new Edison Yocto image (ww25)

-> 

< Overview >

 This article is a tutorial for setting up OpenCV 3.0.0-beta on Yocto with Intel® Edison. We will build OpenCV 3.0.0-beta on Edison Breakout/Expansion Board using a Linux host machine and it takes up a lot of space on Edison, therefore, it is required to have at least 2GB micro SD Card as an extended storage for your Edison Breakout/Expansion Board.

 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, gets parallelized with the TBB library. By doing this, we can fully utilize the dual-core of Edison.

1. Prepare the image for your Edison

  prepare your standard ( or customized with additional packages ) Edison image following and . You can use the original image or customize the image with your desired additional packages.

2. Enabling UVC ( USB Video device Class ) by customizing the Linux Kernel ( optinal )

  For those who want to use an USB camera module such as a simple webcam, we need to enable UVC in the Linux Kernel configuration. If you are done building your own image ( if you did 'bitbake edison-image') , now you are ready to customize your Linux Kernel. Type

1    ~/edison-src> bitbake virtual/kernel -c menuconfig

and then find and enable Device Drivers -> Multimedia support -> Media USB Adapters. When configuration is completed, replace defconfig with .config that you just modified. Type

1   ~/edison-src> cp /build/tmp/work/edison-poky-linux/linuxyocto/3.10.17+gitAUTOINC+6ad20f049a_c03195ed6e-r0/linux-edison-standardbuild/.config build/tmp/work/edison-poky-linux/linuxyocto/3.10.17+gitAUTOINC+6ad20f049a_c03195ed6er0/defconfig

Finally, we bitbake again, type

1   ~/edison-src> bitbake virtual/kernel -c configure -f -v
2  
3  
4   ~/edison-src> bitbake edison-image

 

3. Changing Partition ( recommended )

 

 It is recommended to change the original partition option because the partition of the root file system only is originally 512 MB which will be mostly consumed after flasing an image. '/home' takes whatever much space remained after assining specified partitions and it is more than 2GB. Therefore, making those two partitions even which can be about 1.3GB would give your Edison more flexibility to do more work after flashing.

 Look into 'edison-src/device-software/meta-edison-distro/recipes-bsp/u-boot/files/edison.env' file (for the new source release ww05, it is 'edison-src/device-software/meta-edison/recipes-bsp/u-boot/files/edison.env'), change Rootfs’ size from 512MB to 1312MB. As results, /home size will shrink automatically. One more change needs to be made before we flash the image again. The second part of this is the rootfs image size itself, which is set in the 'edison-src/device-software/meta-edison-distro/recipes-core/images/edison-image.bb' and is also 512MB. Change the size of rootfs again then re-build the image again, by typing 'bitbake edison-image' .

 After 'bitbake' is done, type

1  ~/edison-src> /device-software/utils/flash/postBuild.sh

 and check if you have 'dfu-util'. If you do not , then install it by typing

1  ~/edison-src> sudo apt-get install dfu-util

now we need to flash twice to apply the new partition settings. First complete

1  ~/edison-src> /build/toFlash/flashall.sh --recovery

and then complete flashing without '--recovery' ,

1 ~/edison-src> /build/toFlash/flashall.sh

After your Edison boots up successfully, connect a USB cable to Edison's serial terminal port. Check what number of USB device your Edison gets detected on your host Linux and connect Edison through 'screen' ( put the corresponding number instead of 'X' ex) ttyUSBX -> ttyUSB0 )

1 sudo screen /dev/ttyUSBX 115200

If you see your Edison successfully boots up , login as 'root' and check the space by typing

1  root@edison:~# df -h

 

4. Setup root password and WiFi for ssh and FTP

 

 After your host Linux is connected with Edison through the serial port, type

1  root@edison:~# configure_edison --setup

 and follow the instruction, you will have no trouble setting up your password and WiFi. If you use no password account, 'ssh' may refuse access requiests from outside of Edison.

Connect your host Linux machine and your Edison to the same wireless access point and enable FTP using any FTP program or command as you want.

5. Install CMake

 

 Edison image does not come with 'cmake' and we need it to build OpenCV. Therefore we need to manually install it. One of many ways to do it, it is fairly recommended to use 'opkg'. There is a repository established by one of the users out there, which can be refered through .

 In the link, AlexT instroduces a way to connect his repo through 'opkg'. To configure your Edison to fetch packages from the repo, replace anything you have in /etc/opkg/base-feeds.conf with the following (other opkg config files don't need any changes):

===/etc/opkg/base-feeds.conf contents below===
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32

===end of /etc/opkg/base-feeds.conf contents===

Now type 'opkg update' and

you should see the below output, which means you're successfully communicating with the repo:

01 root@edison:~# opkg update
02 Downloading 
03 Inflating 
04 Updated list of available packages in /var/lib/opkg/all.
05 Downloading 
06 Inflating 
07 Updated list of available packages in /var/lib/opkg/edison.
08 Downloading 
09 Inflating 
10 Updated list of available packages in /var/lib/opkg/core2-32.

Now you are ready to install CMake, type

1 root@edison:~# opkg install cmake-dev

 try 'cmake' if you can see the help page of it.

 

6. OpenCV 3.0.0-beta

 

 Before we jump in to OpenCV, we need a plenty of space for building OpenCV on Edison. Therefore, it is required to have an external storage such as a micro SD Card. We will format the micro SD Card and will mount it on Edison.

 Insert the card to your Linux host machine and type ( block_device ex-> /dev/mmcblk1 )

1  > mkfs.ext4 block_device

or

1   > mke4fs -t ext4 block_device

 now we lable the partition using

1   > e4label <block_device> new_label

 insert the SD Card to your Edison and mount it.

1  root@edison:~# mkdir <Desired DIR>
1  root@edison:~# mount block_device <Desired DIR >

check if it is mounted without problem by typing 'df -h'

  For the future use, it is convinient that you configure 'auto mount'. Add '/dev/block_device <Desired DIR> ' to /etc/fstab . For example type

1  root@edison:~# vi /etc/fstab

and add '/dev/mmcblk1  /home/ext'

  Go to  and download OpenCV for Linux 3.0 BETA on your host Linux machine. When download is done, copy the zip file to your Edison through FTP. It is recommended to use the external SD card space for OpenCV. When it is built, it uses up more than 1 GB.

 Unzip the downloaded file by typing 'unzip opencv-3.0.0-beta.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 will be downloaded automatically when the flag is turned on but unfortunately, the library for TBB needs to be installed manually. Therefore, install TBB package on your host machine and copy the corresponding files to Edison. If your host Linux is 64bit you need to specify i386 when apt-get it. On your host machine, type

1 sudo apt-get install libtbb-dev:i386

 and copy all files in /usr/include/tbb to Edison's same named folder, and /usr/lib/libtbb.so, /usr/lib/libtbbmalloc.so, /usr/lib/libtbbmalloc_proxy.so, and /usr/lib/pkgconfig/tbb.pc need to be copied to Edison also. Please refer  to see the full file list of tbb library.

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

1  root@edison:<OpenCV DIR># cmake -D WITH_IPP=ON -D WITH_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

1 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.

1 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

1 root@edison:<OpenCV DIR># make install

 

7. Making applications with OpenCV 3.0.0-beta

 

 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

1  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

1  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.

1 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.

转载地址:https://blog.csdn.net/lphbtm/article/details/50953389 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:OpenCV300 CMake生成工程项目过程中的问题
下一篇:MATLAB图像处理工具箱

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月06日 11时23分02秒