Canny算子边缘提取+霍夫曼圆检测

Canny算子边缘检测

import cv2
import matplotlib.pyplot as plt
import numpy as np
image = cv2.imread("原图路径")
img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)  # 转为灰度图
low_threshold = x
high_threshold = y
img_gaussian = cv2.GaussianBlur(img_gray, (3,3), 1)
img_canny = cv2.Canny(blurred, low_threshold, high_threshold)  # 用Canny算子提取边缘
#cv2.imwrite("存储路径", img_canny) #存储canny提取的边缘图

霍夫曼圆检测

# 2 进行中值模糊,去噪点
#注:由于我的canny算比边缘宽度为1像素,所以中值滤波的核选择1,不然会导致将边缘过滤,导致下面的输入为空
img = cv.medianBlur(img_canny, 1)

# 3 霍夫圆检测
circles = cv.HoughCircles(gay_img, cv.HOUGH_GRADIENT, 1, 200, param1=100, param2=30, minRadius=0, maxRadius=200)
# 4 将检测结果绘制在图像上
for i in circles[0, :]:  # 遍历矩阵每一行的数据
    # cvCircle(源图像指针, 画圆的圆心坐标,圆的半径,圆的颜色,圆的线条的粗细程度,线条的类型,圆心坐标点和半径值的小数点位数)

    # 绘制圆形
    cv.circle(planets, (int(i[0]), int(i[1])), int(i[2]), (0, 255, 0), 1)
    cv.circle(planets, (int(i[0]), int(i[1])), 2, (0, 0, 255),3)

# 5 图像显示
plt.figure(figsize=(10,8),dpi=100)
plt.imshow(planets[:,:,::-1]),plt.title('霍夫变换圆检测')
plt.xticks([]), plt.yticks([])
plt.show()

TAG:none

已有 9 条评论

  1. 博主真是太厉害了!!!

    fsvdmcgyue September 22nd, 2024 at 07:15 pm回复
  2. 想想你的文章写的特别好www.jiwenlaw.com

    ouzqwtmpzg October 6th, 2024 at 07:51 pm回复
  3. 如何突破传奇世界2私服登录器难题?:https://501h.com/fugu/2024-10-26/45024.html

    kyxczdgqom November 12th, 2024 at 12:32 am回复
  4. 独家揭秘:传奇私服破解账号密码,一夜称霸游戏界的神秘攻略!:https://501h.com/yuanshi/2024-10-07/40648.html

    tjpjunsldf November 12th, 2024 at 01:54 am回复
  5. 你的文章内容非常卖力,让人点赞。 https://www.yonboz.com/video/9773.html

    razmkkwvts November 18th, 2024 at 04:49 am回复
  6. 《巅峰拍档第十三季》记录片高清在线免费观看:https://www.jgz518.com/xingkong/107079.html

    sshlqrqiiy November 23rd, 2024 at 04:38 pm回复
  7. 《巅峰拍档第十三季》记录片高清在线免费观看:https://www.jgz518.com/xingkong/107079.html

    yvdwobfskx December 5th, 2024 at 07:39 pm回复
  8. 《社长之路》港台综艺高清在线免费观看:https://www.jgz518.com/xingkong/34611.html

    nfjeacxzca December 15th, 2024 at 01:14 am回复
  9. 《爱与罪短剧》短片剧高清在线免费观看:https://www.jgz518.com/xingkong/159249.html

    lifepinzxg January 2nd, 2025 at 06:03 pm回复

发表新评论