2011-11-30 49 views
2

我檢查the documentation但其不完全的:沒有什麼rtype參數實際上是不在話下。如何使用OpenCV的降低使用CV2蟒蛇API

我認爲這是一個降低類型,但我找不到任何像cv2.CV_REDUCE_SUM等變量...我發現了這個問題,使用不同的變量名許多功能。在cv2 API中找到正確名稱的最佳方法是什麼?

+0

你試過'dir(cv2)'還是'help(cv2)'? –

回答

5

我發現相應的變量可以在下面的包

cv2.cv 

發現如果使用CV_REDUCE_SUM操作上UINT8像你必須明確地提供更大的範圍D型參數,以避免溢出(如

slice = cv2.reduce(image, 1, cv2.cv.CV_REDUCE_SUM, dtype=numpy.int32) 

如果使用CV_REDUCE_AVG操作,結果不能溢出,這就是爲什麼設置D型是可選的。

+3

D類的參數會導致錯誤: '類型錯誤:一個整數required' 使用'cv2.CV_32S'代替。 – Nianliang

3

當前新的cv2庫存在一些缺陷。通常這些常量沒有被遷移到cv2,並且仍然只是cv。這裏有一些代碼可以幫助你找到它們:

import cv2 
import cv2.cv as cv 
nms = [(n.lower(), n) for n in dir(cv)] # list of everything in the cv module 
nms2 = [(n.lower(), n) for n in dir(cv2)] # list of everything in the cv2 module 

search = 'window' 

print "in cv2\n ",[m[1] for m in nms2 if m[0].find(search.lower())>-1] 
print "in cv\n ",[m[1] for m in nms if m[0].find(search.lower())>-1]