在阅读文档之后,我完全不明白为什么我不能用OpenCV绘制一个椭圆。
首先,我使用的是CV 2.4.9
>>> cv2.__version__
'2.4.9'
>>>
第二,我试图使用以下方法:
>>> help(cv2.ellipse)
Help on built-in function ellipse in module cv2:
ellipse(...)
ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[,
lineType[, shift]]]) -> None or ellipse(img, box, color[, thickness[, lineType
]]) -> None
我的椭圆看起来如下:
cx,cy = 201,113
ax1,ax2 = 37,27
angle = -108
center = (cx,cy)
axes = (ax1,ax2)
cv2.ellipse(frame, center, axes, angle, 0 , 360, (255,0,0), 2)
但是,运行它将给我提供以下内容
>>> cv2.ellipse(frame,center,axes,angle,0,360, (255,0,0), 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ellipse() takes at most 5 arguments (8 given)
>>>
帮助?
编辑:
我想将以下内容用作一个框架
cap = cv2.VideoCapture(fileLoc)
frame = cap.read()
显然,它可以通过以下方法来修复
pil_im = Image.fromarray(frame)
cv2.ellipse(frame,center,axes,angle,0,360,(255,0,0), 2)
pil_im = Image.fromarray(raw_image)
pil_im.save('C:/Development/export/foo.jpg', 'JPEG')
发布于 2016-06-16 11:01:46
我也有同样的问题我解决了。我无法运行的第一行代码是:
cv2.ellipse(ellipMask, (113.9, 155.7), (23.2, 15.2), 0.0, 0.0, 360.0, (255, 255, 255), -1);
我发现,轴(以及中心)必须是一个整数元组,而不是浮动。因此,线下是可以的!
cv2.ellipse(ellipMask, (113, 155), (23, 15), 0.0, 0.0, 360.0, (255, 255, 255), -1);
我认为你应该采取其他的价值观,以正确的格式。
以下是Opencv网站的链接:http://answers.opencv.org/question/30778/how-to-draw-ellipse-with-first-python-function/
发布于 2014-08-20 15:40:22
下面是我的iPython会话--它似乎运行得很好:
In [54]: cv2.__version__
Out[54]: '2.4.9'
In [55]: frame = np.ones((400,400,3))
In [56]: cx,cy = 201,113
In [57]: ax1,ax2 = 37,27
In [58]: angle = -108
In [59]: center = (cx,cy)
In [60]: axes = (ax1,ax2)
In [61]: cv2.ellipse(frame, center, axes, angle, 0 , 360, (255,0,0), 2)
In [62]: plt.imshow(frame)
Out[62]: <matplotlib.image.AxesImage at 0x1134ad8d0>
这起了作用--并产生了以下情况:
所以有点奇怪。也许您导入cv2
模块的方式有什么不同吗?
或者(更有可能的) frame
对象的类型/结构是什么?
发布于 2020-05-27 08:26:13
实际上,如果在0°到360°之间绘制图,则可以使用floats,方法是使用单个椭圆参数调用函数:
ellipse_float = ((113.9, 155.7), (23.2, 15.2), 0.0)
cv2.ellipse(image, ellipse_float, (255, 255, 255), -1);
或者是一条单线:
cv2.ellipse(image, ((113.9, 155.7), (23.2, 15.2), 0.0), (255, 255, 255), -1);
# compared to the following which does not work if not grouping the ellipse paramters in a tuple
#cv2.ellipse(image, (113.9, 155.7), (23.2, 15.2), 0.0, 0, 360, (255, 255, 255), -1); # cryptic error
不幸的是,如果您想添加startAngle和stopAngle,这是行不通的。
https://stackoverflow.com/questions/25408391
复制相似问题