午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

python 實現Harris角點檢測算法

瀏覽:176日期:2022-07-02 14:39:53
算法流程: 將圖像轉換為灰度圖像 利用Sobel濾波器求出 海森矩陣 (Hessian matrix) :

python 實現Harris角點檢測算法

將高斯濾波器分別作用于Ix²、Iy²、IxIy 計算每個像素的 R= det(H) - k(trace(H))²。det(H)表示矩陣H的行列式,trace表示矩陣H的跡。通常k的取值范圍為[0.04,0.16]。 滿足 R>=max(R) * th 的像素點即為角點。th常取0.1。Harris算法實現:

import cv2 as cv import numpy as npimport matplotlib.pyplot as plt# Harris corner detectiondef Harris_corner(img):## Grayscaledef BGR2GRAY(img):gray = 0.2126 * img[..., 2] + 0.7152 * img[..., 1] + 0.0722 * img[..., 0]gray = gray.astype(np.uint8)return gray## Sobeldef Sobel_filtering(gray):# get shapeH, W = gray.shape# sobel kernelsobely = np.array(((1, 2, 1),(0, 0, 0),(-1, -2, -1)), dtype=np.float32)sobelx = np.array(((1, 0, -1),(2, 0, -2),(1, 0, -1)), dtype=np.float32)# paddingtmp = np.pad(gray, (1, 1), ’edge’)# prepareIx = np.zeros_like(gray, dtype=np.float32)Iy = np.zeros_like(gray, dtype=np.float32)# get differentialfor y in range(H):for x in range(W):Ix[y, x] = np.mean(tmp[y : y + 3, x : x + 3] * sobelx)Iy[y, x] = np.mean(tmp[y : y + 3, x : x + 3] * sobely)Ix2 = Ix ** 2Iy2 = Iy ** 2Ixy = Ix * Iyreturn Ix2, Iy2, Ixy# gaussian filteringdef gaussian_filtering(I, K_size=3, sigma=3):# get shapeH, W = I.shape## gaussianI_t = np.pad(I, (K_size // 2, K_size // 2), ’edge’)# gaussian kernelK = np.zeros((K_size, K_size), dtype=np.float)for x in range(K_size):for y in range(K_size):_x = x - K_size // 2_y = y - K_size // 2K[y, x] = np.exp( -(_x ** 2 + _y ** 2) / (2 * (sigma ** 2)))K /= (sigma * np.sqrt(2 * np.pi))K /= K.sum()# filteringfor y in range(H):for x in range(W):I[y,x] = np.sum(I_t[y : y + K_size, x : x + K_size] * K)return I# corner detectdef corner_detect(gray, Ix2, Iy2, Ixy, k=0.04, th=0.1):# prepare output imageout = np.array((gray, gray, gray))out = np.transpose(out, (1,2,0))# get RR = (Ix2 * Iy2 - Ixy ** 2) - k * ((Ix2 + Iy2) ** 2)# detect cornerout[R >= np.max(R) * th] = [255, 0, 0]out = out.astype(np.uint8)return out# 1. grayscalegray = BGR2GRAY(img)# 2. get difference imageIx2, Iy2, Ixy = Sobel_filtering(gray)# 3. gaussian filteringIx2 = gaussian_filtering(Ix2, K_size=3, sigma=3)Iy2 = gaussian_filtering(Iy2, K_size=3, sigma=3)Ixy = gaussian_filtering(Ixy, K_size=3, sigma=3)# 4. corner detectout = corner_detect(gray, Ix2, Iy2, Ixy)return out# Read imageimg = cv.imread('../qiqiao.jpg').astype(np.float32)# Harris corner detectionout = Harris_corner(img)cv.imwrite('out.jpg', out)cv.imshow('result', out)cv.waitKey(0)cv.destroyAllWindows()實驗結果:

原圖:

python 實現Harris角點檢測算法

Harris角點檢測算法檢測結果:

python 實現Harris角點檢測算法

以上就是python 實現Harris角點檢測算法的詳細內容,更多關于python Harris角點檢測算法的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 一级特黄aa大片欧美 | 日日草视频 | 一级欧美片| 成人精品免费 | 久久91视频| 人人玩人人干 | 中文字幕天堂在线 | 亚洲天堂精品在线 | 99热.com | 懂色av,蜜臀av粉嫩av | 国产又粗又硬又长 | www久久久久久 | 国产一级片在线 | 伊人再见免费在线观看高清版 | 成人豆奶视频 | 免费一二三区 | 免费爱爱视频网站 | 人人看av | 超碰精品在线 | 黄色一极毛片 | 四虎网站最新网址 | 黄视频在线播放 | 欧美资源在线 | 久久永久视频 | 免费在线观看视频 | 第四色av | 黄色污网站在线观看 | 国产伦精品一区 | 欧美黄大片 | 五月婷婷免费视频 | 野性的青春 | 天堂中文av | 蜜挑成熟时在线观看 | 五月婷婷丁香在线 | 免费在线观看一区 | 国产欧美日韩综合精品 | 亚洲va在线 | 新中文字幕 | 日韩在线精品 | 毛片在线免费观看视频 | 日韩av综合在线 |