ImageDB.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import os, json
  2. import numpy as np
  3. class ImageDB(object):
  4. """Generic Class for image-database
  5. main assumption:
  6. DB: CSV files with image link (path or uri)
  7. CSV file structure: per row (uri; uri; uri; ...) or (filename; filename; filename; ...)
  8. """
  9. def __init__(self, jsonConfigFile = None):
  10. """
  11. json file format:
  12. {
  13. "name": "my_DB", <- database name
  14. "imagePATH": "../images/", <- where are local copy of images
  15. "csvFilePATH": "../imagefile_utf8.csv", <- image path or uri list in csv format
  16. }
  17. """
  18. # attribute
  19. self.jsonConfigFile = jsonConfigFile
  20. # load config
  21. with open(self.jsonConfigFile) as json_file: config = json.load(json_file)
  22. # recover cvsFileName from config file
  23. self.name = config["name"]
  24. self.csvFileName = config["csvFilePATH"]
  25. self.imagePATH = config["imagePATH"]
  26. # DEBUG
  27. # print("DEBUG[ImageDB.name::",self.name,"]")
  28. # print("DEBUG[ImageDB.csvFileName::",self.csvFileName,"]")
  29. # print("DEBUG[ImageDB.imagePATH::",self.imagePATH,"]")
  30. # database set to None
  31. self.db = None
  32. if os.path.isfile(self.csvFileName):
  33. # DEBUG
  34. # print("DEBUG[ImageDB.csvFileName::",self.csvFileName,"> load csv]")
  35. self.db = np.loadtxt(self.csvFileName, dtype=np.unicode_, delimiter=";",encoding="utf8")
  36. #DEBUG
  37. # print("DEBUG[ImageDB.db.shape::",self.db.shape,"]")
  38. pass
  39. def build(self,builder,src=""):
  40. """ build cvs file """
  41. builder.compute(self,src)
  42. def check(self,checker):
  43. """ check if images in cvs are in local storage """
  44. checker.compute(self)
  45. def lookForUpdate(self):
  46. pass
  47. def update(self):
  48. pass