Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why OpenCV does not apply antialiasing when drawing on grayscale image?

Tags:

opencv

Here's the code I use to create new image, draw a circle onto it and show it:

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()                                                                                                                                                                                        

However, no antialiasing seems to be applied (I upscaled the image x10): enter image description here

What am I doing wrong?

like image 347
Rogach Avatar asked Mar 10 '23 01:03

Rogach


1 Answers

If the image depth is not CV_8U, the line_type is automatically set to 8.

From opencv/modules/imgproc/src/drawing.cpp:

if( line_type == CV_AA && img.depth() != CV_8U )
    line_type = 8;

Since the type of numpy.ones defaults to numpy.float64, you're losing the antialiased line.

like image 171
beaker Avatar answered May 13 '23 04:05

beaker