def apply_effect_swap(models, frame, effect): image2 = effect['image2'] if image2 is not None: params = effect['params'] out1, out2 = swap_faces(models, frame, image2=image2, params=params) return out1 return frame
import cv2 from face_swap import swap_faces from image_utils import concatenate_images imgPath = "assets/img3.jpg" # Read images img = cv2.imread(imgPath) # Swap faces img_changed_face = swap_faces(img) # Concatenate images horizontally result = concatenate_images((img, img_changed_face), axis='h', border=5) # Show final result and process cv2.imshow("result", result) cv2.waitKey(0) # Save Results cv2.imwrite('results/result81_1img.png', result)
import imutils ap=ArgumentParser() ap.add_argument("-i","--input1",type=str,required=True) ap.add_argument("-m","--input2",type=str,default="") ap.add_argument("-o","--output",type=str,default="") args=vars(ap.parse_args()) detector=dlib.get_frontal_face_detector() predictor=dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") image=cv2.imread(args["input1"]) cap=cv2.VideoCapture(args["input2"]) while True: (access,frame)=cap.read() frame=imutils.resize(frame,width=900) if not access: break result=swap_faces(image,frame,detector,predictor) cv2.imshow("frame",result) key=cv2.waitKey(1) & 0xFF if key==ord("q"): break
import cv2 from face_swap import swap_faces from image_utils import resize_and_border_image, concatenate_images imgPath = "assets/img1.jpg" imgPath2 = "assets/img2.jpg" # Read images img = cv2.imread(imgPath) img2 = cv2.imread(imgPath2) # Resize and border image, so both images have same dimensions img, img2 = resize_and_border_image(img, img2) # Swap faces img_changed_face, img2_changed_face = swap_faces(img, img2) # Concatenate results result = concatenate_images( (concatenate_images((img, img_changed_face), axis='h', border=5), concatenate_images((img2, img2_changed_face), axis='h', border=5)), axis='v', border=0) # Resize results so they fit in the screen result = cv2.resize(result, (int(result.shape[1] / 3), int(result.shape[0] / 3))) # Show results cv2.imshow("result", result) cv2.waitKey(0)
import cv2 from argparse import ArgumentParser import dlib from face_swap import swap_faces ap=ArgumentParser() ap.add_argument("-i","--input1",type=str,required=True) ap.add_argument("-m","--input2",type=str,required=True) ap.add_argument("-o","--output",type=str,default="") args=vars(ap.parse_args()) image1=cv2.imread(args["input1"]) image2=cv2.imread(args["input2"]) detector=dlib.get_frontal_face_detector() predictor=dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") result=swap_faces(image1,image2,detector,predictor) if args["output"]!="": cv2.imwrite(args["output"],result) cv2.imshow("frame",result) cv2.waitKey(0) cv2.destroyAllWindows()