为什么 OpenCV 在绘制灰度图像时不应用抗锯齿?

Rog*_*ach 3 opencv

这是我用来创建新图像的代码,在它上面画一个圆圈并显示它:

import numpy as np
import cv2

# create 50x50 image, filled with white
img = np.ones((50,50))
# draw a circle onto the image
cv2.circle(img, (25,25), 10, 0, 2, lineType=cv2.LINE_AA)
# show the image on the screen
cv2.imshow("i", img)
cv2.waitKey(0)                                                                                                                                                                                                 
cv2.destroyAllWindows()                                                                                                                                                                                        
Run Code Online (Sandbox Code Playgroud)

但是,似乎没有应用抗锯齿(我将图像放大了 10 倍): 在此处输入图片说明

我究竟做错了什么?

bea*_*ker 6

如果图像深度不是CV_8Uline_type则自动设置为8

来自opencv/modules/imgproc/src/drawing.cpp

if( line_type == CV_AA && img.depth() != CV_8U )
    line_type = 8;
Run Code Online (Sandbox Code Playgroud)

由于类型numpy.ones默认为numpy.float64,您将丢失抗锯齿线。