From 1a9c07167a7ef6cdfd2f0c522fd887783165e2db Mon Sep 17 00:00:00 2001 From: Migushthe2nd Date: Sun, 12 Apr 2020 21:34:27 +0200 Subject: [PATCH] Automatically adjust window size and borders --- faceit_live.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/faceit_live.py b/faceit_live.py index db82410..7b99fe6 100644 --- a/faceit_live.py +++ b/faceit_live.py @@ -37,6 +37,7 @@ webcam_height = 480 webcam_width = 640 screen_width, screen_height = pyautogui.size() +img_shape = [256, 256, 0] system = args.system if system=="linux": @@ -117,7 +118,7 @@ def main(): cv2.namedWindow('Stream', cv2.WINDOW_GUI_NORMAL) # rendered to fake webcam cv2.moveWindow('Stream', int(screen_width/2)-int(webcam_width/2), 400) - cv2.resizeWindow('Stream', webcam_width,webcam_width) + cv2.resizeWindow('Stream', webcam_width,webcam_height) print("Press C to center Webcam, Press N for next image in media directory, T to alter between relative and absolute transformation, Q to quit") @@ -146,9 +147,11 @@ def main(): cv2.imshow('DeepFake', deep_fake) - rgb = cv2.resize(deep_fake,(480,480)) + rgb = cv2.resize(deep_fake,(int(img_shape[1] / img_shape[0] * 480),480)) # pad image - stream_v = cv2.copyMakeBorder( rgb, 0, 0, 80, 80, cv2.BORDER_CONSTANT) + x_border = int((640-(img_shape[1] / img_shape[0] * 480))/2) + y_border = int((480-(img_shape[0] / img_shape[1] * 640))/2) + stream_v = cv2.copyMakeBorder(rgb, y_border if y_border >=0 else 0, y_border if y_border >=0 else 0, x_border if x_border >=0 else 0, x_border if x_border >=0 else 0, cv2.BORDER_CONSTANT) cv2.imshow('Stream',stream_v) #time.sleep(1/30.0) @@ -248,7 +251,7 @@ def find_face_cut(net,face,previous=False): return cut_x1,cut_y1,cut_x2,cut_y2 def readnextimage(position=-1): - global img_list,pos + global img_list,pos,img_shape if (position != -1): pos = position else: @@ -257,6 +260,8 @@ def readnextimage(position=-1): else: pos=0 img = imageio.imread(img_list[pos]) + img_shape = img.shape + cv2.resizeWindow('DeepFake', int(img_shape[1] / img_shape[0] * 256), 256) img = resize(img, (256, 256))[..., :3] return img