forked from victordibia/handtracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splatter.py
27 lines (24 loc) · 1.06 KB
/
splatter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import cv2
import random
# from threading import Timer
class Splatter:
def __init__(self, topleft, bottomright, color=None):
imgnum = str(random.randint(1,8))
self.outline = cv2.imread(str('splatter-'+imgnum+'.png'), -1)
self.outline = cv2.resize(self.outline, (bottomright[0]-topleft[0], bottomright[1]-topleft[1]), interpolation = cv2.INTER_AREA)
cv2.cvtColor(self.outline, cv2.COLOR_BGRA2RGBA) #remember to try to convert frame to RGBA also
if color == None:
self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
else:
self.color = color
self.outline[:, :, 0:3][self.outline[:, :, 3] != 0] = self.color
self.outline[:, :, 0:3][self.outline[:, :, 3] == 0] = (0, 0, 0)
self.opacity = 1
self.topleft = topleft
self.bottomright = bottomright
def fade(self):
#self.outline[self.outline[:, :, 3] >= 4] -= 4
if self.opacity > 0:
self.opacity -= 0.1
if self.opacity < 0:
self.opacity = 0