I'm new to opencv.Some weird things happened when I drew a circle.It didn't work when I tried to pass c2 to the circle function,but it worked well when I pass c1 to the color argument. But c1 == c2.
Here is my code:
import cv2
import numpy as np
canvas = np.zeros((300, 300, 3), dtype='uint8')
for _ in range(1):
r = np.random.randint(0, 200)
center = np.random.randint(0, 300, size=(2, ))
color = np.random.randint(0, 255, size=(3, ))
c1 = tuple(color.tolist())
c2 = tuple(color)
print('c1 == c2 : {} '.format(c1 == c2))
cv2.circle(canvas, tuple(center), r, c2, thickness=-1)
cv2.imshow('Canvas', canvas)
cv2.waitKey(0)
when I use c2,the console printed:'TypeError: Scalar value for argument 'color' is not numeric',but why it happened when c1 == c2?Thanks.
ndarray.tolist()
: data items are converted to the nearest compatible builtin Python type, via the item
function.Ex.
import cv2
import numpy as np
canvas = np.zeros((300, 300, 3), dtype='uint8')
for _ in range(1):
r = np.random.randint(0, 200)
center = np.random.randint(0, 300, size=(2, ))
color = np.random.randint(0, 255, size=(3, ))
#convert data types int64 to int
color = ( int (color [ 0 ]), int (color [ 1 ]), int (color [ 2 ]))
cv2.circle(canvas, tuple(center), r, tuple (color), thickness=-1)
cv2.imshow('Canvas', canvas)
cv2.waitKey(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With