diff python/cvutils.py @ 936:56cc8a1f7082

removed all old versions of projection methods
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 14 Jul 2017 16:48:42 -0400
parents 0e63a918a1ca
children e5970606066f
line wrap: on
line diff
--- a/python/cvutils.py	Fri Jul 14 16:30:57 2017 -0400
+++ b/python/cvutils.py	Fri Jul 14 16:48:42 2017 -0400
@@ -333,7 +333,6 @@
                                 obj.projectedPositions = obj.getPositions().homographyProject(homography)
                                 if undistort:
                                     obj.projectedPositions = obj.projectedPositions.newCameraProject(newCameraMatrix)
-                                #obj.projectedPositions = obj.positions
                             cvPlot(img, obj.projectedPositions, cvColors[colorType][obj.getNum()], frameNum-obj.getFirstInstant())
                             if frameNum not in boundingBoxes.keys() and obj.hasFeatures():
                                 yCropMin, yCropMax, xCropMin, xCropMax = imageBoxSize(obj, frameNum, homography, width, height)
@@ -577,70 +576,6 @@
     else:
         return points
 
-def projectArray(homography, points, intrinsicCameraMatrix = None, distortionCoefficients = None, newCameraMatrix = None):
-    '''Returns the coordinates of the projected points through homography
-    (format: array 2xN points)'''
-    if points.shape[0] != 2:
-        raise Exception('points of dimension {}'.format(points.shape))
-
-    augmentedPoints = append(points,[[1]*points.shape[1]], 0) # 3xN
-    if homography is not None and homography.size>0:
-        prod = dot(homography, augmentedPoints)
-        projected = prod/prod[2]
-    else:
-        projected = augmentedPoints
-
-    if intrinsicCameraMatrix is not None and distortionCoefficients is not None:
-        if newCameraMatrix is not None:
-            invNewCameraMatrix = inv(newCameraMatrix)
-            reducedPoints = dot(invNewCameraMatrix, projected)
-        else:
-            reducedPoints = projected
-        projected, jacobian = cv2.projectPoints(reducedPoints.T, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients) # in: 3xN, out: 2x1xN
-        projected = projected.reshape(-1,2).T
-    return projected[:2,:]
-
-def project(homography, p, intrinsicCameraMatrix = None, distortionCoefficients = None, newCameraMatrix = None):
-    '''Returns the coordinates of the projection of the point p with coordinates p[0], p[1]
-    through homography'''
-    return projectArray(homography, array([[p[0]],[p[1]]]), intrinsicCameraMatrix, distortionCoefficients, newCameraMatrix)
-
-def projectTrajectory(homography, trajectory, intrinsicCameraMatrix = None, distortionCoefficients = None, newCameraMatrix = None):
-    '''Projects a series of points in the format
-    [[x1, x2, ...],
-    [y1, y2, ...]]'''
-    return projectArray(homography, array(trajectory), intrinsicCameraMatrix, distortionCoefficients, newCameraMatrix)
-
-def invertHomography(homography):
-    '''Returns an inverted homography
-    Unnecessary for reprojection over camera image'''
-    invH = inv(homography)
-    invH /= invH[2,2]
-    return invH
-
-def undistortTrajectory(invMap1, invMap2, positions):
-    floorPositions = npfloor(positions)
-    #ceilPositions = npceil(positions)
-    undistortedTrajectory = [[],[]]
-    for i in xrange(len(positions[0])):
-        x,y = None, None
-        if positions[0][i]+1 < invMap1.shape[1] and positions[1][i]+1 < invMap1.shape[0]:
-            floorX = invMap1[floorPositions[1][i], floorPositions[0][i]]
-            floorY = invMap2[floorPositions[1][i], floorPositions[0][i]]
-            ceilX = invMap1[floorPositions[1][i]+1, floorPositions[0][i]+1]
-            ceilY = invMap2[floorPositions[1][i]+1, floorPositions[0][i]+1]
-            #ceilX = invMap1[ceilPositions[1][i], ceilPositions[0][i]]
-            #ceilY = invMap2[ceilPositions[1][i], ceilPositions[0][i]]
-            if floorX >=0 and floorY >=0 and ceilX >=0 and ceilY >=0:
-                x = floorX+(positions[0][i]-floorPositions[0][i])*(ceilX-floorX)
-                y = floorY+(positions[1][i]-floorPositions[1][i])*(ceilY-floorY)
-        undistortedTrajectory[0].append(x)
-        undistortedTrajectory[1].append(y)
-    return undistortedTrajectory
-
-def projectGInputPoints(homography, points):
-    return projectTrajectory(homography, array(points+[points[0]]).T)
-
 if opencvAvailable:
     def computeTranslation(img1, img2, img1Points, maxTranslation2, minNMatches, windowSize = (5,5), level = 5, criteria = (cv2.TERM_CRITERIA_EPS, 0, 0.01)):
         '''Computes the translation of img2 with respect to img1