{"id":941,"date":"2018-10-20T21:31:55","date_gmt":"2018-10-21T04:31:55","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=941"},"modified":"2018-10-24T21:13:33","modified_gmt":"2018-10-25T04:13:33","slug":"cross-compiling-opencv-3-for-raspberry-pi-2","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/raspberry\/opencv\/build\/","title":{"rendered":"Cross-compiling OpenCV 3 for Raspberry Pi 2"},"content":{"rendered":"<p>This tutorial shows how to cross-compile the OpenCV library for Raspberry Pi to allow stepping through its source code and searching through it using Find-All-References and Code Map.<\/p>\n<p>Before you begin, download the <a href=\"http:\/\/gnutoolchains.com\/raspberry\/jessie\/\">Latest Raspberry Pi SD card image<\/a> and write it to the SD card. Then get a cross-toolchain compatible with the image from the <a href=\"http:\/\/gnutoolchains.com\/raspberry\/\">gnutoolchains.com<\/a> website. Then download the source code of <a href=\"https:\/\/opencv.org\/releases.html\">OpenCV for Linux<\/a> to your Windows machine and unpack it. Then install VisualGDB 5.4 or later.<\/p>\n<ol>\n<li>Start Visual Studio and select File-&gt;New-&gt;Project. Then pick the VisualGDB Linux Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4311\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-new.png\" alt=\"01-new\" width=\"896\" height=\"611\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-new.png 896w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-new-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-new-130x90.png 130w\" sizes=\"(max-width: 896px) 100vw, 896px\" \/><\/a><\/li>\n<li>Select &#8220;Import a project -&gt; Import a CMake project&#8221;. Ensure you have the &#8220;Use the advanced CMake Project Subsystem&#8221; checkbox checked:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-import1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4312\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-import1.png\" alt=\"02-import\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-import1.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-import1-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Select &#8220;Build the project locally with a cross-compiler&#8221; and choose your Raspberry Pi board in the &#8220;Deployment computer&#8221; field:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-raspi.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4313\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-raspi.png\" alt=\"03-raspi\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-raspi.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-raspi-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Specify the directory where you have unpacked the OpenCV source code\u00a0and click &#8220;Finish&#8221; to import the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-opencv.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4314\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-opencv.png\" alt=\"04-opencv\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-opencv.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-opencv-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>If we build OpenCV now, it will not recognize the GTK+ library and the GUI-related API will not work. To ensure OpenCV builds with GTK+ support, first download <a href=\"https:\/\/sourceforge.net\/projects\/pkgconfiglite\/?source=typ_redirect\">pkg-config-lite for Windows<\/a> and extract the pkg-config.exe executable into the &lt;sysgcc&gt;\\Raspberry\\bin directory:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-pkg-config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4315\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-pkg-config.png\" alt=\"05-pkg-config\" width=\"786\" height=\"593\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-pkg-config.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-pkg-config-300x226.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>Before you can build the code using the\u00a0GTK3 headers and libraries, you need to install the libgtk3.0-dev package on your Raspberry Pi. The easiest way to do this is\u00a0to use the <a href=\"http:\/\/smartty.sysprogs.com\/\">SmarTTY<\/a>&#8216;s<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/libgtk.png\"><br \/>\n<\/a> package installation GUI:<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4316\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/libgtk.png\" alt=\"libgtk\" width=\"969\" height=\"539\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/libgtk.png 969w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/libgtk-300x167.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/libgtk-800x445.png 800w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/><\/li>\n<li>Once you install the libgtk3-dev package, open VisualGDB Project Properties for the recently created project, and resynchronize the toolchain sysroot to ensure that all headers and libraries end are copied to the Windows machine. Ensure that you include the <strong>\/usr\/share\/pkgconfig<\/strong> and <strong>\/opt<\/strong>\u00a0directories:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/sync.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4317\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/sync.png\" alt=\"sync\" width=\"957\" height=\"754\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/sync.png 957w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/sync-300x236.png 300w\" sizes=\"(max-width: 957px) 100vw, 957px\" \/><\/a><\/li>\n<li>Before you can start the build, you need to set the environment variables so that pkg-config knows how to find the information about the packages. Set the following environment variables for the CMake command:\n<pre class=\"\">PKG_CONFIG_LIBDIR=$(ToolchainDir.forwardslashes)\/arm-linux-gnueabihf\/sysroot\/usr\/lib\/arm-linux-gnueabihf\/pkgconfig\r\nPKG_CONFIG_PATH=$(ToolchainDir.forwardslashes)\/arm-linux-gnueabihf\/sysroot\/usr\/lib\/arm-linux-gnueabihf\/pkgconfig;$(ToolchainDir.forwardslashes)\/arm-linux-gnueabihf\/sysroot\/usr\/share\/pkgconfig\r\nPKG_CONFIG_SYSROOT_DIR=$(ToolchainDir.forwardslashes)\/arm-linux-gnueabihf\/sysroot<\/pre>\n<p>Replace &#8220;C:\\SysGCC\\Raspberry&#8221; with your toolchain directory and do not forget to replace the backward slashes (&#8216;\\&#8217;) with forward slashes (&#8216;\/&#8217;):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-libdir.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4318\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-libdir.png\" alt=\"10-libdir\" width=\"1102\" height=\"698\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-libdir.png 1102w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-libdir-300x190.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-libdir-1024x649.png 1024w\" sizes=\"(max-width: 1102px) 100vw, 1102px\" \/><\/a><\/li>\n<li>In order to automatically install the built OpenCV libraries to your Raspberry Pi, set the deployment options as shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10a-deploy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4324\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10a-deploy.png\" alt=\"10a-deploy\" width=\"1103\" height=\"753\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10a-deploy.png 1103w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10a-deploy-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10a-deploy-1024x699.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10a-deploy-130x90.png 130w\" sizes=\"(max-width: 1103px) 100vw, 1103px\" \/><\/a><\/li>\n<li>Once you close the VisualGDB Project Properties, the project will be automatically reloaded. If you were using the Ninja build subsystem, the load may fail as OpenCV doesn&#8217;t support Ninja out-of-the-box:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-cfgerrors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4319\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-cfgerrors.png\" alt=\"06-cfgerrors\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-cfgerrors.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-cfgerrors-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-cfgerrors-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>If this happens, double-check that you are using GNU Make, not Ninja:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/gnumake.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4321\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/gnumake.png\" alt=\"gnumake\" width=\"1075\" height=\"714\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/gnumake.png 1075w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/gnumake-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/gnumake-1024x680.png 1024w\" sizes=\"(max-width: 1075px) 100vw, 1075px\" \/><\/a><\/li>\n<li>If you get errors due to incompatible values cached\u00a0from the previous build, use the :Clean and Reconfigure CMake Project&#8221; command to clear all\u00a0caches:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-reload.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4322\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-reload.png\" alt=\"08-reload\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-reload.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-reload-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-reload-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Once the project is configured, double-check that GTK is found:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/16-gtkfound.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4323\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/16-gtkfound.png\" alt=\"16-gtkfound\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/16-gtkfound.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/16-gtkfound-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/16-gtkfound-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Now we will\u00a0show how to\u00a0use the CMake Script Debugger to diagnose\u00a0problems related to locating GTK. You can trigger an error here by temporarily removing the PKG_CONFIG_PATH variable definition and ensuring that GTK is now not found:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-nogtk1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4326\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-nogtk1.png\" alt=\"09-nogtk\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-nogtk1.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-nogtk1-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-nogtk1-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Right-click on the project in Solution Explorer and select &#8220;Launch CMake Debugger&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-debugcmake.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4327\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-debugcmake.png\" alt=\"11-debugcmake\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-debugcmake.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-debugcmake-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-debugcmake-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>VisualGDB will step into the top-level CMakeLists.txt file. Set a breakpoint on output message:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/12-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4328\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/12-bkpt.png\" alt=\"12-bkpt\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/12-bkpt.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/12-bkpt-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/12-bkpt-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Specify &#8220;gtk-3.0&#8221; as the message filter:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/13-gtk1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4329\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/13-gtk1.png\" alt=\"13-gtk\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/13-gtk1.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/13-gtk1-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/13-gtk1-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Press F5 to continue debugging CMake. Once the build\u00a0logic reaches the gtk checks, the breakpoint will trigger:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/14-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4330\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/14-bkpt.png\" alt=\"14-bkpt\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/14-bkpt.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/14-bkpt-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/14-bkpt-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Step through the check code until you reach the <strong>execute_process()<\/strong> statement (or\u00a0simply set a breakpoint there).\u00a0Check the environment and the pkg-config arguments used by CMake:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/15-stepexec.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4331\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/15-stepexec.png\" alt=\"15-stepexec\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/15-stepexec.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/15-stepexec-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/15-stepexec-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>If the output from pkg-config doesn&#8217;t match your expectations, try running it manually from command prompt:\n<pre class=\"\">set PKG_CONFIG_PATH=&lt;...&gt;\r\nset PKG_CONFIG_SYSROOT_DIR=&lt;...&gt;\r\npkg-config --print-errors --short-errors --exists gtk+-3.0 &amp;&amp; echo found<\/pre>\n<\/li>\n<li>Once you ensure that gtk 3.0 is found, select Solution-&gt;Build Solution to start building OpenCV. The library is relatively big, so the build may take 15 minutes or more. Once the build completes, right-click on the\u00a0project node in Solution Explorer and select &#8220;Install all targets&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/18-install.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4332\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/18-install.png\" alt=\"18-install\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/18-install.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/18-install-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/18-install-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>If you have configured deployment settings\u00a0on the CMake page of VisualGDB Project Properties, VisualGDB will automatically deploy the OpenCV binaries to the correct locations under <strong>\/usr\/local<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/19-uploading.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4333\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/19-uploading.png\" alt=\"19-uploading\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/19-uploading.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/19-uploading-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/19-uploading-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Now we will create a new project based on an OpenCV sample called <strong>findContours_demo<\/strong>.\u00a0Close the solution and start the VisualGDB Linux Project Wizard again:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/20-demo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4334\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/20-demo.png\" alt=\"20-demo\" width=\"842\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/20-demo.png 842w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/20-demo-300x212.png 300w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/a><\/li>\n<li>Select &#8220;New Project&#8221; -&gt; &#8220;Application&#8221; -&gt; &#8220;CMake&#8221;\u00a0and ensure that the advanced Cmake Project\u00a0Subsystem and GNU Make are enabled:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/21-type.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4335\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/21-type.png\" alt=\"21-type\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/21-type.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/21-type-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Select the same cross-toolchain that you used when building OpenCV itself:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/22-cross.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4337\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/22-cross.png\" alt=\"22-cross\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/22-cross.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/22-cross-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to generate the project. Replace the contents of the main .cpp file with the contents of the\u00a0<strong>&lt;OpenCV folder&gt;\\samples\\cpp\\tutorial_code\\ShapeDescriptors\\findContours_demo.cpp<\/strong> file:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/23-copied.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4338\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/23-copied.png\" alt=\"23-copied\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/23-copied.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/23-copied-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/23-copied-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a>Note that as we haven&#8217;t referenced OpenCV from the project yet, it won&#8217;t find the include files and libraries.<\/li>\n<li>Edit the CMakeLists.txt file of the new project as shown below to reference OpenCV:\n<pre class=\"\">find_package(OpenCV REQUIRED)\r\n\r\nocv_include_directories(\"${OpenCV_SOURCE_DIR}\/include\")\r\nocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})\r\n\r\n&lt;...&gt;\r\n\r\ntarget_link_libraries(OpenCVDemo ${OpenCV_LIBS} \"${LIBRARIES_FROM_REFERENCES}\")<\/pre>\n<p>Once you save the\u00a0CMakeLists.txt file,\u00a0CMake will report that the OpenCV package is missing:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/24-error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4339\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/24-error.png\" alt=\"24-error\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/24-error.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/24-error-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/24-error-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Right-click on the project in Solution Explorer and select &#8220;Add-&gt;Add a Prefix Directory&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/25-adddir.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4340\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/25-adddir.png\" alt=\"25-adddir\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/25-adddir.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/25-adddir-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/25-adddir-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Go to the <strong>&lt;OpenCV directory&gt;\\VisualGDB\\Debug<\/strong> folder and pick any file in it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/26-dir.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4341\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/26-dir.png\" alt=\"26-dir\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/26-dir.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/26-dir-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/26-dir-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Now CMake will locate the OpenCV libraries and the configuration will succeed. Build the project via Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/28-built.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4343\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/28-built.png\" alt=\"28-built\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/28-built.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/28-built-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/28-built-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>The prefix directory added in the previous step is stored in the project file itself (not in CMakeLists.txt files) and can be changed via VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/35-prefixdir.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4351\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/35-prefixdir.png\" alt=\"35-prefixdir\" width=\"999\" height=\"626\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/35-prefixdir.png 999w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/35-prefixdir-300x188.png 300w\" sizes=\"(max-width: 999px) 100vw, 999px\" \/><\/a><\/li>\n<li>Now we will run the demo program and step through it. The demo opens an image specified via command line and tries to detect contours on it. To show the program, we will use the Lena image from &lt;OpenCV&gt;\\samples\\wp8\\OpenCVXaml\\OpenCVXaml\\Assets\\Lena.png. First of all, upload it to your Raspberry Pi using SmarTTY. Then specify the path to the image in the command-line arguments of your application:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/29-args.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4344\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/29-args.png\" alt=\"29-args\" width=\"838\" height=\"599\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/29-args.png 838w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/29-args-300x214.png 300w\" sizes=\"(max-width: 838px) 100vw, 838px\" \/><\/a><\/li>\n<li>Press F5 to start debugging. As long as you are\u00a0using VisualGDB 5.4 with the Advanced CMake Project Subsystem, it will automatically discover the locations of the OpenCV libraries on your Windows machine and issue the\u00a0<a href=\"http:\/\/visualgdb.com\/gdbreference\/commands\/set_solib-search-path\">set solib-search-path command<\/a>\u00a0command to GDB so that it can\u00a0load the symbols from them. However the OpenCVDemo project does not\u00a0specify where to find the libraries on the target, hence the first debug session will fail due to missing libraries:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/30-lib.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4345\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/30-lib.png\" alt=\"30-lib\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/30-lib.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/30-lib-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/30-lib-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Locate the missing library on the target (in this tutorial is should be installed\u00a0under \/usr\/local\/lib) and press &#8220;OK&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/31-updated.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4346\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/31-updated.png\" alt=\"31-updated\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/31-updated.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/31-updated-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/31-updated-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Hit F5 again to start another debug session.\u00a0The sample program will start successfully and will run the edge detection algorithm on the image:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/32-picture.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4347\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/32-picture.png\" alt=\"32-picture\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/32-picture.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/32-picture-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/32-picture-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Set a breakpoint inside the thresh_callback() function and move the slider in the left window. The breakpoint will get hit:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/33-canny.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4348\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/33-canny.png\" alt=\"33-canny\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/33-canny.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/33-canny-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/33-canny-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>You should be able to step into the Canny() function by pressing F11 (you would need to do it several times to step out of several implicit constructors), however\u00a0as we have imported OpenCV as a package, IntelliSense won&#8217;t know\u00a0where to find its source files and will only find references\u00a0to various OpenCV functions inside the demo project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/34-refs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4350\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/34-refs.png\" alt=\"34-refs\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/34-refs.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/34-refs-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/34-refs-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>There are 2 ways to\u00a0make\u00a0the OpenCV sources available to IntelliSense while developing the demo project:\n<ol style=\"list-style-type: lower-alpha;\">\n<li>We could import it using CMake logic using the\u00a0<strong>add_subdirectory()<\/strong> command. This would import all OpenCV targets into the current project, greatly increasing the build time.<\/li>\n<li>We could also add the original VisualGDB project\u00a0created earlier in this tutorial to the solution and\u00a0configure Visual Studio to\u00a0not build it. This will make all sources available to IntelliSense and will note increase the build time, as the OpenCV targets will not be rechecked unless you explicitly build the OpenCV project.<\/li>\n<\/ol>\n<\/li>\n<li>Right-click in the solution element in Solution Explorer and select &#8220;Add-&gt;Existing Project&#8221;. Then pick the .vgdbcmake file\u00a0corresponding to the imported OpenCV project. VisualGDB will add it side-by-side with the demo project (OpenCVDemo):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/2proj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4352\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/2proj.png\" alt=\"2proj\" width=\"957\" height=\"754\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/2proj.png 957w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/2proj-300x236.png 300w\" sizes=\"(max-width: 957px) 100vw, 957px\" \/><\/a>Note that each\u00a0CMake project (i.e. both OpenCV and OpenCVDemo) can contain multiple targets.\u00a0The\u00a0Solution Explorer nodes with the CMake icon correspond to\u00a0CMake projects and subprojects, while\u00a0nodes with the console icon correspond to specific\u00a0executables built by each project.<\/li>\n<li>Use the Visual Studio&#8217;s configuration manager to disable building of the OpenCV project and only build OpenCVDemo:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/37-existingprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4353\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/37-existingprj.png\" alt=\"37-existingprj\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/37-existingprj.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/37-existingprj-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/37-existingprj-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<li>Now IntelliSense will be able to index all the source files in both the sample project and the OpenCV library, so you will be able to use go-to-definition, Code Map, Code Jumps and other IntelliSense features:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/38-foundref.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4354\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/38-foundref.png\" alt=\"38-foundref\" width=\"1138\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/38-foundref.png 1138w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/38-foundref-300x204.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/38-foundref-1024x696.png 1024w\" sizes=\"(max-width: 1138px) 100vw, 1138px\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to cross-compile the OpenCV library for Raspberry Pi to allow stepping through its source code and<\/p>\n","protected":false},"author":1,"featured_media":1018,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[72,41,33,85],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/941"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=941"}],"version-history":[{"count":8,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/941\/revisions"}],"predecessor-version":[{"id":4355,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/941\/revisions\/4355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media\/1018"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}