美文网首页
opencv 直线和圆检测

opencv 直线和圆检测

作者: 无效_昵称已经被使用 | 来源:发表于2017-09-20 10:42 被阅读51次
    #!  usr/bin/python
    #   coding=utf-8
    
    import numpy as np
    import cv2
    
    #   opencv 直线和圆检测
    img = cv2.imread('test.jpg')
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    edges = cv2.Canny(gray, 50, 120)
    minLineLength = 20
    maxLineGap = 5
    lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100, minLineLength, maxLineGap)
    
    # (248, 1, 4)
    # print lines.shape
    
    for x1, y1, x2, y2 in lines[0]:
        print x1, y1, x2, y2
        cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2)
    
    circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 120, param1=100, param2=30, minRadius=0, maxRadius=0)
    circles = np.uint16(np.around(circles))
    for i in circles[0, :]:
        print i
        cv2.circle(img, (i[0], i[1]), i[2], (0, 0, 255), 3)
        cv2.circle(img, (i[0], i[1]), 2, (0, 0, 255), 3)
    
    
    cv2.imshow('img', img)
    cv2.waitKey()
    cv2.destroyAllWindow()

    相关文章

      网友评论

          本文标题:opencv 直线和圆检测

          本文链接:https://www.haomeiwen.com/subject/uqwnsxtx.html