Skip to content

Commit

Permalink
add_only_build_VTuber
Browse files Browse the repository at this point in the history
  • Loading branch information
KennardWang committed Oct 26, 2023
1 parent c25702d commit 14474a7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
7 changes: 4 additions & 3 deletions UnityAssets/Script/Momose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void init()
{
// Initialize IP and port
const string IP = "127.0.0.1";
int PORT = PlayerPrefs.GetInt("port");
int PORT = PlayerPrefs.GetInt("port"); // build full project
//int PORT = 14514; // only build VTuber
Debug.Log(PORT);

// Socket initialization
Expand All @@ -82,7 +83,7 @@ void init()
serverSocket.Bind(ipEndPoint);
serverSocket.Listen(100);

// start a new thread to update parameters
// Start a new thread to update parameters
Thread connect = new Thread(new ThreadStart(paraUpdate));
connect.Start();

Expand Down Expand Up @@ -184,7 +185,7 @@ void paraUpdate()
recData = new byte[1024];
int len = clientSocket.Receive(recData);

// client sends data by group, check if no data comes, then enter next group(loop)
// Client sends data by group, check if no data comes, then enter next group(loop)
if (len == 0)
{
SocketConnect();
Expand Down
6 changes: 3 additions & 3 deletions UnityAssets/Script/Test/SocketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class SocketTest : MonoBehaviour
{
// basic setting
// Basic setting
Socket clientSocket;
Socket serverSocket;
const string IP = "127.0.0.1";
Expand All @@ -29,7 +29,7 @@ void init()
serverSocket.Bind(ipEndPoint);
serverSocket.Listen(100);

// start a new thread to update parameters
// Start a new thread to update parameters
Thread connect = new Thread(new ThreadStart(DataReception));
connect.Start();
}
Expand Down Expand Up @@ -69,7 +69,7 @@ void DataReception()
continue;
}

// change data type to string, then to float
// Change data type to string, then to float
string str = Encoding.ASCII.GetString(recData, 0, len);
string[] para = str.Split(' '); // parameters group

Expand Down
11 changes: 5 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run():
cov_process=0.01,
cov_measure=0.1) for _ in range(8)]

# Establish a TCP connection to unity
# Establish a TCP connection to Unity
if args.connect:
address = ('127.0.0.1', args.port)
sock = Socket()
Expand All @@ -82,7 +82,7 @@ def run():

# Loop
# 1. Face detection, draw face and iris landmarks
# 2. Pose estimation and stabilization (face + iris), calculate and calibrate data if low error
# 2. Pose estimation and stabilization (face + iris), calculate and calibrate data if error is low
# 3. Data transmission with socket

# Face detection on every odd frame
Expand All @@ -107,13 +107,13 @@ def run():
if facebox is not None:
prev_boxes.append(facebox)

# Mark face and iris on every frame
# Mark face and iris on each frame
if not args.gpu:
face = dlib.rectangle(left=facebox[0], top=facebox[1],
right=facebox[2], bottom=facebox[3])
marks = utils.shape_to_np(shape_predictor(frame, face))
else:
# Draw landmarks on first frame or every even frame
# Draw landmarks on first frame or each even frame
if len(prev_marks) == 0 \
or frame_count == 1 \
or frame_count % 2 == 0:
Expand Down Expand Up @@ -156,7 +156,6 @@ def run():
steady_pose.append(ps_stb.state[0])

if args.connect:
# Calibrate: pitch(15 is camera angle)
# head
roll = np.clip(
-(180 + np.degrees(steady_pose[2])), -50, 50)
Expand Down Expand Up @@ -242,7 +241,7 @@ def run():
if cv2.waitKey(1) & 0xFF == ord('q'): # press q to exit
break

# Close all if terminated
# Close all if program is terminated
cap.release()
if args.connect:
sock.close()
Expand Down
8 changes: 4 additions & 4 deletions sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class Socket:
"""Socket class for message transmission"""
"""Socket class for message data transmission"""

def __init__(self):
self.roll = 0.0 # rotate along inner axis
Expand All @@ -25,7 +25,7 @@ def __init__(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

def update_all(self, roll, pitch, yaw, eyeOpenLeft, eyeOpenRight, eyeballX, eyeballY, eyebrowLeft, eyebrowRight, mouthWidth, mouthOpen):
"""Update all variables"""
"""Update all parameters"""
self.roll = roll
self.pitch = pitch
self.yaw = yaw
Expand All @@ -38,14 +38,14 @@ def update_all(self, roll, pitch, yaw, eyeOpenLeft, eyeOpenRight, eyeballX, eyeb
self.mouthWidth = mouthWidth
self.mouthOpen = mouthOpen

# Update last frame
# Update some values of last frames
self.eyeOpenLeftLast = self.eyeOpenLeft
self.eyeOpenRightLast = self.eyeOpenRight
self.eyebrowLeftLast = self.eyebrowLeft
self.eyebrowRightLast = self.eyebrowRight

def conv2msg(self):
"""Convert all variables to message data"""
"""Convert all parameters to message data"""
self.msg = '%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f' % \
(self.roll, self.pitch, self.yaw, self.eyeOpenLeft, self.eyeOpenRight,
self.eyeballX, self.eyeballY, self.eyebrowLeft, self.eyebrowRight, self.mouthWidth, self.mouthOpen)
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def draw_FPS(frame, FPS):

def calibrate_eyeOpen(ear, eyeOpenLast, gpu):
"""Calibrate parameter eyeOpen"""
flag = False # jump out current state
flag = False # jump out of current state

if not gpu:
# CPU env
Expand Down Expand Up @@ -208,7 +208,7 @@ def calibrate_eyeball(eyeballX, eyeballY):

def calibrate_eyebrow(bar, eyebroLast, gpu):
"""Calibrate parameter eyebrow"""
flag = False # jump out current state
flag = False # jump out of current state

if not gpu:
# CPU env
Expand Down

0 comments on commit 14474a7

Please sign in to comment.