我一直在尝试使用椭圆函数(https://docs.opencv.org/3.0-beta/modules/imgproc/doc/drawing_functions.html)在openCV中绘制椭圆弧,但是,对于较大的半径值,弧似乎是分段的。
您知道如何增加圆弧的分辨率以在较大的半径值下更好地显示吗?
我尝试绘制一个半径较小的圆弧,看起来很平滑,并且还尝试提高图像分辨率,但是没有发现差异。
我的代码如下:
A[0] = round(A[0]*dpm - Xmin + margin) #Normalize CenterX
A[1] = round(A[1]*dpm - Ymin + margin) #Normalize CenterY
A[2] = round(A[2]*dpm) #Normalize Radius
startAng = A[3]
endAng = A[4]
A=A.astype(int)
cv2.ellipse(Blank,(A[0],A[1]),(A[2],A[2]), 0, startAng, endAng, 0 ,1)
同时: 空白是我要在其上绘制圆弧的图像(np数组,大小=(398,847)
(A [0],A [1])是中心点
(A [2],A [2])椭圆轴
0是角度
startAng是圆弧的起始角度
endAng是圆弧的终止角度
0是线条颜色(黑色)
1是线粗线
代码应产生平滑的弧线,但看起来像是由4条线组成的分段。
答案 0 :(得分:0)
我最终编写了一个在输入图像上绘制圆弧的函数:
import numpy as np
import cv2
blank = np.ones((500,500))
def DrawArc(image, center, radius, startAng, endAng, color,resolution):
'''Draws an arc with specific reslution and color on an input image
Args:
image - The input image to draw the arc on
center - Arc's center
radius - Arc's radius
startAng - the starting angle of the arc
engAng - the ending angle of the arc
color - Arc's color on the input image
resolution - Number of points for calculation
output:
image - updated image with plotted arc'''
startAng += 90
endAng += 90
theta = np.linspace(startAng,endAng,resolution)
x = np.round(radius*np.cos(np.deg2rad(theta))) + center[0]
y = np.round(radius*np.sin(np.deg2rad(theta))) + center[1]
x=x.astype(int)
y=y.astype(int)
for k in range(np.size(theta)):
image[x[k]][y[k]] = color
return image
image = DrawArc(blank,(250,250),200,0,90,0,1000)
cv2.imshow("Arc",image)
cv2.waitKey()
输出图像是 Output