开发者

Python OpenCV cvCreateStructuringElementEx from Image, with shape = CV_SHAPE_CUSTOM

Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx(), my struture is a bmp 160x120, black, with a half ellipse in white.

im = Image.open("struture.jpeg", "r")
im = im.convert("1")
val = numpy.uint(im.getdata())
gim = opencv.cv.cvCreateStructuringElementEx(im.size[0], im.size[1], im.size[0]/2, im.size[1]/2, opencv.cv.CV_SHAPE_CUSTOM, val)

So return the error:

TypeErro开发者_C百科r: in method 'cvCreateStructuringElementEx', argument 6 of type 'int *'


This might solved your problems:

int val[9]={0,1,0,1,1,1,0,1,0};


Running the same instructions with Python 2.7 and OpenCV 2.3.0 didn't give an error for me. It returned an IplConvKernel, as expected.

I'm assuming you're using an older version of OpenCV, since you're using the old naming convention for their functions (that is, cvCreateStructureElementEx vs CreateStructureElementEx). OpenCV has had a few errors here and there with the Python wrappers in the past - this might have been one of them.

Is it possible in your environment to update OpenCV to 2.3.x? And, if so, make sure you're also using either Python 2.6 or 2.7 - those are the only versions currently supported as far as I'm aware.

Edit: Hrm. Just saw the date on this one. Didn't realise I went back that far! Oh well, hopefuly useful to someone.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜