ハフ変換(円検出)

V3.0.0

調整不足

In [5]:
# -*- coding: utf-8 -*-
import cv2
import numpy as np

#Ipythonで表示用の設定
import matplotlib.pyplot as plt
%matplotlib inline

#画像読込
in_img = cv2.imread("opencv-logo.png")

# 入力画像をグレースケール変換
gray = cv2.cvtColor(in_img,cv2.COLOR_BGR2GRAY)

circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1,24,param1=40,param2=25,minRadius=1,maxRadius=300)

circles = np.uint16(np.around(circles))

for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(in_img,(i[0],i[1]),i[2],(0,100,100),2)
    # draw the center of the circle
    cv2.circle(in_img,(i[0],i[1]),2,(0,0,255),3)

#OpenCVがBGRなのでRGBに変換
disp_in_img  = cv2.cvtColor(in_img,  cv2.COLOR_BGR2RGB)

#画像表示
plt.figure(figsize=(15,10))
plt.subplot(111)
plt.imshow(disp_in_img)
Out[5]:
<matplotlib.image.AxesImage at 0x57df330>

inserted by FC2 system