title: Does this OpenCV code run on the GPU or the CPU?
body: <p>I need to do image processing on the GPU for a class requirement.
  Does this OpenCV code run on the GPU or CPU?</p>
  <pre><code>// The &quot;Square Detector&quot; program.
  // It loads several images sequentially and tries to find squares in
  // each image
      #include &quot;opencv2/core/core.hpp&quot;
      #include &quot;opencv2/imgproc/imgproc.hpp&quot;
      #include &quot;opencv2/highgui/highgui.hpp&quot;
      
      #include &lt;iostream&gt;
      #include &lt;math.h&gt;
      #include &lt;string.h&gt;
      
      using namespace cv;
      using namespace std;
      int thresh = 50, N = 11;
      const char* wndname = &quot;Square Detection Demo&quot;;
      static void findSquares( const Mat&amp; image, vector&lt;vector&lt;Point&gt; &gt;&amp; squares )
      {
          squares.clear();
          
          Mat pyr, timg, gray0(image.size(), CV_8U), gray;
          pyrDown(image, pyr, Size(image.cols/2, image.rows/2));
          pyrUp(pyr, timg, image.size());
          vector&lt;vector&lt;Point&gt; &gt; contours;
          
          // find squares in every color plane of the image
          for( int c = 0; c &lt; 3; c++ )
          {
              int ch[] = {c, 0};
              mixChannels(&amp;timg, 1, &amp;gray0, 1, ch, 1);
              for( int l = 0; l &lt; N; l++ )
              {
                  if( l == 0 )
                  {
                      Canny(gray0, gray, 0, thresh, 5);
                      dilate(gray, gray, Mat(), Point(-1,-1));
                  }
                  else
                  {
                      gray = gray0 &gt;= (l+1)*255/N;
                  }
                  
                  findContours(gray, contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
                  
                  vector&lt;Point&gt; approx;
                 for( size_t i = 0; i &lt; contours.size(); i++ )
                  {
                      approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);
                      if( approx.size() == 4 &amp;&amp;
                         fabs(contourArea(Mat(approx))) &gt; 1000 &amp;&amp;
                         isContourConvex(Mat(approx)) )
                      {
                          double maxCosine = 0;
                          
                          for( int j = 2; j &lt; 5; j++ )
                          {
                              // find the maximum cosine of the angle between joint edges
                              double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
                              maxCosine = MAX(maxCosine, cosine);
                          }
                          
                          // if cosines of all angles are small
                          // (all angles are ~90 degree) then write quandrange
                          // vertices to resultant sequence
                          if( maxCosine &lt; 0.3 )
                              squares.push_back(approx);
                      }
                  }
              }
          }
      }
  </code></pre>