{"id":18344946,"url":"https://github.com/nicennnnnnnlee/faceswap","last_synced_at":"2025-04-06T08:31:25.049Z","repository":{"id":45521484,"uuid":"398184992","full_name":"nICEnnnnnnnLee/FaceSwap","owner":"nICEnnnnnnnLee","description":"基于opencv和dlib的视频换脸","archived":false,"fork":false,"pushed_at":"2021-08-20T07:43:03.000Z","size":81263,"stargazers_count":21,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T20:46:36.516Z","etag":null,"topics":["dlib","face-swap","opencv","opencv-python","python","video-processing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nICEnnnnnnnLee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-20T06:57:52.000Z","updated_at":"2024-12-14T01:25:39.000Z","dependencies_parsed_at":"2022-07-18T08:17:07.300Z","dependency_job_id":null,"html_url":"https://github.com/nICEnnnnnnnLee/FaceSwap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nICEnnnnnnnLee%2FFaceSwap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nICEnnnnnnnLee%2FFaceSwap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nICEnnnnnnnLee%2FFaceSwap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nICEnnnnnnnLee%2FFaceSwap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nICEnnnnnnnLee","download_url":"https://codeload.github.com/nICEnnnnnnnLee/FaceSwap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457079,"owners_count":20941899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dlib","face-swap","opencv","opencv-python","python","video-processing"],"created_at":"2024-11-05T21:06:42.191Z","updated_at":"2025-04-06T08:31:20.041Z","avatar_url":"https://github.com/nICEnnnnnnnLee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n      \u003cstrong\u003e\n        \u003ca href=\"https://github.com/nICEnnnnnnnLee/FaceSwap\" target=\"_blank\"\u003eVideoFaceSwap\u003c/a\u003e\u0026nbsp;\n      \u003c/strong\u003e\n  \u003cbr\u003e\n        简单的视频换脸程序\n  \u003cbr\u003e\n      源自\u003cstrong\u003e\n        \u003ca href=\"https://github.com/ButterAndButterfly\" target=\"_blank\"\u003eButterAndButterfly\u003c/a\u003e\u003cbr\u003e\n      \u003c/strong\u003e  \n        Butter, 寓意宅男; Butterfly, 寓意美好的事物。 \n        \u003cbr/\u003e 美好的世界由我们创造!  \n\u003c/p\u003e\n\n## 技术原理  \n参考了以下两个项目：\n+ [simple_faceswap](https://github.com/Jacen789/simple_faceswap)  \n    + 实现了摄像头捕捉的视频流的简单换脸，将其实时显示。   \n    + 换脸思路是直接整个面部到面部的转换。   \n\n+ [AI-Change-face-in-the-video](https://github.com/Liangwe/AI-Change-face-in-the-video)  \n    + 实现了视频中的人脸到指定照片中的人脸的更换，并且输出视频。  \n        但中间有很多冗余步骤，将视频转换为图片保存，再处理图片，再合并视频。  \n        这其中多出了大量磁盘读写IO，且视频帧频率信息丢失。       \n    + 换脸思路是五官到五官的转换。   \n\n考虑到项目2的缺陷，我们可以参考一个简单的opencv读取复制视频的例子，对其进行改善。  \n```python\n# opencv读取复制视频\nimport cv2\n\nvideo = cv2.VideoCapture(\"faces/trump.avi\")\nfps = video.get(cv2.CAP_PROP_FPS)\nframeCount = video.get(cv2.CAP_PROP_FRAME_COUNT)\nsize = (int(video.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))\nvideoWriter = cv2.VideoWriter('trans.mp4', cv2.VideoWriter_fourcc(*'MP4V'), fps, size)  \nsuccess, frame = video.read()  \nindex = 1\nwhile success :  \n\tvideoWriter.write(frame)\n\tsuccess, frame = video.read()\n\tindex += 1\nvideo.release()\n```\n\n\n## 效果预览\n\u003chttps://www.bilibili.com/video/BV1ff4y137ep\u003e\n\n\n## 可能的坑  \n+ 安装dlib报错  \n根据报错信息提示，使用pip安装Cmake即可。  \n但安装Cmake可能也会报错，你需要根据提示再安装Visual Studio，主要是要保证C++的编译环境。  \n\n+ 转换后的视频花屏    \n原始的image矩阵是0~255的整型的，经过处理后可能变成了浮点型，需要再进行`img.astype(np.uint8)`操作。\n\n\n## 如何使用  \n+ 根据`requirements.txt`安装依赖  \n+ 修改[`L15~L18`](https://github.com/nICEnnnnnnnLee/FaceSwap/blob/2ebb74a32b3ed9be50e946cbdde60993e62b1359/main.py#L15-L18)行的参数，指定输入的图片、视频即可。  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicennnnnnnlee%2Ffaceswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicennnnnnnlee%2Ffaceswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicennnnnnnlee%2Ffaceswap/lists"}