我已經安裝了OpenCV的2.2,當我嘗試使用drawContours我得到以下錯誤:使用drawContours OpenCV的功能在Python
cv.drawContours(frame, contours, 0, cv.RGB(255, 0, 0))
TypeError: <unknown> is not a numpy array
與此相關的錯誤代碼是:
storage = cv.CreateMemStorage(0)
contours = cv.FindContours (color_mask, storage, method = cv.CV_CHAIN_APPROX_SIMPLE)
cv.drawContours(frame, contours, 0, cv.RGB(255, 0, 0))
Python文檔不與參數的正確順序(我知道正確的順序感謝爲IDLE)和該功能的C++文檔對應不幫我很
以下是完整的代碼(相關代碼):
cv.NamedWindow("MyWindow", 1)
capture = cv.CaptureFromCAM(0)
while 1:
frame = cv.QueryFrame(capture)
color_mask = cv.CreateImage(cv.GetSize(frame), 8, 1)
cv.InRangeS(frame, cv.Scalar(*min_color), cv.Scalar(*max_color), color_mask)
cv.CvtColor(frame, frame, cv.CV_BGR2HSV)
storage = cv.CreateMemStorage(0)
contours = cv.FindContours (color_mask, storage, method = cv.CV_CHAIN_APPROX_SIMPLE)
cv.drawContours(image = frame, contours = contours, contourIdx = 0, color = cv.RGB(255, 0, 0))
cv.ShowImage("MyWindow", frame)
在此先感謝
正確的函數參數不與官方參考(我知道這聽起來很愚蠢)相對應。如果我像你說的那樣提出以下錯誤:'TypeError:必需的參數'contourIdx'(pos 3)not found' – Manuel 2011-04-06 12:00:32
你能顯示代碼嗎? – P2bM 2011-04-06 12:11:17
經過一小段時間的休息之後,我認爲錯誤可能出現在代碼輪廓 – Manuel 2011-04-06 13:24:59