自然场景下植物图像的基元检测

一.图像的Canny算计运用与角点检测

1.1代码详解

# 角点检测
def work01():
    img = ndimage.imread('flower.jpg', 'L')#这里是你图片的路径
    img1 = feature.canny(img, low_threshold=100, high_threshold=200)
    plt.imshow(img1), plt.gray(), plt.show()
    dst = cv2.cornerHarris(img, 3, 5, 0.04)
    dst = cv2.dilate(dst, None)
    # Threshold for an optimal value, it may vary depending on the image.
    # cv2.imshow('dst', img)
    img[dst > 0.01 * dst.max()] = [255]
    plt.imshow(img), plt.gray(), plt.show()

1.2 边缘检测结果

这里写图片描述

1.3 角点检测结果

这里写图片描述

二.利用霍夫变换的直线检测

2.1 代码详解

#直线检测
def work02():
    img = misc.face()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = img
    edges = cv2.Canny(gray, 50, 150, apertureSize=3)
    minLineLength = 300
    maxLineGap = 10
    lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength, maxLineGap)
    for x1, y1, x2, y2 in lines[0]:
        cv2.line(img, (x1, y1), (x2, y2), (0), 2)
    plt.imshow(img), plt.gray(), plt.show()

2.2 结果

这里写图片描述

三.利用霍夫变换的原的检测

3.1 代码详解

#圆环检测
def work03():

    gray = misc.face(gray=True)
    circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=10,maxRadius=50)
    #这里的参数设置minRadius 和 maxRadius为检测的半径范围
    circles = np.uint16(np.around(circles))
    for i in circles[0, :]:
        # draw the outer circle
        cv2.circle(gray, (i[0], i[1]), i[2], (0, 255, 0), 2)
        # draw the center of the circle
        cv2.circle(gray, (i[0], i[1]), 2, (0, 0, 255), 3)

    plt.imshow(gray),plt.gray(),plt.show()

3.2 结果

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值