Python cv2.cornerHarris() Examples
The following are 7
code examples of cv2.cornerHarris().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: 04_base.py From Practical-Computer-Vision with MIT License | 6 votes |
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')
Example #2
Source File: loaders.py From hfnet with MIT License | 6 votes |
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}
Example #3
Source File: detector.py From GIFT with Apache License 2.0 | 5 votes |
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
Example #4
Source File: harris.py From imutils with MIT License | 5 votes |
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
Example #5
Source File: CVAnalyzer.py From DE3-ROB1-CHESS with Creative Commons Attribution 4.0 International | 5 votes |
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)
Example #6
Source File: 04_base.py From Practical-Computer-Vision with MIT License | 5 votes |
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()
Example #7
Source File: opencv_py.py From python-urbanPlanning with MIT License | 5 votes |
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 尺度不变特征变换)特征点检测