opencv找圆弧轮廓的圆心
时间: 2023-12-14 12:34:00 浏览: 200
以下是使用OpenCV找圆弧轮廓的圆心的步骤:
1. 读取图像并将其转换为灰度图像。
```python
import cv2
img = cv2.imread('image.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
```
2. 对图像进行模糊处理,以减少噪声。
```python
gray_blur = cv2.GaussianBlur(gray, (15, 15), 0)
```
3. 使用HoughCircles函数检测圆形轮廓。
```python
circles = cv2.HoughCircles(gray_blur, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
```
4. 提取圆心坐标。
```python
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(img, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(img, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
```
5. 显示结果。
```python
cv2.imshow("output", img)
cv2.waitKey(0)
```
阅读全文
相关推荐












