changeset 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 f67b4f892195
children 9f7a4a026dab
files trafficintelligence/cvutils.py trafficintelligence/utils.py
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
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)
 
         
 #########################
--- a/trafficintelligence/utils.py	Mon Jun 21 22:55:29 2021 -0400
+++ b/trafficintelligence/utils.py	Tue Jul 06 00:28:24 2021 -0400
@@ -11,7 +11,7 @@
 from scipy.stats import rv_continuous, kruskal, shapiro, lognorm, norm, t, chi2_contingency
 from scipy.spatial import distance
 from scipy.sparse import dok_matrix
-from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve,  dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit, float as npfloat
+from numpy import zeros, array, exp, sum as npsum, int64 as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve,  dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit
 from numpy.random import random_sample, permutation as nppermutation
 from pandas import DataFrame, concat, crosstab
 import matplotlib.pyplot as plt