title: opencv build in debug mode with Ubuntu 18.04 for c/c++ code debugging
body: <p>I tried to installed latest <strong>opencv 4.5.5 in debug mode</strong> (for c/cpp code). So followed below steps -</p>
  <pre><code>$ sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
      libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
      libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
      gfortran openexr libatlas-base-dev python3-dev python3-numpy \
      libtbb2 libtbb-dev libdc1394-22-dev
      
  $ mkdir ~/opencv_build &amp;&amp; cd ~/opencv_build
  $ git clone https://github.com/opencv/opencv.git
  $ git clone https://github.com/opencv/opencv_contrib.git
  
  $ cd ~/opencv_build/opencv
  $ mkdir build &amp;&amp; cd build
  
  $ cmake -D CMAKE_BUILD_TYPE=DEBUG \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..
      
  $ make -j8
      
  $ sudo make install
      
  $ pkg-config --modversion opencv4
      4.5.5
  </code></pre>
  <p>I have installed successfully opencv in my system.</p>
  <p>I want to execute opencv optical flow sample code in <strong>.cpp</strong> .</p>
  <p>I want to enter inside <code>goodFeaturesToTrack</code> function and wants to check its implementation. But with current library I am not able to go inside this function. The execute just going to the next line.</p>
  <p><strong>Query:</strong></p>
  <ol>
  <li><strong>How can I build the opencv in debug mode correctly for C/CPP sample code debugging.</strong></li>
  </ol>
  <p>There are lots of links available on internet for using <strong>cmake -D CMAKE_BUILD_TYPE=DEBUG</strong> flag. But that did not work for me .</p>
  <ol start="2">
  <li>How to cross check weather opencv libraries are in debug mode or release mode.</li>
  </ol>
  <p>Sample code for optical flow code -</p>
  <pre><code>#include &quot;opencv2/video/tracking.hpp&quot;
  #include &quot;opencv2/imgproc/imgproc.hpp&quot;
  #include &quot;opencv2/highgui/highgui_c.h&quot;
  #include &quot;opencv2/highgui.hpp&quot;
  
  #include &lt;iostream&gt;
  #include &lt;ctype.h&gt;
  
  using namespace cv;
  using namespace std;
  
  static void help()
  {
      // print a welcome message, and the OpenCV version
      cout &lt;&lt; &quot;\nThis is a demo of Lukas-Kanade optical flow lkdemo(),\n&quot;
              &quot;Using OpenCV version %s\n&quot; &lt;&lt; CV_VERSION &lt;&lt; &quot;\n&quot;
              &lt;&lt; endl;
  
      cout &lt;&lt; &quot;\nHot keys: \n&quot;
              &quot;\tESC - quit the program\n&quot;
              &quot;\tr - auto-initialize tracking\n&quot;
              &quot;\tc - delete all the points\n&quot;
              &quot;\tn - switch the \&quot;night\&quot; mode on/off\n&quot;
              &quot;To add/remove a feature point click it\n&quot; &lt;&lt; endl;
  }
  
  Point2f point;
  bool addRemovePt = false;
  
  static void onMouse( int event, int x, int y, int /*flags*/, void* /*param*/ )
  {
      if( event == CV_EVENT_LBUTTONDOWN )
      {
          point = Point2f((float)x,(float)y);
          addRemovePt = true;
      }
  }
  
  int main( int argc, char** argv )
  {
      VideoCapture cap;
      TermCriteria termcrit(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03);
      Size subPixWinSize(10,10), winSize(31,31);
  
      const int MAX_COUNT = 500;
      bool needToInit = false;
      bool nightMode = false;
  
      if( argc == 1 || (argc == 2 &amp;&amp; strlen(argv[1]) == 1 &amp;&amp; isdigit(argv[1][0])))
          cap.open(argc == 2 ? argv[1][0] - '0' : 0);
      else if( argc == 2 )
          cap.open(argv[1]);
  
      if( !cap.isOpened() )
      {
          cout &lt;&lt; &quot;Could not initialize capturing...\n&quot;;
          return 0;
      }
  
      help();
  
      namedWindow( &quot;LK Demo&quot;, 1 );
      setMouseCallback( &quot;LK Demo&quot;, onMouse, 0 );
  
      Mat gray, prevGray, image;
      vector&lt;Point2f&gt; points[2];
  
      for(;;)
      {
          Mat frame;
          cap &gt;&gt; frame;
          if( frame.empty() )
              break;
  
          frame.copyTo(image);
          cvtColor(image, gray, CV_BGR2GRAY);
  
          if( nightMode )
              image = Scalar::all(0);
  
          if( 1 ) //needToInit )
          {
              // automatic initialization
              goodFeaturesToTrack(gray, points[1],
                                  MAX_COUNT, 0.01, 10,
                                  Mat(), 3,
                                  0, 0, 0.04);
              cornerSubPix(gray, points[1], subPixWinSize, Size(-1,-1), termcrit);
              addRemovePt = false;
          }
          else if( !points[0].empty() )
          {
              vector&lt;uchar&gt; status;
              vector&lt;float&gt; err;
              if(prevGray.empty())
                  gray.copyTo(prevGray);
              calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize,
                                   3, termcrit, 0, 0.001);
              size_t i, k;
              for( i = k = 0; i &lt; points[1].size(); i++ )
              {
                  if( addRemovePt )
                  {
                      if( norm(point - points[1][i]) &lt;= 5 )
                      {
                          addRemovePt = false;
                          continue;
                      }
                  }
  
                  if( !status[i] )
                      continue;
  
                  points[1][k++] = points[1][i];
                  circle( image, points[1][i], 3, Scalar(0,255,0), -1, 8);
              }
              points[1].resize(k);
          }
  
          if( addRemovePt &amp;&amp; points[1].size() &lt; (size_t)MAX_COUNT )
          {
              vector&lt;Point2f&gt; tmp;
              tmp.push_back(point);
              cornerSubPix( gray, tmp, winSize, cvSize(-1,-1), termcrit);
              points[1].push_back(tmp[0]);
              addRemovePt = false;
          }
  
          needToInit = false;
          imshow(&quot;LK Demo&quot;, image);
  
          char c = (char)waitKey(10);
          if( c == 27 )
              break;
          switch( c )
          {
          case 'r':
              needToInit = true;
              break;
          case 'c':
              points[1].clear();
              break;
          case 'n':
              nightMode = !nightMode;
              break;
          default:
              ;
          }
  
          std::swap(points[1], points[0]);
          swap(prevGray, gray);
      }
  
      return 0;
  }
  </code></pre>