bef899729a9a57f21110f880cfcbe8eda12dfb12
[facial-landmarks-for-cubism.git] / README.md
1 # Facial Landmarks for Cubism
2
3 A library that extracts facial landmarks from a webcam feed (computed by [OpenSeeFace](https://github.com/emilianavt/OpenSeeFace)) and converts them
4 into Live2D® Cubism SDK parameters.
5
6 *Disclaimer: This library is designed for use with the Live2D® Cubism SDK.
7 It is not part of the SDK itself, and is not affiliated in any way with Live2D
8 Inc. The Live2D® Cubism SDK belongs solely to Live2D Inc. You will need to
9 agree to Live2D Inc.'s license agreements to use the Live2D® Cubism SDK.*
10
11 This 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
15 Video showing me using the example program:
16 <https://youtu.be/SZPEKwEqbdI>
17
18 ## Old version using dlib
19 The old version using dlib is no longer actively maintained, but if
20 you 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
22 ## Spin-off: Mouse Tracking for Cubism
23
24 An alternative version using mouse cursor tracking and audio based lip
25 syncing instead of face tracking is available at
26 <https://github.com/adrianiainlam/mouse-tracker-for-cubism>.
27
28 The main advantage is a much lower CPU load.
29
30 ## Supporting environments
31
32 This library was developed and tested only on Ubuntu 18.04 using GCC 7.5.0.
33
34 Currently it only supports Unix-like environments, as I am using
35 `<sys/socket.h>` etc to communicate with OpenSeeFace. If there is demand
36 for it, I can try to make it work on Windows as well (contributions
37 welcome).
38
39 The library should only require C++11. The Cubism
40 SDK requires C++14. I have made use of one C++17 library (`<filesystem>`)
41 in the example program, but it should be straightforward to change this
42 if you don't have C++17 support.
43
44 ## Build instructions
45
46 1. Clone OpenSeeFace from <https://github.com/emilianavt/OpenSeeFace>,
47    refer to its documentation and install its dependencies.
48
49 2. Install dependencies.
50
51    You will require a recent C/C++ compiler, `make`, `patch`, and CMake >= 3.16. To compile the example
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
54    had to install on Ubuntu 18.04 (this list may not be exhaustive) are:
55
56        libgl1-mesa-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libglu1-mesa-dev
57
58 3. Clone this repository
59
60        git clone https://github.com/adrianiainlam/facial-landmarks-for-cubism.git
61
62 4. To build the library only: (Skip this step if you want to build the example
63    program. It will be done automatically.)
64
65        cd <path of the git repo>
66        ./build.sh
67
68 To build the example program:
69
70 5. Download "Cubism 4 SDK for Native R2" from the Live2D website:
71    <https://www.live2d.com/en/download/cubism-sdk/download-native/>.
72
73    Extract the archive -- put the "CubismSdkForNative-4-r.2" folder under
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
79 6. Go into the
80    "example/CubismSdkForNative-4-r.2/Samples/OpenGL/thirdParty/scripts"
81    directory and run
82
83        ./setup_glew_glfw
84
85 7. Go back to the "example" directory and run
86
87        ./build.sh
88
89 8. 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
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:
100
101        cd ./demo_build/build/make_gcc/bin/Demo/
102        ./Demo
103
104
105 ## Command-line arguments for the example program
106
107 Most command-line arguments are to control the Cubism side of the program.
108 Only one argument (`--config`) is used to specify the configuration file
109 for 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.
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/).
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
131 Due to the differences in hardware and differences in each person's face,
132 I have decided to make pretty much every parameter tweakable. The file
133 "config.txt" lists and documents all parameters and their default values.
134 You can change the values there and pass it to the example program using
135 the `-c` argument. If using the library directly, the path to this file
136 should be passed to the constructor (or pass an empty string to use
137 default values).
138
139 ## License
140
141 The library itself is provided under the MIT license. By "the library itself"
142 I 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
150 The license text can be found in LICENSE-MIT.txt, and also at the top of
151 the .cpp and .h files.
152
153 The example program is a patched version of the sample program provided
154 by Live2D (because there's really no point in reinventing the wheel),
155 and as such, as per the licensing restrictions by Live2D, is still the
156 property of Live2D.
157
158 The patch file (example/demo.patch) contains lines showing additions by
159 me, as well as deleted lines and unchanged lines for context. The deleted
160 and unchanged lines are obviously still owned by Live2D. For my additions,
161 where substantial enough for me to claim ownership, I release them under
162 the Do What the Fuck You Want to Public License, version 2. The full license
163 text can be found in LICENSE-WTFPL.txt.
164
165 All 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
167 documents and files generated by Git, are also released under the Do What
168 the Fuck You Want to Public License, version 2, whose full license text
169 can be found in LICENSE-WTFPL.txt.
170
171 In order to use example program, or in any other way use this library
172 with the Live2D® Cubism SDK, you must agree to the license by Live2D Inc.
173 Their licenses can be found here:
174 <https://www.live2d.com/en/download/cubism-sdk/download-native/>.
175
176 This is not a license requirement, but if you find my library useful,
177 I'd love to hear from you! Send me an email at spam(at)adrianiainlam.tk --
178 replacing "spam" with the name of this repo :).
179
180 ## Contributions
181
182 Contributions welcome! This is only a hobby weekend project so I don't
183 really have many environments / faces to test it on. Feel free to submit
184 issues or pull requests on GitHub, or send questions or patches to me
185 (see my email address above) if you prefer email. Thanks :)
186