我完全不明白为什么在看了文档之后不能用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')
对我有用
我有同样的问题,我解决了。我无法运行的第一行代码是:
我发现轴(以及中心)必须是整数元组,而不是浮点数。 所以下线就可以了!
我认为您应该采用其他正确格式的值。
以下是Opencv网站的链接: http://answers.opencv.org/question/30778/how-to-draw-ellipse-with-first-python-function/
这是我的iPython课程-看起来效果不错:
这起作用-并产生了以下结果:
所以,有点奇怪。。。也许您导入
cv2
模块的方式有问题?或者(更有可能)您的
frame
对象的类型/结构是什么?相关问题 更多 >
编程相关推荐