title: Generalized Hough Transform in OpenCV - set angle precision
body: <p>I have a problem with Generalized Hough Transform (Guil version) in OpenCV. My code:</p>
  <pre><code>def generalized_Hough():
      img = cv2.imread(&quot;img.png&quot;)
      img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
      template = cv2.imread(&quot;template.png&quot;)
      height, width = template.shape[:2]
  
      edges = cv2.Canny(template, 200, 250)
      ght = cv2.createGeneralizedHoughGuil()
      ght.setTemplate(edges)
  
      ght.setMinDist(100)
      ght.setMinAngle(0)
      ght.setMaxAngle(360)
      ght.setAngleStep(1)
      ght.setLevels(360)
      ght.setMinScale(1)
      ght.setMaxScale(1.3)
      ght.setScaleStep(0.05)
      ght.setAngleThresh(100)
      ght.setScaleThresh(100)
      ght.setPosThresh(100)
      ght.setAngleEpsilon(1)
      ght.setLevels(360)
      ght.setXi(90)
  
      positions = ght.detect(img_gray)[0][0]
  
      for position in positions:
          center_col = int(position[0])
          center_row = int(position[1])
          scale = position[2]
          angle = int(position[3])
  
          found_height = int(height * scale)
          found_width = int(width * scale)
  
          rectangle = ((center_col, center_row),
                       (found_width, found_height),
                       angle)
  
          box = cv2.boxPoints(rectangle)
          box = np.int0(box)
          cv2.drawContours(img, [box], 0, (0, 0, 255), 2)
  
          for i in range(-2, 3):
              for j in range(-2, 3):
                  img[center_row + i, center_col + j] = 0, 0, 255
  
      cv2.imwrite(&quot;results.png&quot;, img)
  </code></pre>
  <p>So I read image and template, get template as Canny edges, then configure GHT (Guil version for scale and angle) and plot detections. The problem is that the results are always snapped to nearest 90 degrees, despite setting angle min, max and step to 0, 360 and 1, respectively:</p>
  <pre><code>[[294. 110.   1. 270.]
   [100. 303.   1.   0.]
   [561. 312.   1.   0.]
   [461. 126.   1.  90.]
   [194. 109.   1.   0.]]
  </code></pre>
  <p>Image example:</p>
  <p><a href="https://i.stack.imgur.com/xxfCQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xxfCQ.png" alt="enter image description here" /></a></p>
  <p>Template example:</p>
  <p><a href="https://i.stack.imgur.com/vSYUN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vSYUN.png" alt="enter image description here" /></a></p>
  <p>Results:</p>
  <p><a href="https://i.stack.imgur.com/H0th1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H0th1.png" alt="enter image description here" /></a></p>
  <p>It's clearly visible that upper left and upper right detections are in more or less correct places and scales, but angle is wrong. How can I fix that?</p>