2016-02-19 60 views
0

我正在使用OpenCV和WXLibrary一起爲圖像處理創建一個Rect對象。WX庫Rect

這裏是我們的代碼 輪廓在輪廓:

 #print cv2.boundingRect(contour) 
     #rec = Rect(a) 
     a= cv2.boundingRect(contour) 
     rec = wx.Rect(a) 

,我們的錯誤是:

traceback (most recent call last): 
    File "/home/pi/Desktop/OpenCV(c++).py", line 149, in <module> 
processImage() 
    File "/home/pi/Desktop/OpenCV(c++).py", line 101, in processImage 
    rec = wx.Rect(a) 
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py",   line 1145, in __init__ 
    _core_.Rect_swiginit(self,_core_.new_Rect(*args, **kwargs)) 
TypeError: in method 'new_Rect', expected argument 1 of type 'int' 

語法上講,它似乎很動聽。什麼是問題?

回答

1

wx.Rect的構造函數不直接接受來自OpenCV的輸出。嘗試單獨傳遞每個參數。

x, y, w, h = cv2.boundingRect(contour) 
rect = wx.Rect(x, y, w, h) 
+2

或者只是'rec = wx.Rect(* a)' – Gerrat