Skip to content

Commit

Permalink
video_handler process the image as natural as main.py now
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangshaocheng committed Mar 5, 2019
1 parent 87668f5 commit 624e588
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Binary file modified imgs/realtime0.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 7 additions & 13 deletions video_handler.py
Expand Up @@ -9,16 +9,6 @@
from face_points_detection import *
from face_swap import *

# FACE_POINTS = list(range(17, 68))
# MOUTH_POINTS = list(range(48, 61))
# RIGHT_BROW_POINTS = list(range(17, 22))
# LEFT_BROW_POINTS = list(range(22, 27))
# RIGHT_EYE_POINTS = list(range(36, 42))
# LEFT_EYE_POINTS = list(range(42, 48))
# NOSE_POINTS = list(range(27, 35))
# JAW_POINTS = list(range(0, 17))
# FACE_PROFILE=(JAW_POINTS+RIGHT_BROW_POINTS+LEFT_BROW_POINTS)


class VideoHandler(object):
def __init__(self, video_path=0, detector_type="cascade", tracker_type="mosse", lose_threshold=10):
Expand Down Expand Up @@ -57,6 +47,7 @@ def process_src_img(self):
fromCenter=False, showCrosshair=False)
if initBB != (0, 0, 0, 0):
break
cv2.destroyWindow("src_roi")
(x, y, w, h) = initBB
self.src_points -= (x, y)
self.src_img = self.src_img[y:y + h, x:x + w]
Expand All @@ -78,15 +69,18 @@ def fast_face_swap(self, dst_img, dst_face_rect: dlib.rectangle):
logging.error("part of Face")
return (failed, dst_img)

dst_mask = mask_from_points(dst_img.shape[:2], dst_points, erode_flag=1)

r = cv2.boundingRect(dst_points)
(x, y, w, h) = r

if y + h > dst_img.shape[0] or x + w > dst_img.shape[1]:
return (failed, dst_img)

dst_roi = dst_img[y:y + h, x:x + w]
dst_mask = dst_mask[y:y + h, x:x + w]
dst_points -= (x, y)

dst_mask = mask_from_points(
dst_roi.shape[:2], dst_points, erode_flag=0)
dst_only_face = apply_mask(dst_roi, dst_mask)

warped_src_img = warp_image_3d(
Expand Down Expand Up @@ -214,7 +208,6 @@ def cascade_vh(self):
end_tc = cv2.getTickCount()
fps = cv2.getTickFrequency() / (end_tc - start_tc)
logging.info("fps {}".format(fps))

cv2.destroyAllWindows()
self.cap.release()

Expand Down Expand Up @@ -248,3 +241,4 @@ def draw_rect(self, img, bbox, color=(255, 255, 255)):
test.set_src_img(args.src_img)
test.process_src_img()
test.cascade_vh()

0 comments on commit 624e588

Please sign in to comment.