日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

多视几何

發布時間:2024/1/8 编程问答 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 多视几何 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

多視圖幾何是主要研究用幾何的方法,通過若干幅多視圖幾何二維圖像,來恢復三維物體。間言之就是研究三維重構。
1.對極幾何基礎概念
核點(epipole):基線(baseline)與成像平面的交點。同時極點也可以理解為相鄰影像成像中心在本影像上的像,因為基線是兩個相鄰影像成像中心的連線。
核平面(epipolar plane):含有基線的平面,是一簇平面。可以看做是由基線與空間中任意一點構成的平面。
核線(epipolar line):核平面與成像平面的交線??梢钥醋鍪浅上衿矫嫔系娜我庖稽c(非核點)與核點所定義的直線。

2. 基礎矩陣 F
基礎矩陣可以看做是將點投影(轉換)為直線,將左影像上的一個點投影到右影像上形成一條核線。
基礎矩陣表示的是圖像中的像點p1到另一幅圖像對極線l2的映射,有如下公式:

而和像點P1P1匹配的另一個像點p2必定在對極線l2上,所以就有:

這樣僅通過匹配的點對,就可以計算出兩視圖的基礎矩陣F。
基礎矩陣FF是一個3×3的矩陣,有9個未知元素,由于尺度是任意的,所以只需要8個方程。因為算法中需要8個對應點來計算基礎矩陣F,所以該算法叫做八點法。

3.8點法估算基礎矩陣F
由于基礎矩陣 F 定義為

任給兩幅圖像中的匹配點 x 與 x’,令


有相應方程:

最后得到AF=0.

4.實驗過程

#!/usr/bin/env python # coding: utf-8# In[1]: from PIL import Image from numpy import * from pylab import * import numpy as np from imp import reload# In[2]: import importlib from PCV.geometry import camera from PCV.geometry import homography from PCV.geometry import sfm from PCV.localdescriptors import siftcamera = importlib.reload(camera) homography = importlib.reload(homography) sfm = importlib.reload(sfm) sift =importlib.reload(sift)# In[3]:# Read features im1 = array(Image.open('image5/1.jpg')) sift.process_image('image5/1.jpg', 'im1.sift') l1, d1 = sift.read_features_from_file('im1.sift')im2 = array(Image.open('image5/2.jpg')) sift.process_image('image5/2.jpg', 'im2.sift') l2, d2 = sift.read_features_from_file('im2.sift')# In[9]:matches = sift.match_twosided(d1, d2)# In[10]:ndx = matches.nonzero()[0] x1 = homography.make_homog(l1[ndx, :2].T) ndx2 = [int(matches[i]) for i in ndx] x2 = homography.make_homog(l2[ndx2, :2].T)x1n = x1.copy() x2n = x2.copy()# In[11]:print (len(ndx))# In[12]:figure(figsize=(16,16)) sift.plot_matches(im1, im2, l1, l2, matches, True) show()# In[13]:# Chapter 5 Exercise 1 # Don't use K1, and K2#def F_from_ransac(x1, x2, model, maxiter=5000, match_threshold=1e-6): def F_from_ransac(x1, x2, model, maxiter=5000, match_threshold=1e-6):""" Robust estimation of a fundamental matrix F from pointcorrespondences using RANSAC (ransac.py fromhttp://www.scipy.org/Cookbook/RANSAC).input: x1, x2 (3*n arrays) points in hom. coordinates. """from PCV.tools import ransacdata = np.vstack((x1, x2))d = 20 # 20 is the original# compute F and return with inlier indexF, ransac_data = ransac.ransac(data.T, model,8, maxiter, match_threshold, d, return_all=True)return F, ransac_data['inliers']# In[15]:# find E through RANSAC model = sfm.RansacModel() F, inliers = F_from_ransac(x1n, x2n, model, maxiter=5000, match_threshold=1e-3)# In[16]:print (len(x1n[0])) print (len(inliers))# In[17]:P1 = array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]) P2 = sfm.compute_P_from_fundamental(F)# In[18]:# triangulate inliers and remove points not in front of both cameras X = sfm.triangulate(x1n[:, inliers], x2n[:, inliers], P1, P2)# In[19]:# plot the projection of X cam1 = camera.Camera(P1) cam2 = camera.Camera(P2) x1p = cam1.project(X) x2p = cam2.project(X)# In[20]:figure() imshow(im1) gray() plot(x1p[0], x1p[1], 'o') #plot(x1[0], x1[1], 'r.') axis('off')figure() imshow(im2) gray() plot(x2p[0], x2p[1], 'o') #plot(x2[0], x2[1], 'r.') axis('off') show()# In[21]:figure(figsize=(16, 16)) im3 = sift.appendimages(im1, im2) im3 = vstack((im3, im3))imshow(im3)cols1 = im1.shape[1] rows1 = im1.shape[0] for i in range(len(x1p[0])):if (0<= x1p[0][i]<cols1) and (0<= x2p[0][i]<cols1) and (0<=x1p[1][i]<rows1) and (0<=x2p[1][i]<rows1):plot([x1p[0][i], x2p[0][i]+cols1],[x1p[1][i], x2p[1][i]],'c') axis('off') show()# In[22]:print (F)# In[23]:# Chapter 5 Exercise 2x1e = [] x2e = [] ers = [] for i,m in enumerate(matches):if m>0: #plot([locs1[i][0],locs2[m][0]+cols1],[locs1[i][1],locs2[m][1]],'c')p1 = array([l1[i][0], l1[i][1], 1])p2 = array([l2[m][0], l2[m][1], 1])# Use Sampson distance as errorFx1 = dot(F, p1)Fx2 = dot(F, p2)denom = Fx1[0]**2 + Fx1[1]**2 + Fx2[0]**2 + Fx2[1]**2e = (dot(p1.T, dot(F, p2)))**2 / denomx1e.append([p1[0], p1[1]])x2e.append([p2[0], p2[1]])ers.append(e) x1e = array(x1e) x2e = array(x2e) ers = array(ers)# In[24]:indices = np.argsort(ers) x1s = x1e[indices] x2s = x2e[indices] ers = ers[indices] x1s = x1s[:20] x2s = x2s[:20]# In[25]:figure(figsize=(16, 16)) im3 = sift.appendimages(im1, im2) im3 = vstack((im3, im3))imshow(im3)cols1 = im1.shape[1] rows1 = im1.shape[0] for i in range(len(x1s)):if (0<= x1s[i][0]<cols1) and (0<= x2s[i][0]<cols1) and (0<=x1s[i][1]<rows1) and (0<=x2s[i][1]<rows1):plot([x1s[i][0], x2s[i][0]+cols1],[x1s[i][1], x2s[i][1]],'c') axis('off') show()# In[ ]:

室外結果如下:

注:拍攝照片時要注意圖片的景深,否則運行中很容易出現問題。
室外結果如下圖




得到的基礎矩陣為

參考博客:https://www.cnblogs.com/wangguchangqing/p/8214032.html
https://www.cnblogs.com/JingeTU/p/6390915.html

總結

以上是生活随笔為你收集整理的多视几何的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。