【问题标题】:What is the format of the mask for OpenCV's Python ORB module?OpenCV 的 Python ORB 模块的掩码格式是什么?
【发布时间】:2016-06-27 08:59:10
【问题描述】:

我一直在尝试使用 ORB 来查找关键点/描述符,并且我需要屏蔽部分图像,因为我的图像的两个部分中的许多特征非常相似。但是,我无法确定检测和计算函数的掩码参数的正确格式,并且文档对我来说模棱两可。我尝试查看源代码,但我对 C++ 不够熟悉,无法理解它。我认为这只是一个二进制数组,其中 1 = 使用和 0 = 忽略,但我尝试过的每个掩码都不会返回任何关键点。下面是一些示例代码:

img1_gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2_gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
#ignore the left half of the first image
mask1 = np.ones(img1_gray.shape)
mask1[:,:mask1.shape[1]/2] = 0
#ignore the right half of the second image
mask2 = np.ones(img2_gray.shape)
mask2[:,mask2.shape[1]/2:] = 0
kp1, des1 =orb.detectAndCompute(img1_gray,mask1)
kp2, des2 =orb.detectAndCompute(img2_gray,mask2)

文档在这里:http://docs.opencv.org/3.0-beta/modules/features2d/doc/feature_detection_and_description.html

img1 img2

【问题讨论】:

  • 如果你包含一些代码和一些图像可能会更好..

标签: python c++ opencv


【解决方案1】:

我在 OpenCV C++ 中使用过 orb,如果我没记错的话,掩码必须是值为 0 和 255 的 CV_8UC1 类型(至少这是我使用的)。你有没有这样尝试过?

【讨论】:

  • 已确认。谢谢。我遇到的错误是我提交了CV_8UC3 类型的掩码。在 Python 包装器中,这不会引发任何错误,结果是检测器不会检测到任何兴趣点。
【解决方案2】:

ORB 非常适合检测图像上的模式或查找图像重复项,但对于此类任务,ORB 可能信息量不足,因为它被设计为快速且轻量级的二进制描述符。试试看SIFTSURF

【讨论】:

  • 虽然这可能是真的,但这并不能回答实际问题。
【解决方案3】:

上述代码中的错误是掩码必须更改为 Uint8。因此,这会将掩码更改为值为 0 到 255 的 CV_8UC1 类型。这是使用 SIFT 功能而不是 ORB 功能的经过全面测试的工作 Python 代码(版本 3):

import cv2
import numpy as np 
import matplotlib.pyplot as plt

def showing_features(img1, key_points):
   plt.imshow(cv2.drawKeypoints(img1, key_points, None))
   plt.show() 

img1 = cv2.imread('img1.jpg')
img2 = cv2.imread('img2.jpg')

img1_gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2_gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

sift= cv2.xfeatures2d.SIFT_create(nfeatures=0,
                            nOctaveLayers=3,
                            contrastThreshold=0.05,
                            edgeThreshold=10.0,
                            sigma=1.6)

"*-------------- Create Masks --------------*"
mask1 = np.ones(img1_gray.shape)
#ignore the left half of the first image
mask1[:,:int(mask1.shape[1]/2)] = 0
#ignore the right half of the second image
mask2 = np.ones(img2_gray.shape)
mask2[:,int(mask2.shape[1]/2):] = 0

"*-------------- Change Masks to Uint8 --------------*"
mask1 = mask1.astype(np.uint8)
mask2 = mask2.astype(np.uint8)

"*-------------- Extract SIFT Features --------------*"
kp1m, des1m =sift.detectAndCompute(img1_gray,mask1)
kp2m, des2m =sift.detectAndCompute(img2_gray,mask2)

"*-------------- Display SIFT features after using MASK --------------*"
showing_features(img1, kp1m)
showing_features(img2, kp2m)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2013-01-11
    • 2019-07-25
    • 2012-10-19
    • 2012-05-16
    • 1970-01-01
    相关资源
    最近更新 更多