Skip to content

Commit

Permalink
Merge branch 'master' of github.com:alievk/avatarify
Browse files Browse the repository at this point in the history
  • Loading branch information
alievk committed Apr 20, 2020
2 parents 80226c1 + 179cd3e commit 5a7cb42
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

# Avatarify

Avatars for Skype and Zoom. Democratized.
Photorealistic avatars for Skype and Zoom. Democratized.

Based on [First Order Motion Model](https://github.com/AliaksandrSiarohin/first-order-model).

Created by: [Ali Aliev](https://github.com/alievk) and [Karim Iskakov](https://github.com/karfly).

**Disclaimer**: This project is unrelated to Samsung AI Center.

Expand Down Expand Up @@ -243,8 +247,3 @@ Please make pull requests if you have any improvements or bug-fixes.
* `pipe:0: Invalid data found when processing input`: Make sure `CAMID` in `scripts/settings.sh` is correct. Use `v4l2-ctl --list-devices` to query available devices.
* `ASSERT: "false" in file qasciikey.cpp, line 501`. If you have several keyboard layouts, switch to English layout.
* `No such file or directory: 'vox-adv-cpk.pth.tar'`. Please follow instructions [Download network weights](#download-network-weights)


## Credits

- Avatrify uses [First Order Motion Model](https://github.com/AliaksandrSiarohin/first-order-model) for generating avatars.
13 changes: 2 additions & 11 deletions cam_fomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
def load_checkpoints(config_path, checkpoint_path, device='cuda'):

with open(config_path) as f:
config = yaml.load(f)
config = yaml.load(f, Loader=yaml.FullLoader)

generator = OcclusionAwareGenerator(**config['model_params']['generator_params'],
**config['model_params']['common_params'])
Expand Down Expand Up @@ -218,19 +218,11 @@ def log(*args, **kwargs):

fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, flip_input=True, device=device)

# cap = cv2.VideoCapture(opt.cam)
cap = VideoCaptureAsync(opt.cam)
if not cap.isOpened():
log("Cannot open camera. Try to choose other CAMID in './scripts/settings.sh'")
exit()
cap.start()

ret, frame = cap.read()
if not ret:
log("Cannot read from camera")
exit()

if _streaming:
ret, frame = cap.read()
stream = pyfakewebcam.FakeWebcam(f'/dev/video{opt.virt_cam}', frame.shape[1], frame.shape[0])

cur_ava = 0
Expand Down Expand Up @@ -386,6 +378,5 @@ def log(*args, **kwargs):
fps = 10 / sum(fps_hist)
fps_hist = []

#cap.release()
cap.stop()
cv2.destroyAllWindows()
4 changes: 1 addition & 3 deletions run_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

@set CONFIG=fomm/config/vox-adv-256.yaml

REM @set /P CAMID="Pick the webcam id you want to use (typically "0"): "

@set PYTHONPATH=%PYTHONPATH%;%CD%/fomm
@call python cam_fomm.py --config %CONFIG% --cam %CAMID% --relative --adapt_scale --no-pad --checkpoint vox-adv-cpk.pth.tar
@call python cam_fomm.py --config %CONFIG% --cam %CAMID% --relative --adapt_scale --no-pad --checkpoint vox-adv-cpk.pth.tar
21 changes: 20 additions & 1 deletion videocaptureasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

import threading
import cv2
import time


WARMUP_TIMEOUT = 10.0


class VideoCaptureAsync:
def __init__(self, src=0, width=640, height=480):
self.src = src

self.cap = cv2.VideoCapture(self.src)
if not self.cap.isOpened():
raise RuntimeError("Cannot open camera. Try to choose other CAMID in './scripts/settings.sh'")

self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
self.grabbed, self.frame = self.cap.read()
Expand All @@ -21,11 +30,21 @@ def isOpened(self):

def start(self):
if self.started:
print('[!] Asynchroneous video capturing has already been started.')
print('[!] Asynchronous video capturing has already been started.')
return None
self.started = True
self.thread = threading.Thread(target=self.update, args=(), daemon=True)
self.thread.start()

# (warmup) wait for the first successfully grabbed frame
warmup_start_time = time.time()
while not self.grabbed:
warmup_elapsed_time = (time.time() - warmup_start_time)
if warmup_elapsed_time > WARMUP_TIMEOUT:
raise RuntimeError(f"Failed to succesfully grab frame from the camera (timeout={WARMUP_TIMEOUT}s). Try to restart.")

time.sleep(0.5)

return self

def update(self):
Expand Down

0 comments on commit 5a7cb42

Please sign in to comment.