import cv2 import numpy as np def detect_radial_pattern(image_path): # 读取图像 img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) if img is None: print("Error: Image not found.") return # 应用高斯模糊减少图像噪声 blurred = cv2.GaussianBlur(img, (5, 5), 0) # 使用Canny边缘检测算法 edges = cv2.Canny(blurred, 50, 150) # 使用霍夫圆变换检测可能的中心点 circles = cv2.HoughCircles(edges, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0) if circles is not None: circles = np.uint16(np.around(circles)) for i in circles[0, :]: # 绘制圆心 center = (i[0], i[1]) cv2.circle(img, center, 1, (0, 100, 100), 3) # 这里可以进一步分析从圆心出发的线条,但为简化示例,我们仅绘制圆心 # (可选)分析从圆心出发的线条,这通常需要更复杂的图像处理或机器学习方法 # 显示结果 cv2.imshow('Radial Pattern Detection', img) cv2.waitKey(0) cv2.destroyAllWindows() # 使用示例 image_path = 'path_to_your_image.jpg' detect_radial_pattern(image_path)