This code here outputs two graphs. Read the code and give the title for those two…
- User
This code here outputs two graphs. Read the code and give the title for those two graphs. Here is the code: import os import cv2 import numpy as np from utils.bundleAjust import bundleAdjustment from utils.dense import denseMatch, denseReconstruction, outputPly from utils.fundamental import default, ransacimplementation from utils.getPose import getPose from utils.graph import createGraph, triangulateGraph, showGraph, visualizeDense from utils.mergeGraph import mergeG, removeOutlierPts from utils.paresDescript import getPairSIFT
#Credits SFMedu: Structrue From Motion for Education Purpose
% Written by Jianxiong Xiao (MIT License)
def mergeAllGraph(gL,imsize): graphMerged = gL[0] # merge partial views for i in range(len(gL) - 1): graphMerged = updateMerged(graphMerged, gL[i+1],imageSize) return graphMerged def updateMerged(gA,gB,imsize): gt = mergeG(gA, gB) gt = triangulateGraph(gt, imsize) gt = bundleAdjustment(gt, False) gt = removeOutlierPts(gt, 10) gt = bundleAdjustment(gt) return gt
if name == "main":
#---------------------------SET PARAMETERS maxSize = 640 #maximum image resolution carpetaImagenes = 'data/sfM_Images/' debug = False outName = 'pc1' # ouput name for ply file (open with mesh lab to see pointcloud) validFile = ['jpg','png','JPG'] #valid image types f = 2082.7179 # Find this from the image metadata (EXIF) # f = 719.5459 # ---------------------------SET PARAMETERS algoMatrizFundamental = ransacimplementation graphList = [] #Upload images listaArchivos = os.listdir(carpetaImagenes) listaArchivos = sorted(listaArchivos, reverse=False) print(listaArchivos) listaImages = filter(lambda x : x.split('.')[-1] in validFile,listaArchivos ) #Load the images listaImages = [] for fname in listaArchivos: listaImages.append(cv2.imread(carpetaImagenes+fname)) imageSize = listaImages[0].shape print ("original dimensions ",imageSize) #todo Scale the image if it goes over maxSize if imageSize[0] > maxSize: print ("Scaling") print ("Size image ",imageSize," max size ",maxSize) #480 640 function # listaImages = map(lambda x: np.transpose(cv2.resize(x,(640,480)),axes=[1,0,2]), listaImages) listaImages = list(map(lambda x: np.transpose(cv2.resize(x,(1280,720)),axes=[1,0,2]), listaImages)) imageSize = listaImages[0].shape print ("Result size ",imageSize) #Calculate K K = np.eye(3) K[0][0] = f K[1][1] = f graphList = [0 for i in range(len(listaImages)-1)] #calculate pairs from SIFT or other local descriptor #calculated as successive images print ("Start calculating SIFT pairs") for i in range(len(listaImages)-1): keypointsA,keypointsB = getPairSIFT(listaImages[i],listaImages[i+1],show=debug) #Calculate the fundamental matrix or the essential matrix #TODO get the essentials if type(keypointsA[0]) == np.ndarray: assert(len(keypointsA.shape) == 2) assert (len(keypointsB.shape) == 2) pointsA = keypointsA pointsB = keypointsB else: pointsA = np.array([(keypointsA[idx].pt) for idx in range(len(keypointsA))]).reshape(-1, 1, 2) pointsB = np.array([(keypointsB[idx].pt) for idx in range(len(keypointsB))]).reshape(-1, 1, 2) pointsA = pointsA[:,[1,0]] pointsB = pointsB[:, [1, 0]] F = np.array(algoMatrizFundamental(pointsA,pointsB)) Fmat = F[0] K = np.array(K) E = np.dot(np.transpose(K),np.dot(Fmat,K)) # get camera pose Rtbest = getPose(E,K, np.hstack([pointsA,pointsB]),imageSize) #create graph graphList[i] = createGraph(i,i+1,K, pointsA, pointsB, Rtbest, f) #Triangular graphList[i] = triangulateGraph(graphList[i],imageSize) #visualize graph # showGraph(graphList[i],imageSize) #Bundle ajustement graphList[i]=bundleAdjustment(graphList[i]) #Visualize with improvements # showGraph(graphList[i], imageSize) gM = mergeAllGraph(graphList,imageSize) print ("Graph merge finished") #View partial result showGraph(gM,imageSize) #Dense matching for i in range(len(listaImages)-1): graphList[i] = denseMatch(graphList[i],listaImages[i], listaImages[i+1], imageSize, imageSize) print ("Dense match ended") print ("Initializing dense Triangulation") #Dense reconstruction for i in range(len(listaImages) - 1): print (i) graphList[i] = denseReconstruction(graphList[i], gM,K,imageSize) print ("Dense rebuild finished") data = visualizeDense(graphList, gM, imageSize) outputPly(data,outName). - Assistant
Title of Graph 1: Partial 3D reconstruction of views with camera poses and point clouds (before dense reconstruction)
Title of Graph 2: Final 3D reconstruction of views with camera poses and point clouds (after dense reconstruction)