forked from Hydrosys4/Master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
photomod-fswebcam.py
76 lines (61 loc) · 1.91 KB
/
photomod-fswebcam.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
import time
from time import sleep
import datetime
import os
import sys
from subprocess import Popen, PIPE
def saveshot(filepath,realshot=True):
shottaken=False
currentdate=datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
print "Current date and time: " , currentdate
cam_list = "/dev/video0"
if cam_list:
gonext=True
if gonext:
if realshot:
filepath=os.path.join(filepath, currentdate+".jpg")
else:
filepath=os.path.join(filepath, "testimage.jpg")
print filepath
filexist=os.path.isfile(filepath)
print "file already exist = ", filexist
if filexist:
os.rename(filepath, filepath + ".bak")
#p = sub.Popen("fswebcam -d "+ cam_list +" -r 1280x1024 -S 35 --jpeg 95 " + filepath, stdout=sub.PIPE, stderr=sub.PIPE)
#p = os.popen("fswebcam -d "+ cam_list +" -r 1280x1024 -S 35 --jpeg 95 " + filepath)
myproc = Popen("fswebcam -d "+ cam_list +" -r 1280x1024 -S 35 --jpeg 95 " + filepath, shell=True, stdout=PIPE, stderr=PIPE)
#sleep(10)
print myproc.stdout.readline()
print 'Return code was ', myproc.returncode
sleep(2)
newfilexist=os.path.isfile(filepath)
print "file was created = ", newfilexist
shottaken=True
if not newfilexist:
shottaken=False
if filexist:
os.rename(filepath + ".bak", filepath)
print "Picture take = " ,shottaken
else:
print "camera not connected"
return shottaken
if __name__ == '__main__':
"""
prova funzioni di camera
"""
#Determine if the application is a py/pyw or a frozen exe.
if hasattr(sys, 'frozen'):
# If run from exe
dir_path = os.path.dirname(sys.executable)
elif '__file__' in locals():
# If run from py
dir_path = os.path.dirname(os.path.realpath(__file__))
else:
# If run from command line
dir_path = sys.path[0]
print dir_path
filepath=os.path.join(dir_path, "static")
filepath=os.path.join(filepath, "cameratest")
print filepath
saveshot(filepath,False)
#saveshot()