OpenCV Python拆分->;拉普拉斯->;HoughCircles=断言失败。
在分割通道、模糊分割结果(单独)并对组成组件应用拉普拉斯操作后,我尝试在上执行hough圆操作OpenCV Python拆分->;拉普拉斯->;HoughCircles=断言失败。,python,opencv,Python,Opencv,在分割通道、模糊分割结果(单独)并对组成组件应用拉普拉斯操作后,我尝试在上执行hough圆操作 img = cv2.imread(fileName) b, g, r = cv2.split(img) kSize = 3 gBlur = cv2.blur(g, (kSize, kSize)) print(gBlur.shape) test = np.array([]) gEdges = cv2.Laplacian(gBlur, cv2.CV_64F) circles = cv2.HoughCi
img = cv2.imread(fileName)
b, g, r = cv2.split(img)
kSize = 3
gBlur = cv2.blur(g, (kSize, kSize))
print(gBlur.shape)
test = np.array([])
gEdges = cv2.Laplacian(gBlur, cv2.CV_64F)
circles = cv2.HoughCircles(gEdges, cv2.HOUGH_GRADIENT, 40, 10,
param1=50,param2=60,minRadius=2,maxRadius=15)
但是,我从OpenCV收到一个错误,声明:
OpenCV(3.4.1) Error: Assertion failed (!_image.empty() &&
_image.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) &&
(_image.isMat() || _image.isUMat())) in HoughCircles, file
/io/opencv/modules/imgproc/src/hough.cpp, line 1659
OpenCV(3.4.1)错误:断言失败(!\u image.empty()&&
_image.type()==((0)和((1)您在
cv2.Laplacian
中提到的图像类型是问题所在。另一件事是您的代码没有完成。下面是已完成的代码
import cv2
import numpy as np
img = cv2.imread('stack1.png')
b, g, r = cv2.split(img)
kSize = 3
gBlur = cv2.blur(g, (kSize, kSize))
print(gBlur.shape)
test = np.array([])
gEdges = cv2.Laplacian(gBlur, cv2.CV_8UC1)
circles = cv2.HoughCircles(gEdges, cv2.HOUGH_GRADIENT, 40, 10, param1=50,param2=60,minRadius=2,maxRadius=15)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
import numpy as np
img = cv2.imread('stack1.png')
b, g, r = cv2.split(img)
kSize = 3
gBlur = cv2.blur(g, (kSize, kSize))
print(gBlur.shape)
test = np.array([])
gEdges = cv2.Laplacian(gBlur, cv2.CV_8UC1)
circles = cv2.HoughCircles(gEdges, cv2.HOUGH_GRADIENT, 40, 10, param1=50,param2=60,minRadius=2,maxRadius=15)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',img)
cv2.waitKey(0)
cv2.destroyAllWindows()