好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > python opencv實現圖像配準與比較

python opencv實現圖像配準與比較

熱門標簽:千呼ai電話機器人免費 高德地圖標注字母 400電話辦理費用收費 深圳網絡外呼系統代理商 柳州正規電銷機器人收費 騰訊地圖標注有什么版本 申請辦個400電話號碼 外呼系統前面有錄音播放嗎 鎮江人工外呼系統供應商

本文實例為大家分享了python opencv實現圖像配準與比較的具體代碼,供大家參考,具體內容如下

代碼 

from skimage import io
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
 
img_path1 = '2_HE_maxarea.png'
img_path2 = '2_IHC_maxarea.png'
 
img1 = io.imread(img_path1)
img2 = io.imread(img_path2)
img1 = np.uint8(img1)
img2 = np.uint8(img2)
 
# find the keypoints and descriptors with ORB
orb = cv.ORB_create()
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
 
# def get_good_match(des1,des2):
#  bf = cv.BFMatcher()
#  matches = bf.knnMatch(des1, des2, k=2)
#  good = []
#  for m, n in matches:
#   if m.distance  0.75 * n.distance:
#    good.append(m)
#  return good,matches
# goodMatch,matches = get_good_match(des1,des2)
# img3 = cv.drawMatchesKnn(img1,kp1,img2,kp2,matches[:20],None,flags=2)
 
# create BFMatcher object
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 20 matches.
img3 = cv.drawMatches(img1,kp1,img2,kp2,matches[:20],None, flags=2)
 
 
goodMatch = matches[:20]
if len(goodMatch) > 4:
 ptsA= np.float32([kp1[m.queryIdx].pt for m in goodMatch]).reshape(-1, 1, 2)
 ptsB = np.float32([kp2[m.trainIdx].pt for m in goodMatch]).reshape(-1, 1, 2)
 ransacReprojThreshold = 4
 H, status =cv.findHomography(ptsA,ptsB,cv.RANSAC,ransacReprojThreshold);
 #其中H為求得的單應性矩陣矩陣
 #status則返回一個列表來表征匹配成功的特征點。
 #ptsA,ptsB為關鍵點
 #cv2.RANSAC, ransacReprojThreshold這兩個參數與RANSAC有關
 imgOut = cv.warpPerspective(img2, H, (img1.shape[1],img1.shape[0]),flags=cv.INTER_LINEAR + cv.WARP_INVERSE_MAP)
 
# 疊加配準變換圖與基準圖
rate = 0.5
overlapping = cv.addWeighted(img1, rate, imgOut, 1-rate, 0)
io.imsave('HE_2_IHC.png', overlapping)
err = cv.absdiff(img1,imgOut) 
 
# 顯示對比
plt.subplot(221)
plt.title('orb')
plt.imshow(img3)
 
plt.subplot(222)
plt.title('imgOut')
plt.imshow(imgOut)
 
plt.subplot(223)
plt.title('overlapping')
plt.imshow(overlapping)
 
plt.subplot(224)  
plt.title('diff') 
plt.imshow(err)
 
plt.show()

結果:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 利用Python+OpenCV三步去除水印
  • Python基于opencv的簡單圖像輪廓形狀識別(全網最簡單最少代碼)
  • Python OpenCV中的numpy與圖像類型轉換操作
  • Python+OpenCV圖像處理——圖像二值化的實現
  • Python+OpenCV圖像處理——實現直線檢測
  • 使用OpenCV為圖像加水印的教程

標簽:海南 烏蘭察布 平頂山 烏蘭察布 郴州 大慶 合肥 哈爾濱

巨人網絡通訊聲明:本文標題《python opencv實現圖像配準與比較》,本文關鍵詞  python,opencv,實現,圖像,配準,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《python opencv實現圖像配準與比較》相關的同類信息!
  • 本頁收集關于python opencv實現圖像配準與比較的相關信息資訊供網民參考!
  • 推薦文章