generated from eanorambuena/Driver
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37038f7
commit 331de4c
Showing
24 changed files
with
314 additions
and
84 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config.py |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from eggdriver.resources.utils import * | ||
from eggdriver.resources.web import * | ||
from eggdriver.resources.math import * | ||
from eggdriver.resources.video import * | ||
|
||
author="eanorambuena" | ||
author_email="[email protected]" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import cv2 | ||
import mediapipe as mp | ||
import numpy as np | ||
from eggdriver.resources.video.effects import * | ||
from eggdriver.resources.video.backgrounds import * | ||
|
||
counterIterator = 0 | ||
|
||
def forever(): | ||
return True | ||
|
||
def stop(): | ||
return input() | ||
|
||
def itself(var): | ||
return var | ||
|
||
def count(value = 100, step = 1): | ||
global counterIterator | ||
counterIterator += step | ||
print(value - counterIterator) | ||
result = counterIterator < value | ||
return result | ||
|
||
defaultEffect = [(itself, [])] | ||
defaultCondition = (count, [100]) | ||
defaultUser = 'WEBCAM' | ||
|
||
def changeBackground(image, bg_image, background_effects = defaultEffect): | ||
th, th_inv = removeBG(image) | ||
bg = maskImage(bg_image, th_inv) | ||
for ef in background_effects: | ||
args = [bg] + ef[1] | ||
bg = ef[0](*args) | ||
fg = maskImage(image, th) | ||
final = cv2.bitwise_or(bg, fg) | ||
return final | ||
|
||
def capture(): | ||
print("Turning on the WebCam...") | ||
return cv2.VideoCapture(0) | ||
|
||
def applyEffects(image, effects, background_effects): | ||
for ef in effects: | ||
args = [image] + ef[1] | ||
image = ef[0](*args) | ||
return changeBackground(image, image, background_effects) | ||
|
||
def webCam(user = defaultUser, effects = defaultEffect, background_effects = defaultEffect, number_of_windows = 1, apply_effects_to = "all", condition = defaultCondition): | ||
global counterIterator | ||
counterIterator = 0 | ||
cap = capture() | ||
while (cap.isOpened()): | ||
ret, image = cap.read() | ||
if ret == True and condition[0](*condition[1]): | ||
for i in range(number_of_windows): | ||
if apply_effects_to == "all": | ||
image = applyEffects(image, effects, background_effects) | ||
else: | ||
image = applyEffects(image, [effects[i]], [background_effects[i]]) | ||
cv2.imshow(user, image) | ||
if cv2.waitKey(1) & 0xFF == ord('s'): | ||
break | ||
else: break | ||
cap.release() | ||
cv2.destroyAllWindows() | ||
|
||
def changeBackgroundWebCam(user = defaultUser, new_background = solidBackground(), effects = defaultEffect, condition = defaultCondition): | ||
webCam(user, [(changeBackground, [new_background])] + effects, condition) | ||
|
||
class WEBCAM(): | ||
def __init__(self, user, condition = count, *args): | ||
self.user = user | ||
self.condition = (condition, args) | ||
def default(self, effects = defaultEffect, background_effects = defaultEffect, number_of_windows = 1, apply_effects_to = "all",): | ||
webCam(user = self.user, | ||
effects = effects, | ||
background_effects = background_effects, | ||
number_of_windows = number_of_windows, | ||
apply_effects_to = apply_effects_to, | ||
condition = self.condition) | ||
def changeBackground(self, new_background, effects = defaultEffect, background_effects = defaultEffect, number_of_windows = 1, apply_effects_to = "all"): | ||
changeBackgroundWebCam(user = self.user, | ||
new_background = new_background, | ||
effects = effects, | ||
background_effects = background_effects, | ||
number_of_windows = number_of_windows, | ||
apply_effects_to = apply_effects_to, | ||
condition = self.condition) | ||
|
||
class User(): | ||
def __init__(self, username = "video"): | ||
self.user = username | ||
self.background = 0 | ||
self.ef = defaultEffect | ||
def setBackground(self, background): | ||
self.background = background | ||
def addEffect(self, *effects): | ||
self.ef = effects | ||
def meeting(self, condition = forever, *args): | ||
if type(self.background) == int: | ||
webCam(self.user, condition, *args) | ||
else: | ||
changeBackgroundWebCam(self.user, self.background, condition, *args) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import cv2 | ||
import numpy as np | ||
|
||
def solidBackground(shape = (480, 640, 3), color = (0, 255, 0)): | ||
bg_image = np.ones(shape, dtype = np.uint8) | ||
bg_image[:] = color | ||
return bg_image | ||
|
||
def imageBackground(source): | ||
return cv2.imread(source) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import cv2 | ||
import numpy as np | ||
import mediapipe as mp | ||
|
||
def removeBG(image): | ||
mp_selfie_segmentation = mp.solutions.selfie_segmentation | ||
selfie_segmentation = mp_selfie_segmentation.SelfieSegmentation(model_selection = 1) | ||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | ||
results = selfie_segmentation.process(image) | ||
_, th = cv2.threshold(results.segmentation_mask, 0.75, 255, cv2.THRESH_BINARY) | ||
th = th.astype(np.uint8) | ||
th_inv = cv2.bitwise_not(th) | ||
return th, th_inv | ||
|
||
def maskImage(image, mask): | ||
return cv2.bitwise_and(image, image, mask = mask) | ||
|
||
def blur(image): | ||
return cv2.GaussianBlur(image, (15, 15), 0) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ver = "0.0.1a10" | ||
|
||
"""Simply the current installed eggdriver version. The version information is | ||
stored in the regular eggdriver module as eggdriver.ver'. Keeping the version | ||
information also available in a separate module allows you to test the | ||
eggdriver version without importing the main eggdriver module. | ||
""" | ||
|
||
__all__ = ["ver"] |
Binary file not shown.
Binary file not shown.
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
Oops, something went wrong.