真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

python如何將兩張圖片生成為全景圖片-創(chuàng)新互聯(lián)

本文實例為大家分享了python將兩張圖片生成全景圖片的具體代碼,供大家參考,具體內(nèi)容如下

成都創(chuàng)新互聯(lián)專注骨干網(wǎng)絡服務器租用10年,服務更有保障!服務器租用,溫江服務器托管 成都服務器租用,成都服務器托管,骨干網(wǎng)絡帶寬,享受低延遲,高速訪問。靈活、實現(xiàn)低成本的共享或公網(wǎng)數(shù)據(jù)中心高速帶寬的專屬高性能服務器。

1、全景圖片的介紹

全景圖通過廣角的表現(xiàn)手段以及繪畫、相片、視頻、三維模型等形式,盡可能多表現(xiàn)出周圍的環(huán)境。360全景,即通過對專業(yè)相機捕捉整個場景的圖像信息或者使用建模軟件渲染過后的圖片,使用軟件進行圖片拼合,并用專門的播放器進行播放,即將平面照片或者計算機建模圖片變?yōu)?60 度全觀,用于虛擬現(xiàn)實瀏覽,把二維的平面圖模擬成真實的三維空間,呈現(xiàn)給觀賞者。

2、如何實現(xiàn)

2.1、實現(xiàn)原理

主要是利用sift的特征提取與匹配,參考鏈接

2.2、實現(xiàn)代碼

# -*- coding:utf-8 -*-
u'''
Created on 2019年6月14日
@author: wuluo
'''
__author__ = 'wuluo'
__version__ = '1.0.0'
__company__ = u'重慶交大'
__updated__ = '2019-06-14'
import numpy as np
import cv2 as cv
from PIL import Image
from matplotlib import pyplot as plt
print('cv version: ', cv.__version__)

def pinjie():
 top, bot, left, right = 100, 100, 0, 500
 img1 = cv.imread('G:/2018and2019two/qianrushi/wuluo1.png')
 cv.imshow("img1", img1)
 img2 = cv.imread('G:/2018and2019two/qianrushi/wuluo2.png')
 cv.imshow("img2", img2)
 srcImg = cv.copyMakeBorder(
  img1, top, bot, left, right, cv.BORDER_CONSTANT, value=(0, 0, 0))
 testImg = cv.copyMakeBorder(
  img2, top, bot, left, right, cv.BORDER_CONSTANT, value=(0, 0, 0))
 img1gray = cv.cvtColor(srcImg, cv.COLOR_BGR2GRAY)
 img2gray = cv.cvtColor(testImg, cv.COLOR_BGR2GRAY)
 sift = cv.xfeatures2d_SIFT().create()
 # find the keypoints and descriptors with SIFT
 kp1, des1 = sift.detectAndCompute(img1gray, None)
 kp2, des2 = sift.detectAndCompute(img2gray, None)
 # FLANN parameters
 FLANN_INDEX_KDTREE = 1
 index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
 search_params = dict(checks=50)
 flann = cv.FlannBasedMatcher(index_params, search_params)
 matches = flann.knnMatch(des1, des2, k=2)
 
 # Need to draw only good matches, so create a mask
 matchesMask = [[0, 0] for i in range(len(matches))]

 good = []
 pts1 = []
 pts2 = []
 # ratio test as per Lowe's paper
 for i, (m, n) in enumerate(matches):
  if m.distance < 0.7 * n.distance:
   good.append(m)
   pts2.append(kp2[m.trainIdx].pt)
   pts1.append(kp1[m.queryIdx].pt)
   matchesMask[i] = [1, 0]

 draw_params = dict(matchColor=(0, 255, 0),
      singlePointColor=(255, 0, 0),
      matchesMask=matchesMask,
      flags=0)
 img3 = cv.drawMatchesKnn(img1gray, kp1, img2gray,
        kp2, matches, None, **draw_params)
 #plt.imshow(img3, ), plt.show()

 rows, cols = srcImg.shape[:2]
 MIN_MATCH_COUNT = 10
 if len(good) > MIN_MATCH_COUNT:
  src_pts = np.float32(
   [kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
  dst_pts = np.float32(
   [kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
  M, mask = cv.findHomography(src_pts, dst_pts, cv.RANSAC, 5.0)
  warpImg = cv.warpPerspective(testImg, np.array(
   M), (testImg.shape[1], testImg.shape[0]), flags=cv.WARP_INVERSE_MAP)

  for col in range(0, cols):
   if srcImg[:, col].any() and warpImg[:, col].any():
    left = col
    break
  for col in range(cols - 1, 0, -1):
   if srcImg[:, col].any() and warpImg[:, col].any():
    right = col
    break

  res = np.zeros([rows, cols, 3], np.uint8)
  for row in range(0, rows):
   for col in range(0, cols):
    if not srcImg[row, col].any():
     res[row, col] = warpImg[row, col]
    elif not warpImg[row, col].any():
     res[row, col] = srcImg[row, col]
    else:
     srcImgLen = float(abs(col - left))
     testImgLen = float(abs(col - right))
     alpha = srcImgLen / (srcImgLen + testImgLen)
     res[row, col] = np.clip(
      srcImg[row, col] * (1 - alpha) + warpImg[row, col] * alpha, 0, 255)

  # opencv is bgr, matplotlib is rgb
  res = cv.cvtColor(res, cv.COLOR_BGR2RGB)
  # show the result
  plt.figure()
  plt.imshow(res)
  plt.show()
 else:
  print("Not enough matches are found - {}/{}".format(len(good), MIN_MATCH_COUNT))
  matchesMask = None

if __name__ == "__main__":
 pinjie()

文章題目:python如何將兩張圖片生成為全景圖片-創(chuàng)新互聯(lián)
瀏覽路徑:http://weahome.cn/article/gehid.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部