-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
71 lines (58 loc) · 1.72 KB
/
main.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
import cv2
import os
import requests
from PIL import Image
from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
cam = cv2.VideoCapture('./video.mp4')
try:
if not os.path.exists('image_data'):
os.makedirs('image_data')
except OSError:
print('Error: Creating directory of image_data')
try:
if not os.path.exists('deep_image'):
os.makedirs('deep_image')
except OSError:
print('Error: Creating directory of deep_image')
currentframe = 0
while True:
ret, frame = cam.read()
if ret:
name = './image_data/frame' + str(currentframe) + '.jpg'
print('Creating...' + name)
cv2.imwrite(name, frame)
currentframe += 1
allframes = currentframe
else:
break
cam.release()
cv2.destroyAllWindows()
currentframe = 0
while True:
if currentframe < allframes:
r = requests.post(
"https://api.deepai.org/api/deepdream",
files={
'image': open('./image_data/frame' + str(currentframe) + '.jpg', 'rb'),
},
headers={'api-key': 'PUT API KEY FOR DEEPAI HERE'}
)
response = r.json()
print(response)
imagelink = requests.get(response['output_url'])
file = open("./deep_image/" + str(currentframe) + '.jpg', "wb")
file.write(imagelink.content)
file.close()
currentframe += 1
else:
break
cap = cv2.VideoCapture("video.mp4")
fpsa = cap.get(cv2.CAP_PROP_FPS)
print(fpsa)
im = Image.open('./deep_image/0.jpg')
print(im.size)
print(type(im.size))
w, h = im.size
clip = ImageSequenceClip("./deep_image/", fps = fpsa)
clip.write_videofile("deep_video.mp4", fps=clip.fps,
audio_bitrate="1000k", bitrate="4000k")