POGChecker.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from . import ImageDB, Checker, utils
  2. import os, json
  3. import numpy as np
  4. class POGChecker(Checker.Checker):
  5. """description of class"""
  6. def __init__(self, local=True):
  7. """
  8. https://www.portraitsofgirls.com/wp-content/uploads/2020/02/alexandra-ola-by-maxim-gagarin-14.jpg
  9. """
  10. self.local = local # if local local copy are checked else check online images
  11. def compute(self, db):
  12. if self.local:
  13. # check local copy
  14. # get path to local images
  15. path = db.imagePATH
  16. # results of checking
  17. checked = []
  18. missingFiles = []
  19. duplicateFiles= []
  20. # for all item in db
  21. for imageURI in db.db:
  22. # check if locol copy of image exist
  23. filename, ext =utils.img_url_2_file_ext(path,imageURI,minRange=-3,maxRange=-1)
  24. filename = filename+'.'+ext
  25. imgOK = os.path.isfile(filename)
  26. if imgOK:
  27. # check for duplicate
  28. if not filename in checked:
  29. checked.append(filename)
  30. else:
  31. duplicateFiles.append(filename)
  32. else:
  33. missingFiles.append(filename)
  34. # results
  35. if len(duplicateFiles)>0: np.savetxt(db.name+"_"+"duplicateImages.csv",duplicateFiles,delimiter=";",fmt="%s",encoding="utf8")
  36. if len(missingFiles)>0:np.savetxt(db.name+"_"+"missingImages.csv",missingFiles,delimiter=";",fmt="%s",encoding="utf8")
  37. # DEBUG
  38. # print("DEBUG[POGChecker.compute(",db.name,")::missing images>",len(missingFiles),"]")
  39. # print("DEBUG[POGChecker.compute(",db.name,")::duplicate images>",len(duplicateFiles),"]")
  40. # print("DEBUG[POGChecker.compute(",db.name,")::",len(db.db)," uri tested ->",len(checked)," local images OK]")
  41. db.db = np.asarray(checked)
  42. else:
  43. # check online images
  44. pass