日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python的特征提取实验一_在opencv3中使用ORB进行特征提取实验-Python版

發布時間:2023/12/18 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python的特征提取实验一_在opencv3中使用ORB进行特征提取实验-Python版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ORB (Oriented FAST and Rotated BRIEF)

分為兩部分:

特征點提取 -由FAST(Features from Accelerated Segment Test)算法發展來的

特征點描述 -根據BRIEF(Binary Robust IndependentElementary Features)特征描述算法改進的

具體不詳述,數學原理對我來說需要一段時間去理解消化,網上的相關的介紹也很多。這里先從實例開始,學習怎么用這個工具。

ORB特征提取實驗

基于opencv3.2.0的ORB特征提取試驗

import numpy as np

import cv2

img1 = cv2.imread("data/face1.jpg",0)#導入灰度圖像

img2 = cv2.imread("data/face2.jpg",0)

def drawMatches(img1, kp1, img2, kp2, matches):

rows1 = img1.shape[0]

cols1 = img1.shape[1]

rows2 = img2.shape[0]

cols2 = img2.shape[1]

out = np.zeros((max([rows1,rows2]),cols1 + cols2, 3),dtype = 'uint8')

#拼接圖像

out[:rows1, :cols1] = np.dstack([img1, img1,img1])

out[:rows2, cols1:] = np.dstack([img2, img2,img2])

for mat in matches:

img1_idx = mat.queryIdx

img2_idx = mat.trainIdx

(x1,y1) = kp1[img1_idx].pt

(x2,y2) = kp2[img2_idx].pt

#繪制匹配點

cv2.circle(out, (int(x1),int(y1)),4,(255,255,0),1)

cv2.circle(out,(int(x2)+cols1,int(y2)),4,(0,255,255),1)

cv2.line(out,(int(x1),int(y1)),(int(x2)+cols1,int(y2)),(255,0,0),1)

return out

detector = cv2.ORB_create()

kp1 = detector.detect(img1,None)

kp2 = detector.detect(img2,None)

kp1,des1 = detector.compute(img1,kp1)

kp2,des2 = detector.compute(img2,kp2)

bf = cv2.BFMatcher(cv2.NORM_HAMMING,crossCheck = True)

matches = bf.match(des1,des2)

img3 = drawMatches(img1,kp1,img2,kp2,matches[:50])

# img3 = cv2.drawKeypoints(img1,kp,None,color = (0,255,0),flags = 0)

cv2.imwrite("orbTest.jpg",img3)

cv2.imshow('orbTest',img3)

cv2.waitKey(0)

實驗結果:

orbResult.jpg

然后也可以對比下AKAZE,只要將改成

detector = cv2.ORB_create()

改成

detector = cv2.AKAZE_create()

效果圖:

orbResult_akaze.jpg

這里復習了一下Python特性之切片,在拼接圖片時用到了:

例如:

list[1:3],表示返回從位置1開始,包括位置2,但是停止在位置3的一個序列切片,因此返回一個含有兩個項目的切片。

out[:rows1, :cols1] 行:從0開始,到rows1之前;列:從0開始,到cols1之前

out[:rows2, cols1:] 行:從0開始,到rows2之前;列:從cols1開始,到最后

補充說明:

在opencv2中, orb = cv2.ORB ()是對的;

在opencv3中這樣會報錯,改成orb = cv2.ORB_create()就沒問題了。

總結

以上是生活随笔為你收集整理的python的特征提取实验一_在opencv3中使用ORB进行特征提取实验-Python版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。