{"id":18,"date":"2019-11-10T10:55:42","date_gmt":"2019-11-10T10:55:42","guid":{"rendered":"http:\/\/blog.edgesmart.co.uk\/?p=18"},"modified":"2020-07-06T22:52:32","modified_gmt":"2020-07-06T21:52:32","slug":"cross-compiling-opencv-for-xilinx-zynq-arm-on-ubuntu-linux-os","status":"publish","type":"post","link":"https:\/\/blog.edgesmart.co.uk\/index.php\/2019\/11\/10\/cross-compiling-opencv-for-xilinx-zynq-arm-on-ubuntu-linux-os\/","title":{"rendered":"Cross Compiling OpenCV for Xilinx Zynq Arm on Ubuntu Linux OS"},"content":{"rendered":"\n<p>I am writing this to keep a log for myself and others whenever I want to cross compile OpenCV for Xilinx Zynq &#8211; ARM platform for Ubuntu 14.04. I have followed instructions mentioned on <a href=\"http:\/\/www.wiki.xilinx.com\/OpenCV+Installation\">Xilinx-Wiki<\/a>&nbsp;however I had to tweak quite a few&nbsp;instructions for me at a few places in order to successfully compile OpenCV. I have chosen to download and compile OpenCV-2.4.9 in particular. I did this a while ago so the Xilinx Vivado tools are older versions Vivado 2014.4. I have not tried on other versions of Ubuntu and OpenCV but I think it should still work. I have not listed any OS level dependencies that is required before attempting to start cross compiling&nbsp;OpenCV for Xilinx Zynq. The prerequisite is that the Xilinx Vivado tools have been installed correctly in Ubuntu \/opt\/Xilinx\/ directory and can be invoked from Linux shell prompt. The following are my&nbsp;compilation of&nbsp;the instructions:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>First install Xilinx Vivado Tools successfully without any problems in \/opt\/Xilinx\/Vivado folder.<\/li><li>Create a text file (env_opencv_xilinx) with the following environment variables to be sourced so that the Vivado tools are available on command line:<\/li><li>export CROSS_COMPILE=arm-xilinx-linux-gnueabi-<br>source \/opt\/Xilinx\/Vivado\/2014.4\/settings64.sh<\/li><li>Source env_opencv_xilinx file<\/li><li>Download OpenCV-2.4.9 from&nbsp;<a href=\"http:\/\/opencv.org\/downloads.html\">http:\/\/opencv.org\/downloads.html<\/a><\/li><li>Unzip and untar OpenCV and place it in \/home\/user\/opencv-2.4.9 folder<\/li><li>Download&nbsp;ffmpeg-2.8.10 from&nbsp;<a href=\"http:\/\/www.ffmpeg.org\/download.html#releases\">http:\/\/www.ffmpeg.org\/download.html#releases<\/a><\/li><li>Unzip and untar FFmpeg folder. I chose to move the ffmpeg-2.8.10 folder inside the opencv-2.4.9 folder.<\/li><li>Change directory inside the ffmpeg-2.8.10 folder<\/li><li>Run: .\/configure &#8211;enable-shared &#8211;disable-static &#8211;cross-prefix=arm-xilinx-linux-gnueabi- &#8211;arch=armv7l &#8211;target-os=linux &#8211;prefix=\/home\/user\/opencv-2.4.9_arm\/ffmpeg-2.8.10\/<\/li><li>Add the following paths in the env_opencv_xilinx and source it again:<\/li><li>export LD_LIBRARY_PATH=\/home\/user\/opencv-2.4.9_arm\/ffmpeg-2.8.10\/lib:${LD_LIBRARY_PATH}<br>export C_INCLUDE_PATH=\/home\/user\/opencv-2.4.9_arm\/ffmpeg-2.8.10\/include:${C_INCLUDE_PATH}<br>export CPLUS_INCLUDE_PATH=\/home\/user\/opencv-2.4.9_arm\/ffmpeg-2.8.10\/include:${CPLUS_INCLUDE_PATH}<br>export PKG_CONFIG_PATH=\/home\/user\/opencv-2.4.9_arm\/ffmpeg-2.8.10\/lib\/pkgconfig:${PKG_CONFIG_PATH}<\/li><li>Create a folder called build within the opencv-2.4.9 directory.<\/li><li>Add the following lines in a text file called&nbsp;toolchain.make and place it in the \/home\/user\/opencv-2.4.9\/ folder:<\/li><li>set( CMAKE_SYSTEM_NAME Linux )<br>set( CMAKE_SYSTEM_PROCESSOR arm )<br>set( CMAKE_C_COMPILER arm-xilinx-linux-gnueabi-gcc )<br>set( CMAKE_CXX_COMPILER arm-xilinx-linux-gnueabi-g++ )<br>set( CMAKE_INSTALL_PREFIX \/home\/user\/opencv-2.4.9_arm\/build )<br>set( CMAKE_FIND_ROOT_PATH \/opt\/Xilinx\/SDK\/2014.4\/gnu\/arm\/lin\/arm-xilinx-linux-gnueabi )<\/li><li>Copy all the generated SO library files from ffmpeg-2.8.10\/lib\/ folder to opencv-2.4.9\/build\/lib folder otherwise OpenCV build process may not find the FFmpeg libraries automatically.<\/li><li>Change directory into the build folder.<\/li><li>I have chosen to set the BUILD_opencv_nonfree=ON as I would like to explore the algorithms available in the non-free of OpenCV.<\/li><li>Run: cmake -D CMAKE_TOOLCHAIN_FILE=toolchain.make -D BUILD_opencv_nonfree=ON \/home\/user\/opencv-2.4.9_arm\/<\/li><li>Check the configuration information of OpenCV to confirm the FFmpeg library is detected.<\/li><li>Customise Build options by running: ccmake .<\/li><li>I have chosen to keep&nbsp;WITH_JPEG and WITH_PNG set to ON so that the applications can read and write JPEG and PNG format image files, however Xilinx recommends the following options to be set to OFF<\/li><li>WITH_1394,&nbsp;WITH_CUDA,&nbsp;WITH_CUFFT,&nbsp;WITH_EIGEN,&nbsp;WITH_GSTREAMER,&nbsp;WITH_GTK,&nbsp;WITH_JASPER,&nbsp;WITH_OPENEXR,&nbsp;WITH_PVAPI,&nbsp;WITH_QT,&nbsp;WITH_TBB,&nbsp;WITH_TIFF,&nbsp;WITH_UNICAP,&nbsp;WITH_V4L,&nbsp;WITH_XINE<\/li><li>First press &#8216;c&#8217; then &#8216;g&#8217; to generate new Makefile.&nbsp;Alternatively&nbsp;edit CMakeCache.txt to modify build options. Check that&nbsp;WITH_FFMPEG=ON in CMakeCache.txt to enable FFmpeg support.<\/li><li>Run: make<\/li><li>Copy and Save build\/lib\/libopencv_core.so.2.4.9 in a different folder than lib.<\/li><li>Run: make install .If all goes well then there will not be any errors however I did get an error here saying libopencv_core.so.2.4.9 not found, flagged by the module\/core\/cmake_install.cmake script. I checked that this particular SO was generated however during the make install process, due to may be some incorrectly generated command in some script it gets removed. I did not have time to debug this in detail however I fond a work around to complete the installation.<\/li><li>Edit build\/modules\/core\/cmake_install.cmake and remove the following lines, this will not generate the error during &#8220;make install&#8221; and the installation should now&nbsp;complete:<\/li><li>&#8220;FILE(INSTALL DESTINATION &#8220;${CMAKE_INSTALL_PREFIX}\/lib&#8221; TYPE SHARED_LIBRARY FILES<br>&#8220;\/home\/jj901099\/opencv-2.4.9_arm\/build\/lib\/libopencv_core.so.2.4.9&#8221;<br>&#8220;\/home\/jj901099\/opencv-2.4.9_arm\/build\/lib\/libopencv_core.so.2.4&#8221;<br>&#8220;\/home\/jj901099\/opencv-2.4.9_arm\/build\/lib\/libopencv_core.so&#8221;<br>)&#8221;<\/li><li>Copy the saved libopencv_core.2.4.9 back to the build\/lib\/ folder. That&#8217;s it.<\/li><\/ol>\n\n\n\n<p>If I have not missed any step then Opencv-2.4.9 should have now compiled in the opencv-2.4.9\/build directory, enjoy image processing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am writing this to keep a log for myself and others whenever I want to cross compile OpenCV for Xilinx Zynq &#8211; ARM platform for Ubuntu 14.04. I have followed instructions mentioned on Xilinx-Wiki&nbsp;however I had to tweak quite a few&nbsp;instructions for me at a few places in order to successfully compile OpenCV. I &hellip;<br \/><a href=\"https:\/\/blog.edgesmart.co.uk\/index.php\/2019\/11\/10\/cross-compiling-opencv-for-xilinx-zynq-arm-on-ubuntu-linux-os\/\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">Cross Compiling OpenCV for Xilinx Zynq Arm on Ubuntu Linux OS<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,26,23,48,25],"tags":[34,9,29,31,30,28,32],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-cross-compilation","category-linux","category-opencv","category-ubuntu","category-zynq","tag-cross-compilation","tag-fpga","tag-opencv","tag-opencv-for-linux","tag-opencv-for-zynq","tag-xilinx-zynq","tag-zynq"],"_links":{"self":[{"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":1,"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":19,"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/18\/revisions\/19"}],"wp:attachment":[{"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.edgesmart.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}