我刚发现 SIFT 写了 Octave as packed value ( Octave 、层和音阶)。
我需要解压这个值,因为我必须将 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 函数来解压 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)
比如我检测 Pandas 上的sift kpts。
使用 unpackSiftOctave
解压筛选 kpts,获取( Octave 、层、比例)列表。部分解包结果。
[(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),
...
]
我是一名优秀的程序员,十分优秀!