-
Notifications
You must be signed in to change notification settings - Fork 0
/
Live-Cam-Capture.py
41 lines (36 loc) · 1.16 KB
/
Live-Cam-Capture.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
#Import libraries
import urllib.request
import time
from datetime import datetime
import os
import filecmp
URL = input("Please enter the URL: ")
#Create new folder
path = "Capture-"+ str(datetime.today().year) + str(datetime.today().month) +str(datetime.today().day)
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
exit()
else:
print ("Successfully created the directory %s " % path)
#Capture first image
contador =0
filename = os.path.join(path, "Image" + str(contador) + ".jpg")
urllib.request.urlretrieve(URL, filename)
print("Saved Images: " + str(contador+1))
contador=contador+1
time.sleep(60)
#Capture one image every 60 seconds
while True:
filename = os.path.join(path, "Image" + str(contador) + ".jpg")
urllib.request.urlretrieve(URL, filename)
#If previously captured image is the same, then it is deleted
if filecmp.cmp(filename, os.path.join(path, "Image" + str(contador-1) + ".jpg"), shallow=False):
print("Duplicated image")
os.remove(filename)
time.sleep(60)
else:
print("Saved Images: " + str(contador+1))
contador=contador+1
time.sleep(60)