changed the way to call Point2D functions.
Added missing point array generation code
This commit is contained in:
parent
3a9be4e4ea
commit
d35fc3b1ea
2 changed files with 26 additions and 11 deletions
|
|
@ -77,6 +77,21 @@ def generate_point_array_from_image(image):
|
||||||
|
|
||||||
if image_hash in cached_point_arrays:
|
if image_hash in cached_point_arrays:
|
||||||
return [Point2D(point["x"], point["y"], tuple(point["color"])) for point in cached_point_arrays[image_hash]]
|
return [Point2D(point["x"], point["y"], tuple(point["color"])) for point in cached_point_arrays[image_hash]]
|
||||||
|
|
||||||
|
width, height = image.size
|
||||||
|
pixel_array = []
|
||||||
|
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
pixel = image.getpixel((x, y))
|
||||||
|
if pixel != (0, 0, 0): # any non-white pixels
|
||||||
|
point = {"x": x, "y": y, "color": pixel}
|
||||||
|
pixel_array.append(point)
|
||||||
|
|
||||||
|
cached_point_arrays[image_hash] = pixel_array
|
||||||
|
save_cached_point_arrays(cached_point_arrays)
|
||||||
|
|
||||||
|
return [Point2D(point["x"], point["y"], tuple(point["color"])) for point in pixel_array]
|
||||||
|
|
||||||
|
|
||||||
def generate_image_from_point_array(points: list[Point2D], width: int, height: int) -> Image:
|
def generate_image_from_point_array(points: list[Point2D], width: int, height: int) -> Image:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
||||||
import Point2D
|
from Point2D import interpolate_point_pairs, mirror_points, generate_image_from_point_array, generate_point_array_from_image, pair_points
|
||||||
from ProotState import ProotState
|
from ProotState import ProotState
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
@ -78,10 +78,10 @@ startT = curr_time = round(time.time()*1000)
|
||||||
|
|
||||||
# generate pixel arrays from each image
|
# generate pixel arrays from each image
|
||||||
# TODO ^ storing and loading lists of points will take away this step. (it will require a dedicated script to precompute these)
|
# TODO ^ storing and loading lists of points will take away this step. (it will require a dedicated script to precompute these)
|
||||||
points_left_eye_open = Point2D.generate_point_array_from_image(image_left_eye_open)
|
points_left_eye_open = generate_point_array_from_image(image_left_eye_open)
|
||||||
points_left_eye_closed = Point2D.generate_point_array_from_image(image_left_eye_closed)
|
points_left_eye_closed = generate_point_array_from_image(image_left_eye_closed)
|
||||||
points_left_nose = Point2D.generate_point_array_from_image(image_left_nose)
|
points_left_nose = generate_point_array_from_image(image_left_nose)
|
||||||
points_left_mouth = Point2D.generate_point_array_from_image(image_left_mouth)
|
points_left_mouth = generate_point_array_from_image(image_left_mouth)
|
||||||
|
|
||||||
endT = curr_time = round(time.time()*1000)
|
endT = curr_time = round(time.time()*1000)
|
||||||
print("generating pixel array took: " + str(endT - startT) + " ms")
|
print("generating pixel array took: " + str(endT - startT) + " ms")
|
||||||
|
|
@ -93,7 +93,7 @@ startT = curr_time = round(time.time()*1000)
|
||||||
|
|
||||||
#calculate the point pairs between the open and closed left eye
|
#calculate the point pairs between the open and closed left eye
|
||||||
# TODO look into precomputing and storing these animations before runtime
|
# TODO look into precomputing and storing these animations before runtime
|
||||||
left_eye_blink_pairs = Point2D.pair_points(points_left_eye_open, points_left_eye_closed)
|
left_eye_blink_pairs = pair_points(points_left_eye_open, points_left_eye_closed)
|
||||||
|
|
||||||
endT = curr_time = round(time.time()*1000)
|
endT = curr_time = round(time.time()*1000)
|
||||||
print("pairing points for one eye took: " + str(endT - startT) + " ms")
|
print("pairing points for one eye took: " + str(endT - startT) + " ms")
|
||||||
|
|
@ -107,13 +107,13 @@ 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()
|
||||||
|
|
||||||
left_eye = Point2D.interpolate_point_pairs(left_eye_blink_pairs, alpha/10)
|
left_eye = interpolate_point_pairs(left_eye_blink_pairs, alpha/10)
|
||||||
right_eye = Point2D.mirror_points(left_eye)
|
right_eye = mirror_points(left_eye)
|
||||||
nose = points_left_nose + Point2D.mirror_points(points_left_nose)
|
nose = points_left_nose + mirror_points(points_left_nose)
|
||||||
mouth = points_left_mouth + Point2D.mirror_points(points_left_mouth)
|
mouth = points_left_mouth + mirror_points(points_left_mouth)
|
||||||
face = left_eye + right_eye + nose + mouth
|
face = left_eye + right_eye + nose + mouth
|
||||||
|
|
||||||
interpolated_face_image = Point2D.generate_image_from_point_array(face, 128, 32)
|
interpolated_face_image = generate_image_from_point_array(face, 128, 32)
|
||||||
offscreen_interpolated_canvas.SetImage(interpolated_face_image, unsafe=False)
|
offscreen_interpolated_canvas.SetImage(interpolated_face_image, unsafe=False)
|
||||||
blinkFrameCanvases.append(offscreen_interpolated_canvas)
|
blinkFrameCanvases.append(offscreen_interpolated_canvas)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue