modify ui to render

This commit is contained in:
brige 2024-09-25 14:37:15 +08:00
parent 5af8ba1878
commit 2127982650
2 changed files with 30 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import logging
import multiprocessing as mp
import platform, subprocess
import queue
import threading
import time
@ -268,7 +269,6 @@ def datagen_signal(frame, mel, face_det_results):
return img_batch, mel_batch, frame_batch, coords_batch
if len(img_batch) > 0:
img_batch, mel_batch = np.asarray(img_batch), np.asarray(mel_batch)
img_masked = img_batch.copy()
@ -280,7 +280,6 @@ def datagen_signal(frame, mel, face_det_results):
return img_batch, mel_batch, frame_batch, coords_batch
class Human:
def __init__(self):
self._fps = 25 # 20 ms per frame
@ -296,7 +295,10 @@ class Human:
# self._tts = TTSBase(self)
self.mel_chunks_queue_ = Queue()
self.test()
self._test_image_queue = Queue()
self._thread = None
# self.test()
# face_images_path = r'./face/'
# self._face_image_paths = utils.read_files_path(face_images_path)
@ -370,6 +372,8 @@ class Human:
# name = "%04d" % j
# cv2.imwrite(f'temp/images/{j}.jpg', p)
# j = j + 1
p = cv2.cvtColor(f, cv2.COLOR_BGR2RGB)
self._test_image_queue.put(p)
out.write(f)
out.release()
@ -403,11 +407,14 @@ class Human:
logging.info('human destroy')
def read(self, txt):
if self._tts is None:
logging.warning('tts is none')
return
# if self._tts is None:
# logging.warning('tts is none')
# return
self._tts.push_txt(txt)
if self._thread is None:
self._thread = threading.Thread(target=self.test)
self._thread.start()
# self._tts.push_txt(txt)
def push_audio_chunk(self, audio_chunk):
self._chunk_2_mal.push_chunk(audio_chunk)
@ -422,7 +429,8 @@ class Human:
def render(self):
try:
img, aud = self._res_frame_queue.get(block=True, timeout=.3)
# img, aud = self._res_frame_queue.get(block=True, timeout=.3)
img = self._test_image_queue.get(block=True, timeout=.3)
except queue.Empty:
# print('render queue.Empty:')
return None

17
ui.py
View File

@ -5,6 +5,7 @@ from logging import handlers
import tkinter
import tkinter.messagebox
import customtkinter
import cv2
import requests
from PIL import Image, ImageTk
@ -65,19 +66,29 @@ class App(customtkinter.CTk):
self.after(100, self._render)
return
iheight, iwidth = image.shape[0], image.shape[1]
width = self.winfo_width()
height = self.winfo_height()
if iheight / iwidth >= width / height:
image = cv2.resize(image, (int(width), int(iheight * width / iwidth)))
else:
image = cv2.resize(image, (int(iwidth * height / iheight), int(height)), interpolation=cv2.INTER_AREA)
# image = cv2.resize(image, (int(width), int(height)), interpolation=cv2.INTER_AREA)
# image = cv2.resize(image, (int(width), int(height)), interpolation=cv2.INTER_AREA)
img = Image.fromarray(image)
imgtk = ImageTk.PhotoImage(image=img)
self._canvas.delete("all")
self._canvas.imgtk = imgtk
width = self.winfo_width() * 0.5
height = self.winfo_height() * 0.5
self._canvas.create_image(width, height, anchor=customtkinter.CENTER, image=imgtk)
self._canvas.update()
self.after(30, self._render)
self.after(60, self._render)
def request_tts(self):
content = self.entry.get()