【发布时间】:2021-08-25 03:45:04
【问题描述】:
原图circle
设置图片
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread('blackcirr.jpg')
fig = plt.figure(figsize = (5, 5))
plt.imshow(image)
寻找质心
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
canny_edges = cv2.Canny(gray_img, 30, 200)
M = cv2.moments(canny_edges)
#calculate x,y coordinate of the center
cx = int(M['m10'] / M['m00'])
cy = int(M['m01'] / M['m00'])
circle = cv2.circle(image, (cx,cy), 5, (255,255,0), -1)
cv2.putText(image, "centroid", (cx -25, cy-25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,0),)
fig = plt.figure(figsize = (5, 5))
line = cv2.line(image,(cx,cy), () )
plt.imshow(image)
plt.xticks([])
plt.yticks([])
我想每隔 2 度或设定的度数绘制一条线,将质心连接到形状中的点。
【问题讨论】:
标签: python python-3.x opencv