python調(diào)用stitcher類自動(dòng)實(shí)現(xiàn)多個(gè)圖像拼接融合功能
使用stitcher需要注意,圖像太大會(huì)報(bào)錯(cuò)而且計(jì)算慢。
特點(diǎn)和適用范圍:圖像需有足夠重合相同特征區(qū)域。
優(yōu)點(diǎn):適應(yīng)部分傾斜/尺度變換和畸變情形,拼接效果好,使用簡(jiǎn)單,可以一次拼接多張圖片。
缺點(diǎn):需要有足夠的相同特征區(qū)域進(jìn)行匹配,速度較慢(和圖像大小有關(guān))。
原圖(可下載)
代碼(兩張圖片拼接)
import sysimport cv2 if __name__ == '__main__': img1 = cv2.imread(’C:/Users/Guaguan/Desktop/img/1.jpg’) # 圖片絕對(duì)路徑, img2 = cv2.imread(’C:/Users/Guaguan/Desktop/img/2.jpg’) # stitcher = cv2.createStitcher(False) # 老的OpenCV版本,用這一個(gè) stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA) # 我的是OpenCV4 (status, pano) = stitcher.stitch((img1, img2)) if status != cv2.Stitcher_OK:print('不能拼接圖片, error code = %d' % status)sys.exit(-1) print('拼接成功.') cv2.imshow(’pano’, pano) # cv2.imwrite('pano.jpg', pano) cv2.waitKey(0)
拼接結(jié)果
原圖
代碼(多個(gè)圖像自動(dòng)拼接)
import osimport sysimport cv2import win32ui # ? python基于Stitcher圖像拼接 def imgstitcher(imgs): # 傳入圖像數(shù)據(jù) 列表[] 實(shí)現(xiàn)圖像拼接 stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA) _result, pano = stitcher.stitch(imgs) if _result != cv2.Stitcher_OK:print('不能拼接圖片, error code = %d' % _result)sys.exit(-1) output = ’result’ + ’.png’ cv2.imwrite(output, pano) print('拼接成功. %s 已保存!' % output) if __name__ == '__main__': # imgPath為圖片所在的文件夾相對(duì)路徑 imgPath = ’C:/Users/Guaguan/Desktop/img’imgList = os.listdir(imgPath) imgs = [] for imgName in imgList:pathImg = os.path.join(imgPath, imgName)img = cv2.imread(pathImg)if img is None: print('圖片不能讀取:' + imgName) sys.exit(-1)imgs.append(img) imgstitcher(imgs) # 拼接 cv2.waitKey(0) cv2.destroyAllWindows()
結(jié)果
到此這篇關(guān)于python調(diào)用stitcher類自動(dòng)實(shí)現(xiàn)多個(gè)圖像拼接融合的文章就介紹到這了,更多相關(guān)python圖像拼接融合內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法2. IntelliJ IDEA設(shè)置編碼格式的方法3. Python OpenCV去除字母后面的雜線操作4. Spring security 自定義過(guò)濾器實(shí)現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實(shí)例代碼)5. IntelliJ IDEA設(shè)置背景圖片的方法步驟6. docker /var/lib/docker/aufs/mnt 目錄清理方法7. Python TestSuite生成測(cè)試報(bào)告過(guò)程解析8. Python 的 __str__ 和 __repr__ 方法對(duì)比9. JAMon(Java Application Monitor)備忘記10. 增大python字體的方法步驟
