马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
python检测同心圆
原图如下:
- import cv2
- import numpy as np
- # 读取图像
- image_path = r"E:\pycharm3\pythonProject\image\image.png"
- img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) # 灰度图像
- img_color = cv2.imread(image_path, cv2.IMREAD_COLOR) # 彩色图像
- # 检查图像加载
- if img is None or img_color is None:
- print("图像加载失败,请检查文件路径是否正确:", image_path)
- exit()
- # 第一次检测(较大圆)
- circles1 = cv2.HoughCircles(
- img,
- cv2.HOUGH_GRADIENT,
- dp=1,
- minDist=60,
- param1=50,
- param2=60,
- minRadius=170,
- maxRadius=200
- )
- # 第二次检测(中等圆1)
- circles2 = cv2.HoughCircles(
- img,
- cv2.HOUGH_GRADIENT,
- dp=1,
- minDist=170,
- param1=100,
- param2=60,
- minRadius=60,
- maxRadius=90
- )
- # 第三次检测(中等圆2,模糊图像)
- blurred = cv2.GaussianBlur(img, (9, 9), 2) # 高斯模糊处理
- circles3 = cv2.HoughCircles(
- blurred,
- cv2.HOUGH_GRADIENT,
- dp=1
复制代码 |