【问题标题】:OpenCV (Python) unpack SIFT OctaveOpenCV (Python) 解压 SIFT Octave
【发布时间】:2018-07-01 07:48:55
【问题描述】:

我刚刚发现 SIFT 写入 Octave as packed value(八度、层和比例)。
我需要解压这个值,因为我必须将 SIFT 检测器与其他描述符(ORB、BRIEF、SURF、BRISK)结合使用。 Here你可以找到类似的问题。
我已经尝试了不同的解决方案(参见下面的代码),但似乎没有一个在 python 中有效(this one 也是如此)。
有什么建议吗?

unpackOctave(keypoints[i], octave, layer, scale)     

或:

unpackOctave(const KeyPoint& kpt, int& octave, int& layer, float& scale){    
    octave = kpt.octave & 255;    
    layer = (kpt.octave >> 8) & 255;    
    octave = octave < 128 ? octave : (-128 | octave);    
    scale = octave >= 0 ? 1.f/(1 << octave) : (float)(1 << -octave);    
}

【问题讨论】:

    标签: python opencv sift


    【解决方案1】:

    我定义了一个 Python 函数来解压 SIFT Octave:

    #!/usr/bin/python3
    ## 2018.01.23 11:12:30 CST
    ## created by Silencer
    
    def unpackSIFTOctave(kpt):
        """unpackSIFTOctave(kpt)->(octave,layer,scale)
        @created by Silencer at 2018.01.23 11:12:30 CST
        @brief Unpack Sift Keypoint by Silencer
        @param kpt: cv2.KeyPoint (of SIFT)
        """
        _octave = kpt.octave
        octave = _octave&0xFF
        layer  = (_octave>>8)&0xFF
        if octave>=128:
            octave |= -128
        if octave>=0:
            scale = float(1/(1<<octave))
        else:
            scale = float(1<<-octave)
        return (octave, layer, scale)
    

    例如,我检测熊猫上的 sift kpts。

    使用unpackSiftOctave解包sift kpts,得到(八度、层、尺度)的列表。部分解压结果。

    [(0, 3, 1.0),
     (1, 3, 0.5),
     (-1, 3, 2.0),
     (-1, 3, 2.0),
     (2, 1, 0.25),
     (2, 1, 0.25),
     (-1, 1, 2.0),
     (-1, 1, 2.0),
     (0, 2, 1.0),
     (1, 3, 0.5),
     ...
    ]
    

    【讨论】:

    • -1 的八度是什么意思?
    • @RachitBhargava 2^octave * scale = 1。octave = -1, scale = 2, resized 2x。
    【解决方案2】:

    Kinght 的回答似乎是正确的,但我只想补充一点,我能够在 Github repository 中找到 unpackOctave(keypoint) 方法的良好实现,该方法在 Python 中实现了用于关键点检测和描述的整个 SIFT 算法。它非常有助于理解 SIFT 并亲自动手(如果你熟悉 Python),它附带了 two part 教程。

    这就是他们实现 unpackOctave(keypoint) 方法的方式——非常类似于原始的 C 实现(也与 Kinght 的回答)。

    def unpackOctave(keypoint):
        """Compute octave, layer, and scale from a keypoint
        """
        octave = keypoint.octave & 255
        layer = (keypoint.octave >> 8) & 255
        if octave >= 128:
            octave = octave | -128
        scale = 1 / float32(1 << octave) if octave >= 0 else float32(1 << -octave)
        return octave, layer, scale
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 2013-01-02
      • 2020-05-20
      • 2021-07-21
      相关资源
      最近更新 更多