【问题标题】:OpenCV Python Split -> Laplacian -> HoughCircles = Assertion failed.OpenCV Python Split -> Laplacian -> HoughCircles = 断言失败。
【发布时间】:2018-06-07 15:19:04
【问题描述】:

在拆分通道后,我尝试对image 执行霍夫圆运算,模糊拆分(单独)的结果,并对组成组件应用拉普拉斯运算。

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

cv2.error: OpenCV(3.4.1) /io/opencv/modules/imgproc/src/hough.cpp:1659: 
error: (-215) !_image.empty() && _image.type() == (((0) & ((1 << 3) - 1)) 
+ (((1)-1) << 3)) && (_image.isMat() || _image.isUMat()) in function 
HoughCircles

我不明白为什么会这样。图像是灰度的。我还尝试将拉普拉斯运算中的数据类型更改为 cv2.CV_16U,甚至 cv2.CV_8U;但是,这些会导致空白图像 - 结果 opencv 会引发不同的错误。

【问题讨论】:

    标签: python opencv


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 2020-05-04
      • 2014-02-10
      • 1970-01-01
      • 2012-11-26
      • 2014-11-24
      • 2014-05-28
      相关资源
      最近更新 更多