diff trafficintelligence/cvutils.py @ 1168:d71a4d174b1a

corrected potential bug with dtype in image to world projection
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 06 Jul 2021 00:28:24 -0400
parents 7eb972942f22
children 2f89dc3d99e5
line wrap: on
line diff
--- a/trafficintelligence/cvutils.py	Mon Jun 21 22:55:29 2021 -0400
+++ b/trafficintelligence/cvutils.py	Tue Jul 06 00:28:24 2021 -0400
@@ -7,7 +7,7 @@
 from math import floor, log10, ceil
 from time import time
 
-from numpy import dot, array, append, float32, loadtxt, savetxt, append, zeros, ones, identity, abs as npabs, logical_and, unravel_index, sum as npsum, isnan, mgrid, median, floor as npfloor, ceil as npceil, nonzero
+from numpy import dot, array, append, float32, loadtxt, savetxt, append, zeros, ones, identity, abs as npabs, logical_and, unravel_index, sum as npsum, isnan, mgrid, median, floor as npfloor, ceil as npceil, nonzero, dtype
 from numpy.linalg import inv
 from matplotlib.pyplot import imread, imsave, imshow, figure, subplot
 
@@ -71,7 +71,7 @@
 
 def loadPointCorrespondences(filename):
     '''Loads and returns the corresponding points in world (first 2 lines) and image spaces (last 2 lines)'''
-    points = loadtxt(filename, dtype=float32)
+    points = loadtxt(filename, dtype=dtype('float32'))
     return  (points[:2,:].T, points[2:,:].T) # (world points, image points)
 
 def cvMatToArray(cvmat):
@@ -559,7 +559,9 @@
     2. through homograph projection (from ideal point (no camera) to world)'''
     if points.shape[0] != 2:
         raise Exception('points of dimension {}'.format(points.shape))
-
+    if points.dtype != dtype('float64'):
+        points = array(points, dtype = dtype('float64'))
+        
     if intrinsicCameraMatrix is not None and distortionCoefficients is not None:
         undistortedPoints = cv2.undistortPoints(points.T.reshape(1,points.shape[1], 2), intrinsicCameraMatrix, distortionCoefficients).reshape(-1,2)
         return homographyProject(undistortedPoints.T, homography)
@@ -643,7 +645,7 @@
             inputData.append(features)
 
         nImages = len(inputData)
-        return array(inputData, dtype = float32), array([classLabel]*nImages)
+        return array(inputData, dtype = dtype('float32')), array([classLabel]*nImages)
 
         
 #########################