开发者

CvSize does not exist?

I have installed the official python bindings for OpenCv and I am implementing som开发者_运维百科e standard textbook functions just to get used to the python syntax. I have run into the problem, however, that CvSize does not actually exist, even though it is documented on the site...

The simple function: blah = cv.CvSize(inp.width/2, inp.height/2) yields the error 'module' object has no attribute 'CvSize'. I have imported with 'import cv'.

Is there an equivalent structure? Do I need something more? Thanks.


It seems that they opted to eventually avoid this structure altogether. Instead, it just uses a python tuple (width, height).


To add a bit more to Nathan Keller's answer, in later versions of OpenCV some basic structures are simply implemented as Python Tuples.

For example in OpenCV 2.4:

This (incorrect which will give an error)

image = cv.LoadImage(sys.argv[1]);
grayscale = cv.CreateImage(cvSize(image.width, image.height), 8, 1)

Would instead be written as this

image = cv.LoadImage(sys.argv[1]);
grayscale = cv.CreateImage((image.width, image.height), 8, 1)

Note how we just pass the Tuple directly.


The right call is cv.cvSize(inp.width/2, inp.height/2).

All functions in the python opencv bindings start with a lowercased c even in the highgui module.


Perhaps the documentation is wrong and you have to use cv.cvSize instead of cv.CvSize ? Also, do a dir(cv) to find out the methods available to you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜