2013年5月11日 星期六

Basic Opencv Python Function Usage

These are some note of how to use opencv2.4.5 in Python, some of them are collected on web.


  • HoughCircle

#!/usr/bin/python
import cv2
import cv2.cv as cv
import numpy as np
import sys
fn = sys.argv[1]
img = cv2.imread(fn)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

circles = cv2.HoughCircles(gray, cv2.cv.CV_HOUGH_GRADIENT, 1, 10, np.array([]), 100, 20, 1, 20)

a, b, c = circles.shape
for i in range(b):
    cv2.circle(img, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv2.CV_AA)
    cv2.circle(img, (circles[0][i][0], circles[0][i][1]), 2, (0, 255, 0), 3, cv2.CV_AA) # draw center of circle
cv2.imwrite('output.jpg',img)
cv2.imshow('win',img)
cv2.waitKey(0)

  • k
  • l

沒有留言 :

張貼留言