示例#1
0
def AugmentImage(img):
    #The following does not utilize the global variables and was made before
    #the optimisation for live augmentation.

    I1 = cv2.imread("pattern.png")
    I2 = img
    I1Gray = cv2.cvtColor(I1,cv2.COLOR_RGB2GRAY)
    I2Gray = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)

    I1Corners = getCornerCoords(I1Gray)
    I2Corners = getCornerCoords(I2Gray)

    H = estimateHomography(I1Corners, I2Corners)

    K, dist_coefs = calibrate.loadMatrixes()

    box = cube_points((0,0,0),0.3)

    #This is K * [I | O]
    cam1 = Camera(hstack((K,dot(K,array([[0],[0],[-1]])) )) )

    # compute second camera matrix from cam1.
    cam2 = Camera(dot(H,cam1.P))

    #isolates the [Rotation | translation] (extrinsic parameters)
    A = dot(linalg.inv(K),cam2.P[:,:3])
    #estimate z axis from cross product.
    A = array([A[:,0],A[:,1],np.cross(A[:,0],A[:,1],axis=0)]).T

    #add K again
    cam2.P[:,:3] = np.dot(K,A[0])

    # project with the second camera
    box_cam2 = np.array(cam2.project(toHomogenious(box)))

    figure()
    imshow(I2)
    plot(box_cam2[0,:],box_cam2[1,:],linewidth=3)
    show()
示例#2
0
__author__ = 'Roed, Ghurt, Stoffi'
import calibrationExample as calibrate
import numpy as np
from SIGBToolsForSecond import *
import cv2
import cv

global K, dist_coefs, I1, I1Corners, box, cam1

I1 = cv2.imread("pattern.png")

I1Gray = cv2.cvtColor(I1,cv2.COLOR_RGB2GRAY)
K, dist_coefs = calibrate.loadMatrixes()


def cube_points(c,wid):
    """ Creates a list of points for plotting a cube with plot. (the first 5 points are
    the bottom square, some sides repeated). """
    p = []
    #bottom
    p.append([c[0]-wid,c[1]-wid,c[2]-wid])
    p.append([c[0]-wid,c[1]+wid,c[2]-wid])
    p.append([c[0]+wid,c[1]+wid,c[2]-wid])
    p.append([c[0]+wid,c[1]-wid,c[2]-wid])
    p.append([c[0]-wid,c[1]-wid,c[2]-wid])
    #top
    p.append([c[0]-wid,c[1]-wid,c[2]+wid])
    p.append([c[0]-wid,c[1]+wid,c[2]+wid])
    p.append([c[0]+wid,c[1]+wid,c[2]+wid])
    p.append([c[0]+wid,c[1]-wid,c[2]+wid])
    p.append([c[0]-wid,c[1]-wid,c[2]+wid])