欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python?OpenCV中的drawMatches()關(guān)鍵匹配繪制方法

 更新時間:2022年07月17日 14:47:40   作者:喬卿  
這篇文章主要介紹了Python?OpenCV中的drawMatches()關(guān)鍵匹配繪制方法,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的朋友可以參考一下

作用說明

該方法被用于繪制關(guān)鍵點的匹配情況。我們看到的許多匹配結(jié)果都是使用這一方法繪制的——一左一右兩張圖像,匹配的關(guān)鍵點之間用線條鏈接。

函數(shù)原型

cv.drawMatches(	img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg
cv.drawMatches(	img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchesThickness[, matchColor[, singlePointColor[, matchesMask[, flags]]]]	) -> outImg
cv.drawMatchesKnn(	img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg

參數(shù)詳解

  • img1:第一張原始圖像。
  • keypoints1:第一張原始圖像的關(guān)鍵點。
  • img2:第二張原始圖像。
  • keypoints2:第二張原始圖像的關(guān)鍵點。
  • matches1to2:從第一個圖像到第二個圖像的匹配,這意味著keypoints1[i]在keypoints2[Matches[i]中有一個對應(yīng)的點。
  • outImg:繪制結(jié)果圖像。
  • matchColor:匹配連線與關(guān)鍵點點的顏色,當(dāng)matchColor==Scalar::all(-1) 時,代表取隨機(jī)顏色。
  • singlePointColor:沒有匹配項的關(guān)鍵點的顏色,當(dāng)singlePointColor==Scalar::all(-1) 時,代表取隨機(jī)顏色。
  • matchesMask:確定繪制哪些匹配項的掩碼。如果掩碼為空,則繪制所有匹配項。
  • flags:繪圖功能的一些標(biāo)志。具體有:
    • cv.DRAW_MATCHES_FLAGS_DEFAULT
    • cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS
    • cv.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG
    • cv.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS 代碼實例
def bf_match(img_path1, img_path2):
    # 讀取兩張圖像
    img1 = cv2.imread(img_path1, cv2.IMREAD_GRAYSCALE)
    img2 = cv2.imread(img_path2, cv2.IMREAD_GRAYSCALE)

    # 計算兩張圖像的SIFT描述符
    kp1, des1, _ = sift_algorithm(img_path1)
    kp2, des2, _ = sift_algorithm(img_path2)

    # 創(chuàng)建BFMatcher實例
    bf = cv2.BFMatcher()

    # 獲得最佳匹配
    matches = bf.match(des1, des2)
    # 繪制匹配結(jié)果
    # matches = sorted(matches, key = lambda x:x.distance)
    match_result = cv2.drawMatches(img1, kp1, img2, kp2, matches, None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
    # 顯示繪制結(jié)果
    plt.imshow(match_result)
    plt.show()
    return match_result

結(jié)果

到此這篇關(guān)于Python OpenCV中的drawMatches()關(guān)鍵匹配繪制方法的文章就介紹到這了,更多相關(guān)Python OpenCV drawMatches() 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論