This commit is contained in:
lvmin
2023-08-11 05:19:09 -07:00
parent fb22bbf89d
commit 6bd69367aa
2 changed files with 32 additions and 10 deletions
+30 -8
View File
@@ -1,14 +1,36 @@
import threading
import cv2
def show_preview(flag, img, title=None):
if title is None:
title = flag
cv2.imshow(flag, img[:, :, ::-1].copy())
cv2.setWindowTitle(flag, title)
cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 1)
cv2.waitKey(1)
flag = 'fooocus_cv2win32'
buffer = []
def worker():
global buffer, flag
while True:
cv2.waitKey(50)
try:
if len(buffer) > 0:
task = buffer.pop(0)
if task is None:
cv2.destroyAllWindows()
else:
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(img, title='preview'):
buffer.append((img, title))
def close_all_preview():
cv2.destroyAllWindows()
buffer.append(None)
threading.Thread(target=worker, daemon=True).start()