Last active
August 12, 2023 10:49
-
-
Save sunpazed/c031307efed3a2be9ee122d2a80e7ea6 to your computer and use it in GitHub Desktop.
MacOS fix for Fooocus to work correctly within a cv2 worker with AppKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import cv2 | |
buffer = [] | |
cv2.namedWindow('Foooocus', cv2.WINDOW_NORMAL) | |
def worker(): | |
global buffer | |
while True: | |
cv2.waitKey(50) | |
try: | |
if len(buffer) > 0: | |
task = buffer.pop(0) | |
if task is None: | |
cv2.destroyAllWindows() | |
else: | |
flag, img, title = task | |
cv2.imshow(flag, img) | |
cv2.setWindowTitle(flag, title) | |
cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 1) | |
except Exception as e: | |
print(e) | |
pass | |
def show_preview(flag, img, title='preview'): | |
buffer.append((flag, img[..., ::-1].copy(), title)) | |
def close_all_preview(): | |
buffer.append(None) | |
threading.Thread(target=worker, daemon=True).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment