【发布时间】:2018-01-30 07:32:15
【问题描述】:
通过阅读有关stackoverflow的一些答案,到目前为止我已经学到了很多:
掩码必须是numpy 数组(与图像具有相同的形状),数据类型为CV_8UC1,值从0 到255。
但是,这些数字的含义是什么?是否会在检测过程中忽略相应掩码值为 0 的像素,而使用掩码值为 255 的任何像素?两者之间的值呢?
另外,如何在 python 中初始化数据类型为CV_8UC1 的numpy 数组?我可以使用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 documentation on data types?
-
问题是,CV_8UC1 对应于该列表中的哪种数据类型?由于 8 和 U,我倾向于相信它是 uint8,尽管我还没有找到任何证实这一点的文档。问题是我没有从中得到任何关键点
-
docs.opencv.org/2.4/modules/core/doc/basic_structures.html -- 第一段。你没看错,
uint8。 |检查面具并确保它们有意义。
标签: python opencv numpy feature-detection