我在Python 2.7中使用openCV 3.1.0 我已经使用FAST检测器成功检测到了关键点。现在我想使用FAST.compute()方法计算每个点的特征 但是我没有设法运行此函数,它返回:
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
即使通过播放关键点属性(如class_id ...),我也无法运行detectAndCompute方法。 谢谢你的帮助,
以下是完整代码:
# -*- 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)
答案 0 :(得分:0)
很明显,FAST描述符没有像STAR描述符那样实现。只有检测工作: How to use STAR detector in openCV 3 with python?