[英]Compute FAST features - openCV Python
I am using openCV 3.1.0 in Python 2.7. 我在Python 2.7中使用openCV 3.1.0。
I have successfully detected keypoints using the FAST detector. 我已经使用FAST检测器成功检测到关键点。 Now I would like to compute the features for each of these points using the FAST.compute() method.
现在,我想使用FAST.compute()方法为每个点计算特征。
However I did not manage to have this function running, it returns : 但是我没有设法让这个功能运行,它返回:
Traceback (most recent call last):
File "<ipython-input-82-1b8e23b25e3b>", line 1, in <module>
Fast.compute(Image8,Kp)
error: ..\..\..\modules\features2d\src\feature2d.cpp:144: error: (-213) in function cv::Feature2D::detectAndCompute
I haven't manage to run the detectAndCompute method work neither, even by playing the keypoints properties (like class_id...). 即使通过播放关键点属性(例如class_id ...),我也没有设法运行detectAndCompute方法都无法正常工作。 Thanks for the help,
谢谢您的帮助,
Here is the full code: 这是完整的代码:
# -*- coding: utf-8 -*-
import cv2
import matplotlib.pyplot as plt
import numpy as np
# Function for 16-bit to 8-bit conversion
def map_uint16_to_uint8(img, lower_bound=None, upper_bound=None):
'''
Map a 16-bit image trough a lookup table to convert it to 8-bit.
Parameters
----------
img: numpy.ndarray[np.uint16]
image that should be mapped
lower_bound: int, optional
lower bound of the range that should be mapped to ``[0, 255]``,
value must be in the range ``[0, 65535]`` and smaller than `upper_bound`
(defaults to ``numpy.min(img)``)
upper_bound: int, optional
upper bound of the range that should be mapped to ``[0, 255]``,
value must be in the range ``[0, 65535]`` and larger than `lower_bound`
(defaults to ``numpy.max(img)``)
Returns
-------
numpy.ndarray[uint8]
'''
if not(0 <= lower_bound < 2**16) and lower_bound is not None:
raise ValueError(
'"lower_bound" must be in the range [0, 65535]')
if not(0 <= upper_bound < 2**16) and upper_bound is not None:
raise ValueError(
'"upper_bound" must be in the range [0, 65535]')
if lower_bound is None:
lower_bound = np.min(img)
if upper_bound is None:
upper_bound = np.max(img)
if lower_bound >= upper_bound:
raise ValueError(
'"lower_bound" must be smaller than "upper_bound"')
lut = np.concatenate([
np.zeros(lower_bound, dtype=np.uint16),
np.linspace(0, 255, upper_bound - lower_bound).astype(np.uint16),
np.ones(2**16 - upper_bound, dtype=np.uint16) * 255
])
return lut[img].astype(np.uint8)
# Main
Image = cv2.imread("C:\Users\Laurent Thomas\Documents\Acquifer\DataSet\IM03_BISCHOFF_DORSAL_2ndGO\BrightField\WE00006---A006--PO01--LO001--CO6--SL001--PX32500--PW0040--IN0020--TM246--X059308--Y011163--Z215816--T1373998365.tif",-1)
Image8 = map_uint16_to_uint8(Image) # Conversion to 8-bit for FAST detection
ImageRGB = cv2.cvtColor(Image8,cv2.COLOR_GRAY2RGB) # RGB necessary if we want to see the detected points in color
# Get Keypoints
Fast = cv2.FastFeatureDetector_create()
Kp = Fast.detect(Image8)
# Overlay Keypoints on image
ImagePoint = cv2.drawKeypoints(ImageRGB,Kp,ImageRGB,color=(255,0,0),flags=4) # flag 4 to be able to plaw with the size of the detected spot
# View Overlay
plt.imshow(ImagePoint)
# Compute features
Features = Fast.compute(Image8,Kp)
Well apparently the FAST descriptor is not implemented like for the STAR descriptor. 显然,FAST描述符没有像STAR描述符那样实现。 Only the detection works : How to use STAR detector in openCV 3 with python?
仅检测有效: 如何在带有Python的openCV 3中使用STAR检测器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.