{"id":49,"date":"2016-04-03T02:33:51","date_gmt":"2016-04-03T06:33:51","guid":{"rendered":"http:\/\/blogs.nd.edu\/tianchen-wang\/?p=49"},"modified":"2016-05-19T02:39:31","modified_gmt":"2016-05-19T06:39:31","slug":"setup-eclipse-cdt-c-with-opencv-3-1-in-ubuntu-14-04","status":"publish","type":"post","link":"https:\/\/sites.nd.edu\/tianchen-wang\/2016\/04\/setup-eclipse-cdt-c-with-opencv-3-1-in-ubuntu-14-04\/","title":{"rendered":"Build Debug Environment of OpenCV 3.1 C++ with Eclipse in Ubuntu"},"content":{"rendered":"<p>To build the debug environment, the first part is to set up OpenCV.<\/p>\n<ol>\n<li>Download the latest version of OpenCV 3.x from<br \/>\n<strong>http:\/\/sourceforge.net\/projects\/opencvlibrary<\/strong><br \/>\nThen unzip it to certain folder, say \/home\/tc\/Documents<\/li>\n<li>Update and upgrade Ubuntu for the preparation installation, and required packages\n<ul>\n<li><strong>sudo apt-get update<\/strong><\/li>\n<li><strong>sudo apt-get upgrade<\/strong><\/li>\n<li><strong>sudo 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 libeigen3-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 default-jdk ant libvtk5-qt4-dev<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>In terminal, browse to the unzipped folder, make a new release folder and generate the Makefile from cmake. Then make install.\n<ul>\n<li><strong>cd \/opencv-x.x.x<\/strong><\/li>\n<li><strong>mkdir release<\/strong><\/li>\n<li><strong>cd release<\/strong><\/li>\n<li><strong>cmake -DWITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..<\/strong><\/li>\n<li><strong>sudo make<\/strong><\/li>\n<li><strong>sudo make install<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>If all is well without any error message, continue to step 5. Otherwise, install required package and start from cmake again.<\/li>\n<li>Edit OpenCV configuration file with appending\u00a0the following line to the opencv.conf file:\n<ul>\n<li><strong>sudo gedit \/etc\/ld.so.conf.d\/opencv.conf<\/strong><\/li>\n<li>add \u00a0\u00a0<strong>\/usr\/local\/lib<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>Then add the pkgconfig OpenCV path to .\/bashrc file for final environment setup\n<ul>\n<li><strong>sudo ldconfig<\/strong><\/li>\n<li><strong>sudo gedit \/etc\/bash.bashrc<\/strong><\/li>\n<li>add \u00a0<strong>PKG_CONFIG_PATH=$PKG_CONFIG_PATH:\/usr\/local\/lib\/pkgconfig<\/strong><\/li>\n<li>add \u00a0<strong>export PKG_CONFIG_PATH<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>After this, the OpenCV is successfully set up in Ubuntu. The next part is go for Eclipse C++ installation with library include configuration.<\/p>\n<ol>\n<li>Install latest Eclipse with cdt and C++ package on ubuntu\n<ul>\n<li><strong>sudo apt-get install eclipse eclipse-cdt g++<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>Open Eclipse, and start a new C++ Project by choosing <strong>&#8216;Empty Project&#8217;<\/strong> with Toolchains <strong>&#8216;Cross GCC&#8217;<\/strong>. Fill a name you like, say &#8216;testopenCV&#8217;.\u00a0Create a new C++ flie with &#8216;cpp&#8217; extension, say &#8216;src.cpp&#8217;.<\/li>\n<li>Add external OpenCV properties to the project. To find the location of OpenCV and its libraries, type:\n<ul>\n<li><strong>pkg-config \u00a0&#8211; -cflags opencv<\/strong><\/li>\n<li><strong>pkg-config \u00a0&#8211; -libs opencv<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>Normally, the OpenCV installation folder is &#8216;\/usr\/local\/include\/opencv&#8217; and its library folder is &#8216;\/usr\/local\/lib&#8217;. To add them in the properties, open the <strong>&#8216;Properties&#8217;\u00a0<\/strong>of the project and go to <strong>&#8216;C\/C++ Build&#8217;<\/strong>, then <strong>&#8216;Setting&#8217;<\/strong>. In <strong>&#8216;Cross GCC Compiler&#8217; &#8211;&gt; &#8216;Includes&#8217; &#8211;&gt; &#8216;Include<\/strong> <strong>paths(l)&#8217;<\/strong>,\u00a0<strong>\u00a0<\/strong>add OpenCV installation folder (\/usr\/local\/include\/opencv).<\/li>\n<li>Go to <strong>&#8216;Cross G++ Compiler&#8217;\u00a0<\/strong><strong>&#8211;&gt; &#8216;Includes&#8217; &#8211;&gt; &#8216;Include paths&#8217;<\/strong>, add the same address (\/usr\/local\/include\/opencv).<\/li>\n<li>The for library, go to <strong>&#8216;Cross G++ Linker&#8217; &#8211;&gt; &#8216;Libraries&#8217; &#8211;&gt; &#8216;Library search path (-L)&#8217;<\/strong>, add library path (\/usr\/local\/lib). Then in <strong>&#8216;Libraries (-l)&#8217;<\/strong>, add libraries names for applying in the search. Normally except the core, all others are optional for specific programs you implement. If other libraries are needed, just add them in.\n<ul>\n<li><strong>opencv_core \u00a0 opencv_imgproc \u00a0 opencv_legacy \u00a0 opencv_contrib \u00a0 opencv_highgui \u00a0 opencv_features2d \u00a0 opencv_flann \u00a0 opencv_video \u00a0 opencv_objdetect \u00a0 opencv_ml \u00a0 opencv_calib3d<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>That&#8217;s it for the new C\/C++ project with OpenCV implementation. If you want to import codes from others and link to OpenCV:\n<ul>\n<li>Go to <strong>&#8216;C\/C++ General&#8217;\u00a0<\/strong>from project properties, then click &#8216;<strong>Paths and Symbols&#8217; &#8211;&gt; &#8216;Includes&#8217;<\/strong><\/li>\n<li>In both\u00a0<strong>&#8216;GNU&#8217;\u00a0<\/strong>and\u00a0<strong>&#8216;GNU C++&#8217;<\/strong>, add the same include folder in the <strong>&#8216;Include directories&#8217;<\/strong>, say &#8216;\/usr\/local\/include\/opencv&#8217;.<\/li>\n<li>In the tab <strong>&#8216;Libraries&#8217;<\/strong>, add all libraries needed one by one, similar in step 6.<\/li>\n<\/ul>\n<\/li>\n<li>Restart Eclipse and enjoy!<\/li>\n<\/ol>\n<p>g++ hello.cpp -o hello`pkg-config &#8211;cflags &#8211;libs opencv`<\/p>\n<p>Reference:\u00a0http:\/\/www.installthetech.com\/blogs\/2016\/2\/28\/linking-eclipse-cdt-with-opencv-249-in-ubuntu-1404<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To build the debug environment, the first part is to set up OpenCV. Download the latest version of OpenCV 3.x from http:\/\/sourceforge.net\/projects\/opencvlibrary Then unzip it to certain folder, say \/home\/tc\/Documents Update and upgrade Ubuntu for the preparation installation, and required packages sudo apt-get update sudo apt-get upgrade sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev [&hellip;]<\/p>\n","protected":false},"author":2075,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52819],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/users\/2075"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":11,"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/posts\/49\/revisions\/71"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.nd.edu\/tianchen-wang\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}