Skip to content

Re-implement pHash comparison using cv2. Drop imagehash+Pillow #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 19, 2023
Merged

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Dec 13, 2023

  • Re-implement pHash comparison using cv2.
  • Drop imagehash and Pillow as dependencies
  • Reduce bundle size by 1.93MB (139.004 --> 137.074)
  • ~1.6x speed improvement for pHash comparison
  • Reduce install/build time considerably by not installing D3DShot from GitHub
  • Testing suggests some images might differ in comparison from old implementation by at most 2/64 (3.125%)

Timing difference done using:

    def new():
        source_hash = __cv2_phash(source)
        capture_hash = __cv2_phash(capture)
        return np.count_nonzero(source_hash != capture_hash)
    new_time = timeit.Timer(new).timeit(1000)

    def old():
        source_hash = imagehash.phash(Image.fromarray(source))
        capture_hash = imagehash.phash(Image.fromarray(capture))
        return source_hash - capture_hash
    old_time = timeit.Timer(old).timeit(1000)

    print(old_time, "/", new_time, "=", old_time / new_time)

@Avasam
Copy link
Collaborator Author

Avasam commented Dec 14, 2023

Pyright error is likely microsoft/pyright#6722

@Avasam Avasam merged commit f2e6372 into dev Dec 19, 2023
@Avasam Avasam deleted the cv2-phash branch December 19, 2023 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant