-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdolus.py
144 lines (134 loc) · 5.93 KB
/
dolus.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import pyvirtualcam
import numpy as np
import cv2 as cv
import click
from click_help_colors import HelpColorsGroup, HelpColorsCommand
import re, requests, urllib.parse, urllib.request
import pafy
@click.group(
cls=HelpColorsGroup, help_headers_color="yellow", help_options_color="cyan")
@click.version_option('0.1.1')
def main():
"""Dolus - Change your live video from the terminal"""
@main.command('cartoonify', help = 'Gives your face a cartoonish effect')
def cartoonify():
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
b = cv.VideoCapture(0)
while True:
isTrue, frame = b.read()
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
gray = cv.medianBlur(gray, 3)
edges = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 9, 10)
# Making a Cartoon of the image
color = cv.bilateralFilter(frame, 12, 250, 250)
cartoon = cv.bitwise_and(color, color, mask=edges)
cartoon_image = cv.stylization(frame, sigma_s=150, sigma_r=0.25)
frame = cartoon_image
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
frame = cv.resize(frame, (640, 480))
cam.send(frame)
cam.sleep_until_next_frame()
def canny_img(photo):
canny = cv.Canny(photo, 125, 175)
return canny
@main.command('watercolor', help = 'Gives your face a watercolor effect')
def watercolor():
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
b = cv.VideoCapture(0)
while True:
isTrue, frame = b.read()
frame = cv.stylization(frame, sigma_s=60, sigma_r=0.6)
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
frame = cv.resize(frame, (640, 480))
cam.send(frame)
cam.sleep_until_next_frame()
@main.command('pencil', help = 'Gives your face a pencil sketch effect')
def pencil():
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
b = cv.VideoCapture(0)
while True:
isTrue, frame = b.read()
pencil, color = cv.pencilSketch(frame, sigma_s=60, sigma_r=0.5, shade_factor=0.010)
frame = cv.cvtColor(pencil, cv.COLOR_BGR2RGB)
frame = cv.resize(frame, (640, 480))
cam.send(frame)
cam.sleep_until_next_frame()
@main.command('econify', help = 'Gives your face a hacker like theme')
def econify():
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
b = cv.VideoCapture(0)
while True:
isTrue, frame = b.read()
canny = canny_img(frame)
cv.imwrite('canny.jpg', canny)
img = cv.imread('canny.jpg')
blue, g, r = cv.split(img)
blank = np.zeros(img.shape[:2], dtype='uint8')
green = cv.merge([blank,g,blank])
frame = green
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
frame = cv.resize(frame, (640, 480))
cam.send(frame)
cam.sleep_until_next_frame()
@main.command('ytvid', help = 'Replace your video with a youtube video')
@click.argument('song', nargs = 1)
def ytvid(song):
music_name = song
query_string = urllib.parse.urlencode({"search_query": music_name})
formatUrl = urllib.request.urlopen("https://www.youtube.com/results?" + query_string)
search_results = re.findall(r"watch\?v=(\S{11})", formatUrl.read().decode())
clip = requests.get("https://www.youtube.com/watch?v=" + "{}".format(search_results[0]))
clip2 = "https://www.youtube.com/watch?v=" + "{}".format(search_results[0])
video = pafy.new(clip2)
video = video.getbest(preftype="mp4")
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
b = cv.VideoCapture(video.url)
while True:
isTrue, frame = b.read()
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
frame = cv.resize(frame, (640, 480))
cam.send(frame)
cam.sleep_until_next_frame()
@main.command('negative', help = 'Inverts your face')
def negative():
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
b = cv.VideoCapture(0)
while True:
isTrue, frame = b.read()
frame = cv.bitwise_not(frame)
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
frame = cv.resize(frame, (640, 480))
cam.send(frame)
cam.sleep_until_next_frame()
@main.command('merge', help = 'Merges your live feed with a youtube video')
@click.argument('song', nargs = 1)
def merge(song):
with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
music_name = song
query_string = urllib.parse.urlencode({"search_query": music_name})
formatUrl = urllib.request.urlopen("https://www.youtube.com/results?" + query_string)
search_results = re.findall(r"watch\?v=(\S{11})", formatUrl.read().decode())
clip = requests.get("https://www.youtube.com/watch?v=" + "{}".format(search_results[0]))
clip2 = "https://www.youtube.com/watch?v=" + "{}".format(search_results[0])
video = pafy.new(clip2)
video = video.getbest(preftype="mp4")
video=cv.VideoCapture(video.url)
c = cv.VideoCapture(0)
while c.isOpened():
ret, frame1 = c.read()
ret, frame=video.read()
frame=cv.resize(frame, (640, 480))
frame1=cv.resize(frame1, (640,480))
masked = cv.add(frame,frame1)
masked = cv.cvtColor(masked, cv.COLOR_BGR2RGB)
cam.send(masked)
cam.sleep_until_next_frame()
if __name__ == '__main__':
main()