def generateImage(self, K, trans, imgsize): img = np.zeros( imgsize + (3,), np.uint8 ) depths = np.full(imgsize, float('inf')) K4 = Util.identity(4) K4[:-1,:-1] = K fullTrans = K4 * trans for p in self.points: tp = fullTrans * p.pt depth = tp[2, 0] if depth <= 0: continue coord = tuple( ( tp[1::-1] / depth ).getA1().tolist() ) if coord[0] >= 0 and coord[0] < imgsize[0] and coord[1] >= 0 and coord[1] < imgsize[1] and depth < depths[coord]: depths[coord] = depth img[coord] = p.color return img
def reconstruction(K, images): inv_K = np.linalg.inv(K) # find all direct transformations directTransforms = [] max_img_src = 1 for i, (imgA) in enumerate(images): for imgB in images[ i + 1 : i + 1 + max_img_src ]: print "\tLooking for direct transformation from " + str(imgB.index) + " to " + str(imgA.index) matPoints = imgA.matchesToDeepPoints(imgB, imgA.buildMatches(imgB, True), inv_K) print "\t\tMatches found: " + str(len(matPoints)) trans, vote_matches = Util.RANSAC( matPoints, 3, Util.buildDirectTransformation, Util.testTransform, 0.002, 10000, 0.5 * len(matPoints) ) if len(vote_matches) > 0: directTransforms.append( Transformation.Transformation( trans, len(vote_matches), [ imgA.index, imgB.index ] ) ) print "\t\tDirect transformation found!" else: print "\t\tUnable to find a direct transformation!" print "\tDirect transformation search completed. Searching for combinational paths . . ." combinationTransforms = Transformation.searchForPaths(0, xrange( 1, len(images) ), directTransforms, 27) cloudTransforms = [ Transformation.Transformation(Util.identity(4), 1, [0,0]) ] + Transformation.getBestTransformations( 0, xrange(1, len(images)), directTransforms + combinationTransforms ) print "\tAll transformations identified. Combining point clouds . . ." pointCloud = Point.PointCloud() for i, img in enumerate(images): print "\t\tAdding points from image " + str(i) points = img.getAllPoints( inv_K, cloudTransforms[i].getMatrix() ) pointCloud.addPoints(points) print "\tPoint cloud combination finished with " + str(len(pointCloud.points)) + " total points" return pointCloud, cloudTransforms