title: opencv python is faster than c++?
body: <p>I am trying to time the houghcircle in python and c++ to see if c++ gives edge over processing time (intuitively it should!)</p>
  
  <h3>Versions</h3>
  
  <ul>
  <li>python: 3.6.4</li>
  <li>gcc compiler: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609</li>
  <li>cmake : 3.5.1</li>
  <li>opencv : 3.4.1 </li>
  </ul>
  
  <blockquote>
    <p>I actually installed opencv using anaconda. Surprisingly c++ version
    also worked</p>
  </blockquote>
  
  <p>The image I am using is given here:
  <a href="https://i.stack.imgur.com/1sKj7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1sKj7.png" alt="enter image description here"></a></p>
  
  <h1>Python code</h1>
  
  <pre><code>import cv2
  import time
  import sys
  
  def hough_transform(src,dp,minDist,param1=100,param2=100,minRadius=0,maxRadius=0):
      gray = cv2.cvtColor(src,cv2.COLOR_RGB2GRAY)
      start_time = time.time()
      circles=cv2.HoughCircles(gray,
                               cv2.HOUGH_GRADIENT,
                               dp = dp,
                               minDist = minDist,
                               param1=param1,
                               param2=param2,
                               minRadius=minRadius,
                               maxRadius=maxRadius)
      end_time = time.time()
      print("Time taken for hough circle transform is : {}".format(end_time-start_time))
      # if circles is not None:
      #         circles = circles.reshape(circles.shape[1],circles.shape[2])
      # else:
      #     raise ValueError("ERROR!!!!!! circle not detected try tweaking the parameters or the min and max radius")
      #
      # a = input("enter 1 to visualize")
      # if int(a) == 1 :
      #     for circle in circles:
      #         center = (circle[0],circle[1])
      #         radius = circle[2]
      #         cv2.circle(src, center, radius, (255,0,0), 5)
      #
      #     cv2.namedWindow("Hough circle",cv2.WINDOW_NORMAL)
      #     cv2.imshow("Hough circle",src)
      #     cv2.waitKey(0)
      #     cv2.destroyAllWindows()
      #
      #
      return
  
  if __name__ == "__main__":
      if len(sys.argv) != 2:
          raise ValueError("usage: python hough_circle.py &lt;path to image&gt;")
      image = cv2.imread(sys.argv[1])
      image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
      hough_transform(image,1.7,100,50,30,690,700)
  </code></pre>
  
  <h1>C++ code</h1>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;opencv2/opencv.hpp&gt;
  #include &lt;ctime&gt;
  using namespace std;
  using namespace cv;
  
  void hough_transform(Mat src, double dp, double minDist, double param1=100, double param2=100, int minRadius=0, int maxRadius=0 )
  {
    Mat gray;
    cvtColor( src, gray, COLOR_RGB2GRAY);
    vector&lt;Vec3f&gt; circles;
    int start_time = clock();
    HoughCircles( gray, circles, HOUGH_GRADIENT, dp, minDist, param1, param2, minRadius, maxRadius);
    int end_time = clock();
    cout&lt;&lt;"Time taken hough circle transform: "&lt;&lt;(end_time-start_time)/double(CLOCKS_PER_SEC)&lt;&lt;endl;
    // cout&lt;&lt;"Enter 1 to visualize the image";
    // int vis;
    // cin&gt;&gt;vis;
    // if (vis == 1)
    // {
    //   for( size_t i = 0; i &lt; circles.size(); i++ )
    //   {
    //       Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    //       int radius = cvRound(circles[i][2]);
    //       circle( src, center, radius, Scalar(255,0,0), 5);
    //   }
    //   namedWindow( "Hough Circle", WINDOW_NORMAL);
    //   imshow( "Hough Circle", src);
    //   waitKey(0);
    //   destroyAllWindows();
    // }
    return;
  }
  
  int main(int argc, char** argv)
  {
    if( argc != 2 ){
      cout&lt;&lt;"Usage hough_circle &lt;path to image.jpg&gt;";
      return -1;
    }
    Mat image;
    image = imread(argv[1]);
    cvtColor(image,image,COLOR_BGR2RGB);
    hough_transform(image,1.7,100,50,30,690,700);
    return 0;
  }
  </code></pre>
  
  <p>I was hoping for C++ hough transform to ace python but what happened was actually opposite.</p>
  
  <h1>Python result:</h1>
  
  <p><a href="https://i.stack.imgur.com/fuA55.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fuA55.png" alt="enter image description here"></a></p>
  
  <h1>C++ result:</h1>
  
  <p><a href="https://i.stack.imgur.com/mO46Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mO46Y.png" alt="enter image description here"></a></p>
  
  <p>Even though C++ ran the complete program ~2X faster it is very slow in hough transform. Why is it so? This is very counter intuitive. What am I missing here?</p>