box = cv2.minAreaRect(cnt)#轮廓的最小外接矩形
box = cv2.boxPoints(box)#矩形的四个角点
求box[0]到box[1]两点连线上距离box[0]10个像素点的点point1,这个点最简单的方法怎么求,求代劳
cv2.line(image, box[0], point1, (0, 255, 0), 3)#box[0]到point1画线
可以用向量求
d = np.sqrt((box[1][0]-box[0][0])**2+(box[1][1]-box[0][1])**2)
#新的位置
x = box[0][0]+10/d*(box[1][0]-box[0][0])
y = box[0][1]+10/d*(box[1][1]-box[0][])
最后需要一个取整
一个像素点就是图像矩阵里的一个值,box【0】里记录的是box在图中的坐标,这个值取整实际上就相当于是在图二维矩阵的i,j行列值,所以往对应方向偏移10就能拿到point1的位置
v = box[1] - box[0]; # compute the direction of the line
v /= v.length(); # normalize the direction
point1 = box[0] + v * 10;