Added timing function to each step of precomputing the animations.
Added ProotState class and functions to structure and abstract blinking logic.
This commit is contained in:
parent
3bf5083b99
commit
a5246021f9
1 changed files with 63 additions and 0 deletions
|
|
@ -20,6 +20,26 @@ from PIL import Image
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.optimize import linear_sum_assignment
|
from scipy.optimize import linear_sum_assignment
|
||||||
|
|
||||||
|
|
||||||
|
class ProotState:
|
||||||
|
def __init__(self):
|
||||||
|
self.current_blink_state = 0
|
||||||
|
self.desired_blink_state = 0
|
||||||
|
|
||||||
|
def startBlink(self):
|
||||||
|
self.desired_blink_state = 10
|
||||||
|
|
||||||
|
def next_blink_state(self) -> int:
|
||||||
|
if self.current_blink_state == self.desired_blink_state and self.current_blink_state == 10:
|
||||||
|
self.desired_blink_state = 0
|
||||||
|
return 10
|
||||||
|
|
||||||
|
if self.current_blink_state < self.desired_blink_state:
|
||||||
|
self.current_blink_state += 1
|
||||||
|
else:
|
||||||
|
self.current_blink_state -= 1
|
||||||
|
|
||||||
|
return self.current_blink_state
|
||||||
|
|
||||||
class Point2D:
|
class Point2D:
|
||||||
x = 0
|
x = 0
|
||||||
|
|
@ -140,14 +160,40 @@ def interpolate_point_pairs(pairs: list[tuple[Point2D, Point2D]], percentage: fl
|
||||||
return interpolated_points
|
return interpolated_points
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("start loading images")
|
||||||
|
startT = curr_time = round(time.time()*1000)
|
||||||
|
|
||||||
Image1 = Image.open("faces/eyeLeftOpen.png")
|
Image1 = Image.open("faces/eyeLeftOpen.png")
|
||||||
Image2 = Image.open("faces/eyeLeftClosed.png")
|
Image2 = Image.open("faces/eyeLeftClosed.png")
|
||||||
|
|
||||||
|
endT = curr_time = round(time.time()*1000)
|
||||||
|
print("loading images took: " + str(endT - startT))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("start generating pixel array")
|
||||||
|
startT = curr_time = round(time.time()*1000)
|
||||||
|
|
||||||
pixelArray1 = generate_point_array_from_image(Image1)
|
pixelArray1 = generate_point_array_from_image(Image1)
|
||||||
pixelArray2 = generate_point_array_from_image(Image2)
|
pixelArray2 = generate_point_array_from_image(Image2)
|
||||||
|
|
||||||
|
endT = curr_time = round(time.time()*1000)
|
||||||
|
print("generating pixel array took: " + str(endT - startT))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("start pairing points for one eye")
|
||||||
|
startT = curr_time = round(time.time()*1000)
|
||||||
|
|
||||||
LeftEyeBlinkPairs = pair_points(pixelArray1, pixelArray2)
|
LeftEyeBlinkPairs = pair_points(pixelArray1, pixelArray2)
|
||||||
|
|
||||||
|
endT = curr_time = round(time.time()*1000)
|
||||||
|
print("pairing points for one eye took: " + str(endT - startT))
|
||||||
|
|
||||||
|
|
||||||
DesiredBlinkState = 10
|
DesiredBlinkState = 10
|
||||||
currentBlinkState = 0
|
currentBlinkState = 0
|
||||||
|
|
@ -155,6 +201,9 @@ currentBlinkState = 0
|
||||||
blinkFrameCanvases = []
|
blinkFrameCanvases = []
|
||||||
|
|
||||||
|
|
||||||
|
print("start populating matrices for each blink frame")
|
||||||
|
startT = curr_time = round(time.time()*1000)
|
||||||
|
|
||||||
for alpha in range(0,11):
|
for alpha in range(0,11):
|
||||||
offscreen_interpolated_canvas = matrix.CreateFrameCanvas()
|
offscreen_interpolated_canvas = matrix.CreateFrameCanvas()
|
||||||
leftEye = interpolate_point_pairs(LeftEyeBlinkPairs, alpha/10)
|
leftEye = interpolate_point_pairs(LeftEyeBlinkPairs, alpha/10)
|
||||||
|
|
@ -163,9 +212,23 @@ for alpha in range(0,11):
|
||||||
interpolated_image = generate_image_from_point_array(face, 128, 32)
|
interpolated_image = generate_image_from_point_array(face, 128, 32)
|
||||||
offscreen_interpolated_canvas.SetImage(interpolated_image, unsafe=False)
|
offscreen_interpolated_canvas.SetImage(interpolated_image, unsafe=False)
|
||||||
blinkFrameCanvases.append(offscreen_interpolated_canvas)
|
blinkFrameCanvases.append(offscreen_interpolated_canvas)
|
||||||
|
|
||||||
|
endT = curr_time = round(time.time()*1000)
|
||||||
|
print("populating matrices for each blink frame took: " + str(endT - startT))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def move_option(current_option: int, desired_option: int) -> int:
|
||||||
|
if current_option == desired_option:
|
||||||
|
return current_option
|
||||||
|
|
||||||
|
if current_option < desired_option:
|
||||||
|
current_option += 1
|
||||||
|
else:
|
||||||
|
current_option -= 1
|
||||||
|
|
||||||
|
return current_option
|
||||||
|
|
||||||
|
|
||||||
def update_screen():
|
def update_screen():
|
||||||
global DesiredBlinkState, currentBlinkState, blinkFrameCanvases, matrix
|
global DesiredBlinkState, currentBlinkState, blinkFrameCanvases, matrix
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue