You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.9 KiB

9 years ago
9 years ago
  1. #!/usr/bin/env python3
  2. from ctypes import *
  3. import os
  4. large_image1_path = "../test_images/sample_01_large.jpg".encode(encoding="utf-8")
  5. medium_image1_path = "../test_images/sample_01_medium.jpg".encode(encoding="utf-8")
  6. small_image1_path = "../test_images/sample_01_small.jpg".encode(encoding="utf-8")
  7. large_image2_path = "../test_images/sample_02_large.jpg".encode(encoding="utf-8")
  8. medium_image2_path = "../test_images/sample_02_medium.jpg".encode(encoding="utf-8")
  9. small_image2_path = "../test_images/sample_02_small.jpg".encode(encoding="utf-8")
  10. large_image3_path = "../test_images/sample_03_large.jpg".encode(encoding="utf-8")
  11. medium_image3_path = "../test_images/sample_03_medium.jpg".encode(encoding="utf-8")
  12. small_image3_path = "../test_images/sample_03_small.jpg".encode(encoding="utf-8")
  13. test_images=[large_image1_path, medium_image1_path, small_image1_path,large_image2_path, medium_image2_path, small_image2_path,large_image3_path, medium_image3_path, small_image3_path]
  14. def unsigned64(number):
  15. return c_ulonglong(number).value
  16. print("starting ffi test")
  17. # Load the shared library
  18. lib = None
  19. if os.name == 'nt':
  20. path = os.path.dirname(__file__) + "\\pihash.dll"
  21. print(path)
  22. lib = CDLL(path)
  23. else:
  24. lib = cdll.LoadLibrary("libpihash.so")
  25. # Setting the ctypes return type references for the foreign functions
  26. lib.ext_get_ahash.restype = c_ulonglong
  27. lib.ext_get_dhash.restype = c_ulonglong
  28. lib.ext_get_phash.restype = c_ulonglong
  29. #initialize the library
  30. lib.init()
  31. # Print the path and the bytes as hex for debugging
  32. #print(large_image_path)
  33. #print('\\x'+'\\x'.join('{:02x}'.format(x) for x in large_image_path))
  34. for image in test_images:
  35. print("Requesting hashes for: %s"% image)
  36. print("ahash: %i"% unsigned64(lib.ext_get_ahash(image)))
  37. print("dhash: %i"% unsigned64(lib.ext_get_dhash(image)))
  38. print("phash: %i"% unsigned64(lib.ext_get_phash(image)))
  39. # Do cleanup
  40. #lib.teardown()
  41. print("ffi test finished")