如何提高opencv中高半径值的椭圆弧分辨率?

2024-05-26 14:21:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用椭圆函数(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)

而: Blank是我要在其上绘制弧的图像(np数组,size=(398847)

(A[0],A[1])是中心点

(A[2],A[2])椭圆轴

0是角度

startAng是弧的起始角

endAng是弧的结束角

0是线条颜色(黑色)

1是线条粗细

代码应该产生一个平滑的圆弧,但它看起来像是由4条线组成的分段


Tags: 代码margin图像半径绘制分辨率线条dpm
1条回答
网友
1楼 · 发布于 2024-05-26 14:21:29

最后,我编写了一个函数,在输入图像上绘制圆弧:

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

相关问题 更多 >

    热门问题