Upgrade to Cubism 4 Release R4. No incompatible API changes.
[facial-landmarks-for-cubism.git] / README.md
CommitLineData
830d0ba4
AIL
1# Facial Landmarks for Cubism
2
30b18873 3A library that extracts facial landmarks from a webcam feed (computed by [OpenSeeFace](https://github.com/emilianavt/OpenSeeFace)) and converts them
830d0ba4
AIL
4into Live2D® Cubism SDK parameters.
5
6*Disclaimer: This library is designed for use with the Live2D® Cubism SDK.
7It is not part of the SDK itself, and is not affiliated in any way with Live2D
8Inc. The Live2D® Cubism SDK belongs solely to Live2D Inc. You will need to
9agree to Live2D Inc.'s license agreements to use the Live2D® Cubism SDK.*
10
11This block diagram shows the intended usage of this library:
12
13![Block diagram showing interaction of this library with other components](block_diagram.png)
14
15Video showing me using the example program:
c175b891 16<https://youtu.be/SZPEKwEqbdI>
830d0ba4 17
30b18873
AIL
18## Old version using dlib
19The old version using dlib is no longer actively maintained, but if
20you want to use it, you can get it on the [dlib-stable branch](https://github.com/adrianiainlam/facial-landmarks-for-cubism/tree/dlib-stable).
21
b3b6e2a1
AIL
22## Spin-off: Mouse Tracking for Cubism
23
24An alternative version using mouse cursor tracking and audio based lip
25syncing instead of face tracking is available at
26<https://github.com/adrianiainlam/mouse-tracker-for-cubism>.
27
28The main advantage is a much lower CPU load.
830d0ba4
AIL
29
30## Supporting environments
31
32This library was developed and tested only on Ubuntu 18.04 using GCC 7.5.0.
30b18873
AIL
33
34Currently it only supports Unix-like environments, as I am using
35`<sys/socket.h>` etc to communicate with OpenSeeFace. If there is demand
36for it, I can try to make it work on Windows as well (contributions
37welcome).
38
39The library should only require C++11. The Cubism
830d0ba4
AIL
40SDK requires C++14. I have made use of one C++17 library (`<filesystem>`)
41in the example program, but it should be straightforward to change this
42if you don't have C++17 support.
43
30b18873 44## Build instructions
830d0ba4 45
1dccd527 461. Clone OpenSeeFace from <https://github.com/emilianavt/OpenSeeFace>,
30b18873 47 refer to its documentation and install its dependencies.
830d0ba4 48
30b18873 492. Install dependencies.
830d0ba4 50
30b18873 51 You will require a recent C/C++ compiler, `make`, `patch`, and CMake >= 3.16. To compile the example
830d0ba4
AIL
52 program you will also require the OpenGL library (and its dev headers)
53 among other libraries required for the example program. The libraries I
e01443f7 54 had to install on Ubuntu 18.04 (this list may not be exhaustive) are:
830d0ba4
AIL
55
56 libgl1-mesa-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libglu1-mesa-dev
57
30b18873 583. Clone this repository
e01443f7 59
30b18873 60 git clone https://github.com/adrianiainlam/facial-landmarks-for-cubism.git
830d0ba4 61
30b18873 624. To build the library only: (Skip this step if you want to build the example
2b1f0c7c 63 program. It will be done automatically.)
830d0ba4
AIL
64
65 cd <path of the git repo>
66 ./build.sh
67
830d0ba4
AIL
68To build the example program:
69
5f788e6f 705. Download "Cubism 4 SDK for Native R4" from the Live2D website:
830d0ba4
AIL
71 <https://www.live2d.com/en/download/cubism-sdk/download-native/>.
72
5f788e6f 73 Extract the archive -- put the "CubismSdkForNative-4-r.4" folder under
830d0ba4
AIL
74 the "example" folder of this repo.
75
76 Note: The Cubism SDK is the property of Live2D and is not part of this
77 project. You must agree to Live2D's license agreements to use it.
78
30b18873 796. Go into the
5f788e6f 80 "example/CubismSdkForNative-4-r.4/Samples/OpenGL/thirdParty/scripts"
830d0ba4
AIL
81 directory and run
82
83 ./setup_glew_glfw
84
30b18873 857. Go back to the "example" directory and run
830d0ba4
AIL
86
87 ./build.sh
88
30b18873
AIL
898. Now try running the example program.
90
91 First, (in a separate terminal) go to where you have downloaded
92 OpenSeeFace, and run
93
94 ./python3 ./facetracker.py -v 4 --model 3 -M
95
30b18873
AIL
96 I tried models 3 and 4, and I think both work reasonably well.
97 Please feel free to explore other options provided by OSF.
98
99 Back to the original terminal, from the "example" directory:
830d0ba4
AIL
100
101 cd ./demo_build/build/make_gcc/bin/Demo/
102 ./Demo
103
104
105## Command-line arguments for the example program
106
107Most command-line arguments are to control the Cubism side of the program.
108Only one argument (`--config`) is used to specify the configuration file
109for the Facial Landmarks for Cubism library.
110
111 * `--window-width`, `-W`: Specify the window width
112 * `--window-height`, `-H`: Specify the window height
113 * `--window-title`, `-t`: Specify the window title
114 * `--root-dir`, `-d`: The directory at which the "Resources" folder will
115 be found. This is where the model data will be located.
116 * `--scale-factor`, `-f`: How the model should be scaled
117 * `--translate-x`, `-x`: Horizontal translation of the model within the
118 window
119 * `--translate-y`, `-y`: Vertical translation of the model within the window
120 * `--model`, `-m`: Name of the model to be used. This must be located inside
121 the "Resources" folder.
8ff44985
AIL
122 * `--old-param-id`, `-o`: If set to 1, translate new (Cubism 3+) parameter
123 IDs to old (Cubism 2.1) IDs. This is necessary, for example, for
124 [the Chitose model available from Live2D](https://www.live2d.com/en/download/sample-data/).
830d0ba4
AIL
125 * `--config`, `-c`: Path to the configuration file for the Facial Landmarks
126 for Cubism library. See below for more details.
127
128
129## Configuration file
130
131Due to the differences in hardware and differences in each person's face,
132I have decided to make pretty much every parameter tweakable. The file
133"config.txt" lists and documents all parameters and their default values.
134You can change the values there and pass it to the example program using
2b1f0c7c 135the `-c` argument. If using the library directly, the path to this file
830d0ba4
AIL
136should be passed to the constructor (or pass an empty string to use
137default values).
138
139## License
140
141The library itself is provided under the MIT license. By "the library itself"
142I refer to the following files that I have provided under this repo:
143
144 * src/facial_landmark_detector.cpp
145 * src/math_utils.h
146 * include/facial_landmark_detector.h
147 * and if you decide to build the binary for the library, the resulting
148 binary file (typically build/libFacialLandmarksForCubism.a)
149
150The license text can be found in LICENSE-MIT.txt, and also at the top of
151the .cpp and .h files.
152
830d0ba4
AIL
153The example program is a patched version of the sample program provided
154by Live2D (because there's really no point in reinventing the wheel),
155and as such, as per the licensing restrictions by Live2D, is still the
156property of Live2D.
157
158The patch file (example/demo.patch) contains lines showing additions by
159me, as well as deleted lines and unchanged lines for context. The deleted
160and unchanged lines are obviously still owned by Live2D. For my additions,
161where substantial enough for me to claim ownership, I release them under
162the Do What the Fuck You Want to Public License, version 2. The full license
163text can be found in LICENSE-WTFPL.txt.
164
165All other files not mentioned above that I have provided in this repo
166(i.e. not downloaded and placed here by you), *excluding* the two license
167documents and files generated by Git, are also released under the Do What
168the Fuck You Want to Public License, version 2, whose full license text
169can be found in LICENSE-WTFPL.txt.
170
171In order to use example program, or in any other way use this library
172with the Live2D® Cubism SDK, you must agree to the license by Live2D Inc.
173Their licenses can be found here:
174<https://www.live2d.com/en/download/cubism-sdk/download-native/>.
175
830d0ba4
AIL
176This is not a license requirement, but if you find my library useful,
177I'd love to hear from you! Send me an email at spam(at)adrianiainlam.tk --
178replacing "spam" with the name of this repo :).
179
180## Contributions
181
182Contributions welcome! This is only a hobby weekend project so I don't
183really have many environments / faces to test it on. Feel free to submit
184issues or pull requests on GitHub, or send questions or patches to me
185(see my email address above) if you prefer email. Thanks :)
186