通過閱讀計算器上的幾個答案,我多學會爲止這樣的:OpenCV的,Python的:如何使用面膜參數ORB特徵檢測器
面具必須是一個numpy
陣列(具有相同形狀爲圖像),數據類型爲CV_8UC1
,值爲0
至255
。
這些數字是什麼意思?是否在檢測過程中忽略具有相應掩碼值爲零的任何像素,並且將使用掩碼值爲255的任何像素?它們之間的值呢?
另外,我如何初始化一個numpy
陣列與數據類型CV_8UC1
在python中?我可以只使用dtype=cv2.CV_8UC1
下面是我目前使用的代碼,基於我上面所做的假設。但問題是,當我爲任一圖像運行detectAndCompute
時,我沒有得到任何關鍵點。我有一種感覺可能是因爲掩碼不是正確的數據類型。如果我說得對,那我該如何糾正?
# convert images to grayscale
base_gray = cv2.cvtColor(self.base, cv2.COLOR_BGRA2GRAY)
curr_gray = cv2.cvtColor(self.curr, cv2.COLOR_BGRA2GRAY)
# initialize feature detector
detector = cv2.ORB_create()
# create a mask using the alpha channel of the original image--don't
# use transparent or partially transparent parts
base_cond = self.base[:,:,3] == 255
base_mask = np.array(np.where(base_cond, 255, 0))
curr_cond = self.base[:,:,3] == 255
curr_mask = np.array(np.where(curr_cond, 255, 0), dtype=np.uint8)
# use the mask and grayscale images to detect good features
base_keys, base_desc = detector.detectAndCompute(base_gray, mask=base_mask)
curr_keys, curr_desc = detector.detectAndCompute(curr_gray, mask=curr_mask)
print("base keys: ", base_keys)
# []
print("curr keys: ", curr_keys)
# []
「我該如何初始化numpy數組」 - 您是否嘗試閱讀[numpy關於數據類型的文檔](https://docs.scipy.org/doc/numpy/user/basics.types.html) ? –
問題是,CV_8UC1對應的列表上的數據類型是什麼?我傾向於相信這是因爲8和U,但我還沒有找到任何文件證實這一點。問題是我沒有從 –
http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html - 第一段獲得任何關鍵點。你說得對,'uint8'。 |檢查口罩並確保它們有意義。 –