本文整理匯總了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()