python特徵點匹配(python查找特徵數)

本文目錄一覽:

Python中正則表達式的匹配規則總結

其他關於Python的總結文章請訪問:

正則表達式用來匹配字符串,在python中可以使用 re 模塊來完成,本篇做一個對正則表達式的匹配規則的總結

在上述的精確匹配後可以跟上一些符號來進行模糊的匹配:

可以使用中括號的形式進行範圍匹配,中括號表達式後邊可以跟上上述模糊匹配的符號來表示數量

多個條件可以 緊跟着寫在同一個中括號中 ,比如:

[a-zA-Z] :匹配一個大、小寫字母

python指紋圖像細化後如何進行特徵點匹配

thin’這個參數就指定了對二值圖像BW進行細化操作,inf(無窮大)這個參數說的是對圖像一直進行細化,直到圖像不再發生變化為止。

Python編程語言有哪些特徵?

Python語言的主要特徵如下:

①Python語法優雅,程序編碼簡單易讀。

②Python易上手,通過簡單的操作就能讓你寫的程序運行。Python非常適合用來做原型開發或其他專門的編碼任務,同時又不用為了維護而煩惱。

③Python擁有大量的標準庫來支持一般的編碼任務,例如連接網絡服務器、用正則表達式搜索文字、讀取和修改文件等。

④Python的交互模式可以很方便地檢測代碼片段。同時Python其實也自帶了一個叫做IDLE的集成開發環境,初學者可以利用它方便地創建、運行、測試和調試Python程序。

⑤Python通過添加新的模塊可以很容易進行擴展,這些模塊可以是通過類似C或C++等編譯型語言執行應用的。注意,Python是解釋型腳本語言。

⑥Python也可以被嵌入應用中來提供一個可編程的接口。

⑦Python可以在任何環境運行,包括Mac OS X,Windows,Linux和Unix,通過非官方的構建,也可以在android和ios上運行。

⑧Python雙重免費。首先下載和使用或是在你的應用中內置Python是完全免費的。其次Python可以被自由修改然後再發布,因為語言是完全開源的。

Python如何實現圖片特徵點匹配

python-opencv-特徵點匹配連線(畫線)drawMatches

Python 沒有OpenCV 2.4.13版本的cv2.drawMatches(),無法直接使用,故可參看本文第2節的drawMatches函數使用

Python 有OpenCV 3.0.0版本的cv2.drawMatches(),可以直接使用

1、drawMatches數據結構(opencv2.4.13)

Draws the found matches of keypoints from two images.

C++:

void drawMatches(const Mat img1, const vectorKeyPoint keypoints1, const Mat img2, const vectorKeyPoint keypoints2, const vectorvectorDMatch matches1to2, Mat outImg, const Scalar matchColor=Scalar::all(-1), const Scalar singlePointColor=Scalar::all(-1), const vectorvectorchar matchesMask=vectorvectorchar (), int flags=DrawMatchesFlags::DEFAULT )1

Parameters: 

img1 – First source image.

keypoints1 – Keypoints from the first source image.

img2 – Second source image.

keypoints2 – Keypoints from the second source image.

matches1to2 – Matches from the first image to the second one, which means that keypoints1[i] has a corresponding point in keypoints2[matches[i]] . 

outImg – Output image. Its content depends on the flags value defining what is drawn in the output image. See possible flags bit values below.

matchColor – Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1) , the color is generated randomly. 

singlePointColor – Color of single keypoints (circles), which means that keypoints do not have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly.

matchesMask – Mask determining which matches are drawn. If the mask is empty, all matches are drawn.

flags – Flags setting drawing features. Possible flags bit values are defined by DrawMatchesFlags. 

This function draws matches of keypoints from two images in the output image. Match is a line connecting two keypoints (circles). The structure DrawMatchesFlags is defined as follows:

struct DrawMatchesFlags

{

   enum

   {

       DEFAULT = 0, // Output image matrix will be created (Mat::create),

                    // i.e. existing memory of output image may be reused.

                    // Two source images, matches, and single keypoints

                    // will be drawn.

                    // For each keypoint, only the center point will be

                    // drawn (without a circle around the keypoint with the

                    // keypoint size and orientation).

       DRAW_OVER_OUTIMG = 1, // Output image matrix will not be

                      // created (using Mat::create). Matches will be drawn

                      // on existing content of output image.

       NOT_DRAW_SINGLE_POINTS = 2, // Single keypoints will not be drawn.

       DRAW_RICH_KEYPOINTS = 4 // For each keypoint, the circle around

                      // keypoint with keypoint size and orientation will

                      // be drawn.

   };};1234567891011121314151617181920

2、drawMatches(python實現)

# -*- coding: utf-8 -*-“””

Created on Tue Dec 27 09:32:02 2016

@author:

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

   “””

   My own implementation of cv2.drawMatches as OpenCV 2.4.9

   does not have this function available but it’s supported in

   OpenCV 3.0.0

   This function takes in two images with their associated

   keypoints, as well as a list of DMatch data structure (matches)

   that contains which keypoints matched in which images.

   An image will be produced where a montage is shown with

   the first image followed by the second image beside it.

   Keypoints are delineated with circles, while lines are connected

   between matching keypoints.

   img1,img2 – Grayscale images

   kp1,kp2 – Detected list of keypoints through any of the OpenCV keypoint

             detection algorithms

   matches – A list of matches of corresponding keypoints through any

             OpenCV keypoint matching algorithm

   “””

   # Create a new output image that concatenates the two images together

   # (a.k.a) a montage

   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′)    # Place the first image to the left

   out[:rows1,:cols1] = np.dstack([img1, img1, img1])    # Place the next image to the right of it

   out[:rows2,cols1:] = np.dstack([img2, img2, img2])    # For each pair of points we have between both images

   # draw circles, then connect a line between them

   for mat in matches:        # Get the matching keypoints for each of the images

       img1_idx = mat.queryIdx

       img2_idx = mat.trainIdx        # x – columns

       # y – rows

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

       (x2,y2) = kp2[img2_idx].pt        # Draw a small circle at both co-ordinates

       # radius 4

       # colour blue

       # thickness = 1

       a = np.random.randint(0,256)

       b = np.random.randint(0,256)

       c = np.random.randint(0,256)

       cv2.circle(out, (int(np.round(x1)),int(np.round(y1))), 2, (a, b, c), 1)      #畫圓,cv2.circle()參考官方文檔

       cv2.circle(out, (int(np.round(x2)+cols1),int(np.round(y2))), 2, (a, b, c), 1)        # Draw a line in between the two points

       # thickness = 1

       # colour blue

       cv2.line(out, (int(np.round(x1)),int(np.round(y1))), (int(np.round(x2)+cols1),int(np.round(y2))), (a, b, c), 1, lineType=cv2.CV_AA, shift=0)  #畫線,cv2.line()參考官方文檔

   # Also return the image if you’d like a copy

   return out

Python正則表達式的幾種匹配方法

1.測試正則表達式是否匹配字符串的全部或部分

regex=ur”” #正則表達式

if re.search(regex, subject):

do_something()

else:

do_anotherthing()

2.測試正則表達式是否匹配整個字符串

regex=ur”/Z” #正則表達式末尾以/Z結束

if re.match(regex, subject):

do_something()

else:

do_anotherthing()

3.創建一個匹配對象,然後通過該對象獲得匹配細節(Create an object with details about how the regex matches (part of) a string)

regex=ur”” #正則表達式

match = re.search(regex, subject)

if match:

# match start: match.start()

# match end (exclusive): atch.end()

# matched text: match.group()

do_something()

else:

do_anotherthing()

4.獲取正則表達式所匹配的子串(Get the part of a string matched by the regex)

regex=ur”” #正則表達式

match = re.search(regex, subject)

if match:

result = match.group()

else:

result = “”

OpenCV-Python之——圖像SIFT特徵提取

在一定的範圍內,無論物體是大還是小,人眼都可以分辨出來。然而計算機要有相同的能力卻不是那麼的容易,在未知的場景中,計算機視覺並不能提供物體的尺度大小,其中的一種方法是把物體不同尺度下的圖像都提供給機器,讓機器能夠對物體在不同的尺度下有一個統一的認知。在建立統一認知的過程中,要考慮的就是在圖像在不同的尺度下都存在的特徵點。

在早期圖像的多尺度通常使用圖像金字塔表示形式。圖像金字塔是同一圖像在不同的分辨率下得到的一組結果其生成過程一般包括兩個步驟:

多分辨率的圖像金字塔雖然生成簡單,但其本質是降採樣,圖像的局部特徵則難以保持,也就是無法保持特徵的尺度不變性。

我們還可以通過圖像的模糊程度來模擬人在距離物體由遠到近時物體在視網膜上成像過程,距離物體越近其尺寸越大圖像也越模糊,這就是高斯尺度空間,使用不同的參數模糊圖像(分辨率不變),是尺度空間的另一種表現形式。

構建尺度空間的目的是為了檢測出在不同的尺度下都存在的特徵點,而檢測特徵點較好的算子是Δ^2G(高斯拉普拉斯,LoG)

使用LoG雖然能較好的檢測到圖像中的特徵點,但是其運算量過大,通常可使用DoG(差分高斯,Difference of Gaussina)來近似計算LoG。

從上式可以知道,將相鄰的兩個高斯空間的圖像相減就得到了DoG的響應圖像。為了得到DoG圖像,先要構建高斯尺度空間,而高斯的尺度空間可以在圖像金字塔降採樣的基礎上加上高斯濾波得到,也就是對圖像金字塔的每層圖像使用不同的參數σ進行高斯模糊,使每層金字塔有多張高斯模糊過的圖像。

如下圖,octave間是降採樣關係,且octave(i+1)的第一張(從下往上數)圖像是由octave(i)中德倒數第三張圖像降採樣得到。octave內的圖像大小一樣,只是高斯模糊使用的尺度參數不同。

對於一幅圖像,建立其在不同尺度scale下的圖像,也稱為octave,這是為了scale-invariant,也就是在任何尺度都能有對應的特徵點。下圖中右側的DoG就是我們構建的尺度空間。

為了尋找尺度空間的極值點,每一個採樣點要和它所有的相鄰點比較,看其是否比它的圖像域和尺度域的相鄰點大或者小。如圖所示,中間的檢測點和它同尺度的8個相鄰點和上下相鄰尺度對應的9×2個點共26個點比較,以確保在尺度空間和二維圖像空間都檢測到極值點。 一個點如果在DOG尺度空間本層以及上下兩層的26個領域中是最大或最小值時,就認為該點是圖像在該尺度下的一個特徵點。下圖中將叉號點要比較的26個點都標為了綠色。

找到所有特徵點後, 要去除低對比度和不穩定的邊緣效應的點 ,留下具有代表性的關鍵點(比如,正方形旋轉後變為菱形,如果用邊緣做識別,4條邊就完全不一樣,就會錯誤;如果用角點識別,則穩定一些)。去除這些點的好處是增強匹配的抗噪能力和穩定性。最後,對離散的點做曲線擬合,得到精確的關鍵點的位置和尺度信息。

近來不斷有人改進,其中最著名的有 SURF(計算量小,運算速度快,提取的特徵點幾乎與SIFT相同)和 CSIFT(彩色尺度特徵不變變換,顧名思義,可以解決基於彩色圖像的SIFT問題)。

其中sift.detectAndCompute()函數返回kp,des。

上圖dog的shape為(481, 500, 3),提取的特徵向量des的shape為(501, 128),501個128維的特徵點。

該方法可以在特徵點處繪製一個小圓圈。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/257207.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-15 12:44
下一篇 2024-12-15 12:44

相關推薦

  • 如何查看Anaconda中Python路徑

    對Anaconda中Python路徑即conda環境的查看進行詳細的闡述。 一、使用命令行查看 1、在Windows系統中,可以使用命令提示符(cmd)或者Anaconda Pro…

    編程 2025-04-29
  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python列表中負數的個數

    Python列表是一個有序的集合,可以存儲多個不同類型的元素。而負數是指小於0的整數。在Python列表中,我們想要找到負數的個數,可以通過以下幾個方面進行實現。 一、使用循環遍歷…

    編程 2025-04-29
  • Python中引入上一級目錄中函數

    Python中經常需要調用其他文件夾中的模塊或函數,其中一個常見的操作是引入上一級目錄中的函數。在此,我們將從多個角度詳細解釋如何在Python中引入上一級目錄的函數。 一、加入環…

    編程 2025-04-29
  • Python計算陽曆日期對應周幾

    本文介紹如何通過Python計算任意陽曆日期對應周幾。 一、獲取日期 獲取日期可以通過Python內置的模塊datetime實現,示例代碼如下: from datetime imp…

    編程 2025-04-29
  • Python清華鏡像下載

    Python清華鏡像是一個高質量的Python開發資源鏡像站,提供了Python及其相關的開發工具、框架和文檔的下載服務。本文將從以下幾個方面對Python清華鏡像下載進行詳細的闡…

    編程 2025-04-29
  • 蝴蝶優化算法Python版

    蝴蝶優化算法是一種基於仿生學的優化算法,模仿自然界中的蝴蝶進行搜索。它可以應用於多個領域的優化問題,包括數學優化、工程問題、機器學習等。本文將從多個方面對蝴蝶優化算法Python版…

    編程 2025-04-29
  • python強行終止程序快捷鍵

    本文將從多個方面對python強行終止程序快捷鍵進行詳細闡述,並提供相應代碼示例。 一、Ctrl+C快捷鍵 Ctrl+C快捷鍵是在終端中經常用來強行終止運行的程序。當你在終端中運行…

    編程 2025-04-29
  • Python字典去重複工具

    使用Python語言編寫字典去重複工具,可幫助用戶快速去重複。 一、字典去重複工具的需求 在使用Python編寫程序時,我們經常需要處理數據文件,其中包含了大量的重複數據。為了方便…

    編程 2025-04-29
  • Python程序需要編譯才能執行

    Python 被廣泛應用於數據分析、人工智能、科學計算等領域,它的靈活性和簡單易學的性質使得越來越多的人喜歡使用 Python 進行編程。然而,在 Python 中程序執行的方式不…

    編程 2025-04-29

發表回復

登錄後才能評論