本文整理汇总了Python中cv2.cornerHarris方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.cornerHarris方法的具体用法?Python cv2.cornerHarris怎么用?Python cv2.cornerHarris使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.cornerHarris方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_harris_corners
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def display_harris_corners(input_img):
"""
computes corners in colored image and plot it.
"""
# first convert to grayscale with float32 values
gray = cv2.cvtColor(input_img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
# using opencv harris corner implementation
corners = cv2.cornerHarris(gray,2,7,0.04)
# # result is dilated for marking the corners, not important
# dst = cv2.dilate(dst,None)
# additional thresholding and marking corners for plotting
input_img[corners>0.01*corners.max()]=[255,0,0]
return input_img
# # plot image
# plt.figure(figsize=(12, 8))
# plt.imshow(cv2.cvtColor(input_img, cv2.COLOR_BGR2RGB))
# plt.axis('off')
示例2: harris_loader
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def harris_loader(image, name, **config):
num_features = config.get('num_features', 0)
do_nms = config.get('do_nms', False)
nms_thresh = config.get('nms_thresh', 4)
detect_map = cv2.cornerHarris(image.astype(np.uint8), 4, 3, 0.04)
kpts = np.where(detect_map > 1e-6)
scores = detect_map[kpts]
kpts = np.stack([kpts[1], kpts[0]], axis=-1)
if do_nms:
keep = nms_fast(kpts, scores, image.shape[:2], nms_thresh)
kpts, scores = kpts[keep], scores[keep]
if num_features:
keep_indices = np.argsort(scores)[::-1][:num_features]
kpts, scores = [i[keep_indices] for i in [kpts, scores]]
return {'keypoints': kpts, 'scores': scores}
示例3: detect
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def detect(self, img):
# convert our input image to a floating point data type and then
# compute the Harris corner matrix
gray = np.float32(img)
H = cv2.cornerHarris(gray, self.blockSize, self.apertureSize, self.k)
# for every (x, y)-coordinate where the Harris value is above the
# threshold, create a keypoint (the Harris detector returns
# keypoint size a 3-pixel radius)
kps = np.argwhere(H > self.T * H.max())
kps = [cv2.KeyPoint(pt[1], pt[0], 3) for pt in kps]
# return the Harris keypoints
return kps
示例4: cornerDetection
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def cornerDetection(inputImg_edge):
imgCorners=cv2.imread(inputImg_edge)
imgGray=cv2.cvtColor(imgCorners,cv2.COLOR_BGR2GRAY) #将图像转换为灰度,为每一像素位置1个值,可理解为图像的强度(颜色,易受光照影响,难以提供关键信息,故将图像进行灰度化,同时也可以加快特征提取的速度。)
imgGray=np.float32(imgGray) #强制转换为浮点值,用于棱角检测
imgHarris=cv2.cornerHarris(imgGray,7,5,0.04) #哈里斯角检测器 Harris corner detector
print(imgHarris.max(),imgHarris.shape)
imgHarris=cv2.dilate(imgHarris,np.ones((1,1))) #放大棱角标记
print(imgCorners[300:500,])
imgCorners[imgHarris>0.01*imgHarris.max()]=[40,75,236] #定义阈值,显示重要的棱角
cv2.imshow('harris corners',imgCorners)
cv2.imwrite(os.path.join(rootDirectory,'harris corners.jpg'),imgCorners)
cv2.waitKey()
#SIFT(scale invariant feature transform 尺度不变特征变换)特征点检测
示例5: detect_and_compute_harris_np
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def detect_and_compute_harris_np(img,num):
smooth_img = cv2.GaussianBlur(img, (5, 5), 1.5)
if len(smooth_img.shape)==3:
smooth_img=cv2.cvtColor(smooth_img, cv2.COLOR_RGB2GRAY)
harris_img = cv2.cornerHarris(smooth_img.astype(np.float32), 2, 3, 0.04)
element=np.sort(harris_img.flatten())[-num]
mask=harris_img>=element
hs,ws=np.nonzero(mask)
kps=np.concatenate([ws[:,None],hs[:,None]],1)
des=np.zeros([kps.shape[0],128],np.float32)
return kps, des
示例6: get_harris_corners
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def get_harris_corners (self, image):
"""
Function: get_harris_corners
----------------------------
given an image, returns a list of cv2.KeyPoints representing
the harris corners
"""
return cv2.cornerHarris(image,2,3,0.04)
示例7: compute_harris_corners
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cornerHarris [as 别名]
def compute_harris_corners(input):
gray = cv2.cvtColor(input,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,5,0.04)
#result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)
# Threshold for an optimal value, it may vary depending on the image.
input[dst>0.01*dst.max()]=[0,255,0]
plt.figure(figsize=(12, 8))
plt.imshow(cv2.cvtColor(input, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.show()