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

View File

@ -82,9 +82,9 @@ def get_previewer(device, latent_format):
x_sample = x_sample.cpu().numpy().clip(0, 255).astype(np.uint8)
for i, s in enumerate(x_sample):
if i > 0:
show_preview(f'OpenCV Diffusion Preview {i}', s, title=f'Preview Image {i} [{step}/{total_steps}]')
show_preview(s, title=f'Preview Image {i}, step = [{step}/{total_steps}')
else:
show_preview(f'OpenCV Diffusion Preview {i}', s, title=f'Preview Image [{step}/{total_steps}]')
show_preview(s, title=f'Preview Image, step = {step}/{total_steps}')
taesd.preview = preview_function

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()