~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/samples/python/houghcircles.py

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
'''
 
4
This example illustrates how to use cv2.HoughCircles() function.
 
5
 
 
6
Usage:
 
7
    houghcircles.py [<image_name>]
 
8
    image argument defaults to ../data/board.jpg
 
9
'''
 
10
 
 
11
# Python 2/3 compatibility
 
12
from __future__ import print_function
 
13
 
 
14
import cv2
 
15
import numpy as np
 
16
import sys
 
17
 
 
18
if __name__ == '__main__':
 
19
    print(__doc__)
 
20
 
 
21
    try:
 
22
        fn = sys.argv[1]
 
23
    except IndexError:
 
24
        fn = "../data/board.jpg"
 
25
 
 
26
    src = cv2.imread(fn, 1)
 
27
    img = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
 
28
    img = cv2.medianBlur(img, 5)
 
29
    cimg = src.copy() # numpy function
 
30
 
 
31
    circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 10, np.array([]), 100, 30, 1, 30)
 
32
    a, b, c = circles.shape
 
33
    for i in range(b):
 
34
        cv2.circle(cimg, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv2.LINE_AA)
 
35
        cv2.circle(cimg, (circles[0][i][0], circles[0][i][1]), 2, (0, 255, 0), 3, cv2.LINE_AA)  # draw center of circle
 
36
 
 
37
    cv2.imshow("source", src)
 
38
    cv2.imshow("detected circles", cimg)
 
39
    cv2.waitKey(0)