Guest User

Untitled

a guest
Jun 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import numpy as np
  2. import h5py
  3. import cv2
  4. from extract_nvm import extract
  5.  
  6. class Data():
  7. def __init__(self):
  8. self.coordinates = np.zeros((1,7))
  9. self.images = np.zeros((1,480,640,3))
  10.  
  11. def load(self):
  12. pass
  13.  
  14. def save(self, dset_name):
  15.  
  16. self.images = np.asarray(self.images)
  17.  
  18. self.coordinates = np.array(self.coordinates, dtype='float16')
  19.  
  20. h5f = h5py.File(dset_name, 'w')
  21. h5f.create_dataset('X', data=self.images)
  22. h5f.create_dataset('Y', data=self.coordinates)
  23.  
  24. h5f.close()
  25.  
  26. def string_from_integer(integer):
  27. integer = str(integer)
  28. initial_string = ""
  29. initial_string += "0"*(4-len(integer))
  30. initial_string += integer
  31. return initial_string
  32.  
  33. X, Y = extract("/home/mpcr/Desktop/rodrigo-sfm/dataset/fau-routes-6.nvm")
  34.  
  35. d = Data()
  36.  
  37. image_batch = np.zeros((1,480,640,3))
  38. coordinate_batch = np.zeros((1,7))
  39.  
  40. for i in range(1,len(X)):
  41. fname = "/home/mpcr/Desktop/rodrigo-sfm/dataset/fau-route-6/output_{}.jpg".format(string_from_integer(i))
  42. print(fname)
  43. image = cv2.imread(fname)
  44. coordinates = np.asarray(Y[i])
  45. print(d.images.shape)
  46. print(image.shape)
  47. print(d.coordinates.shape)
  48. print(coordinates.shape)
  49. d.images = np.concatenate((d.images, [image]))
  50. d.coordinates = np.concatenate((d.coordinates, [coordinates]))
  51. d.save("/home/mpcr/Desktop/rodrigo-sfm/dataset/fau-route-6/dataset1.h5")
Add Comment
Please, Sign In to add comment