Last active
November 3, 2021 23:09
-
-
Save Kelketek/14e473479a7a043786be646213f4f05e to your computer and use it in GitHub Desktop.
Install and configure OpenSeeFace for use with VTube Studio on Ubuntu Linux.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# This script is a quick setup script for those using Ubuntu-based systems | |
# and which want to set up OpenSeeFace to work with VTube Studio. | |
# | |
# This script will allow novice Linux users to get configured with | |
# a sane VTube configuration that will work with their webcam. | |
# | |
# Before running this script, make sure you've installed VTuber Studio | |
# using the default options in Steam. | |
# | |
# If you know what you're doing, feel free to edit some of the variables below. | |
# | |
# Written by Fox of Artconomy.com. If you're looking for an art commissioning | |
# platform, please give Artconomy a look! | |
VTUBE_DATA_PATH=~/.steam/debian-installation/steamapps/common/VTube\ Studio/VTube\ Studio_Data | |
OPENSEE_INSTALL_PATH=~/opt/openseeface | |
OPENSEE_INTERFACE=0.0.0.0 | |
OPENSEE_PORT=11573 | |
# The name of the new command that will be added to your PATH which will launch OpenSeeFace | |
# and VTube Studio. | |
EXECUTABLE_NAME=vts | |
# In Ubuntu, the ~/bin directory is automatically added to PATH if it exists at startup, | |
# so this shouldn't require extra configuration to persist, though any open shell windows | |
# may not be informed. | |
PERSONAL_BIN=~/.local/bin | |
# Did we screw up? Die immediately. | |
set -e | |
if [[ ! -d "${VTUBE_DATA_PATH}" ]];then | |
>&2 echo "We couldn't find the VTuber Studio data directory at ${VTUBE_DATA_PATH}." | |
>&2 echo "Please make sure you've installed VTuber Studio with Steam using the default options." | |
exit 1 | |
fi | |
cat << EOF > "${VTUBE_DATA_PATH}/ip.txt" | |
# To listen for remote connections, change this to 0.0.0.0 or your actual IP on the desired interface. | |
ip=${OPENSEE_INTERFACE} | |
# This is the port the server will listen for tracking packets on. | |
port=${OPENSEE_PORT} | |
EOF | |
echo ">> Installed ip.txt configuration file." | |
echo ">> Installing required packages. You may be prompted for your password." | |
sudo apt-get install v4l-utils python3 python3-pip python3-virtualenv git | |
mkdir -p "${OPENSEE_INSTALL_PATH}" | |
cd "${OPENSEE_INSTALL_PATH}" | |
if [[ ! -d OpenSeeFace ]];then | |
echo ">> Looks like we haven't downloaded OpenSeeFace yet. Grabbing it now." | |
git clone https://github.com/emilianavt/OpenSeeFace | |
fi | |
if [[ ! -f env/bin/python ]];then | |
echo ">> Creating a virtual Python environment for running OpenSeeFace." | |
virtualenv -p python3 env | |
fi | |
source env/bin/activate | |
# Even though virtualenv should be setting the environment variable here, it may break for people | |
# using Pyenv or similar, so use an explicit path. | |
echo ">> Installing Python requirements." | |
pip3 install onnxruntime opencv-python pillow numpy | |
OPTIONS="$(v4l2-ctl --list-devices|grep -v '^ '|sed -r '/^\s*$/d')" | |
# Change the Internal Field Separator to make Bash's array functionality recognize each entry by line | |
# rather than blank space. | |
echo "${OPTIONS}" | |
OIFS=$IFS | |
IFS=$'\n' | |
PS3="Select the camera you wish to use with OpenSeeFace: " | |
select CAMERA_SELECTION in ${OPTIONS}; do | |
echo "Selected camera: ${CAMERA_SELECTION}" | |
break | |
done | |
# Set the Internal Field Separator back to normal before we end up with any weird bugs. | |
IFS=$OIFS | |
CAMERA_SELECTION="$(echo ${CAMERA_SELECTION}|sed -e 's/[(].*//')" | |
echo ">> Building launch script." | |
# In Ubuntu, the ~/bin directory is automatically added to PATH if it exists at startup, | |
# so this shouldn't require extra configuration to persist, though any open shell windows | |
# may not be informed. | |
mkdir -p "${PERSONAL_BIN}" | |
# Do the initial, interpolated lines. | |
cat << EOF > "${PERSONAL_BIN}/${EXECUTABLE_NAME}" | |
#! /bin/bash | |
# Bash script for running OpenSeeFace. | |
set -e | |
CAMERA_LINE='${CAMERA_SELECTION}' | |
OPENSEEFACE_DIR='${OPENSEE_INSTALL_PATH}' | |
OPENSEE_INTERFACE='${OPENSEE_INTERFACE}' | |
OPENSEE_PORT='${OPENSEE_PORT}' | |
EOF | |
# Append the literal script portion. | |
cat << 'EOF' >> "${PERSONAL_BIN}/${EXECUTABLE_NAME}" | |
CAMERA=$(v4l2-ctl --list-devices | grep "${CAMERA_LINE}" -A 1| tail -1|sed -E 's#/dev/video##'|xargs) | |
cd "${OPENSEEFACE_DIR}" | |
source env/bin/activate | |
cd OpenSeeFace | |
python facetracker.py -c "${CAMERA}" -W 1280 -H 720 --discard-after 0 --scan-every 0 --max-feature-updates 900 --ip ${OPENSEE_INTERFACE} --port ${OPENSEE_PORT} > /dev/null & | |
BACKGROUNDED="${!}" | |
# This should run the VTuber Studio application. | |
steam steam://rungameid/1325860 | |
trap ctrl_c INT | |
function ctrl_c() { | |
kill "${BACKGROUNDED}" | |
echo "Done." | |
exit 0 | |
} | |
echo "When you're finished, hit CTRL+C to kill the tracker. This will not kill VTube Studio." | |
while :;do | |
read | |
done | |
EOF | |
chmod +755 "${PERSONAL_BIN}/${EXECUTABLE_NAME}" | |
echo ">> FINISHED! You are now set up to use OpenSeeFace. You can re-run this script if your installation breaks or you want to change cameras." | |
echo ">> TO BEGIN:" | |
echo "" | |
echo "Start a new terminal and type in ${EXECUTABLE_NAME}. This will launch OpenSeeFace and VTube Studio." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment