Skip to content

Commit

Permalink
Automatically adjust window size and borders
Browse files Browse the repository at this point in the history
  • Loading branch information
Migushthe2nd committed Apr 12, 2020
1 parent ac445a1 commit 1a9c071
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions faceit_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 1a9c071

Please sign in to comment.