2011-08-09 33 views
0

任何人都知道如何使用圖像創建cvCreateStructuringElementEx? 我正在嘗試使用opencv.cv.cvCreateStructuringElementEx(), 我的結構是一個bmp 160x120,黑色,半橢圓形,白色。從圖像Python OpenCV cvCreateStructuringElementEx,形狀= CV_SHAPE_CUSTOM

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) 

所以返回錯誤:

TypeError: in method 'cvCreateStructuringElementEx', argument 6 of type 'int *' 

回答

1

這可能會解決你的問題:

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

與Python 2.7和OpenCV 2.3.0運行相同的指令沒有給出一個錯誤爲了我。如預期的那樣,它返回了一個IplConvKernel。

我假設你使用的是舊版本的OpenCV,因爲你的函數使用了舊命名約定(即,cvCreateStructureElementEx vs CreateStructureElementEx)。 OpenCV在過去曾經有過一些與Python包裝有關的錯誤 - 這可能就是其中之一。

您的環境中是否可以將OpenCV更新爲2.3.x?如果是這樣,請確保您使用的是Python 2.6或2.7 - 這是目前支持的唯一版本,據我所知。

編輯: Hrm。剛看到這一天的日期。沒意識到我回到了那麼遠!哦,希望對某人有用。