【问题标题】:How to increase elliptical arc resolution for high radius values in opencv?如何增加opencv中高半径值的椭圆弧分辨率?
【发布时间】:2019-02-17 20:08:27
【问题描述】:

我一直在尝试使用椭圆函数 (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 array, size= (398, 847) 上绘制弧线的图像

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

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

0是角度

startAng 是圆弧的起始角度

endAng 是圆弧的结束角度

0 是线条颜色(黑色)

1 是线的粗细

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

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    我最终编写了一个函数来在输入图像上绘制弧线:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-29
      • 2016-03-18
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 2015-09-23
      • 2011-07-17
      • 2017-04-07
      相关资源
      最近更新 更多