import cv2 as cv
import numpy as np
def circle_fitness_demo():
# 创建图像, 绘制初始点
image = np.zeros((400, 400, 3), dtype=np.uint8)
x = np.array([30, 50, 100, 120])
y = np.array([100, 150, 240, 200])
for i in range(len(x)):
cv.circle(image, (x[i], y[i]), 3, (255, 0, 0), -1, 8, 0)
cv.imwrite("D:/curve.png", image)
# 多项式曲线生成
poly = np.poly1d(np.polyfit(x, y, 6))
print(poly)
# 绘制拟合曲线
for t in range(30, 250, 1):
y_ = np.int(poly(t))
cv.circle(image, (t, y_), 1, (0, 0, 255), 1, 8, 0)
cv.imshow("fit curve", image)
cv.imwrite("D:/fitcurve.png", image)
cv.waitKey()
cv.destroyAllWindows()
circle_fitness_demo()
import cv2
import math
import numpy as np
import matplotlib.pyplot as plt
def getDis(pointX,pointY,lineX1,lineY1,lineX2,lineY2):
#这里的XY代表要求的点,(x1,y1)(x2,y2)是用来确定直线用的