我刚刚发现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);
}
答案 0 :(得分: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)
例如,我在熊猫上发现了裂缝。
使用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 :(得分:1)
Kinght的答案似乎是正确的,但我想补充一下,我能够在Github repository中找到unpackOctave(keypoint)
方法的良好实现,该方法实现了整个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