Traceback (most recent call last):
hough_res = cv2.HoughCircles(img_edges, cv2.HOUGH_GRADIENT,1,100,param1=80,param2=150,minRadius=60,maxRadius=200)
cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'HoughCircles'
Overload resolution failed:
- image data type = 0 is not supported
- Expected Ptrcv::UMat for argument 'image'
源码:import cv2
import numpy as np
import matplotlib.pyplot as plt
import skimage.feature as sk
coins = cv2.imread('E:/picture.jpg')
img_copy=np.copy(coins)
#convert image to grayscale
img_gray=cv2.cvtColor(img_copy,cv2.COLOR_RGB2GRAY)
img_blur = cv2.GaussianBlur(img_gray, (15, 15), 0)
#plt.imshow(img_blur, cmap='gray')
#plt.show()
th2 = cv2.adaptiveThreshold(img_gray,255,cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY,3,5)
kernel = np.ones((5,5),np.uint8)
erosion = cv2.erode(th2,kernel,iterations=1)
img_edges = sk.canny(erosion,10,50)
#霍夫圆检测
hough_res = cv2.HoughCircles(img_edges, cv2.HOUGH_GRADIENT,1,100,param1=80,param2=150,minRadius=60,maxRadius=200)
参数不对,maxValue参数没了之后导致你的 cv2.HOUGH_GRADIENT变成了maxValue的参数了