1 | #Do not forget |
---|
2 | #export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:../../src:/home/delerue/aravis/src/ |
---|
3 | #export LD_LIBRARY_PATH=../../src/.libs:/home/delerue/aravis/src/.libs |
---|
4 | #On raspberry replace delerue by pi |
---|
5 | |
---|
6 | #Run with python3 |
---|
7 | |
---|
8 | import sys |
---|
9 | sys.path.append('/home/delerue/python-aravis/') |
---|
10 | sys.path.append('/home/pi/python-aravis/') |
---|
11 | |
---|
12 | import os |
---|
13 | import os.path |
---|
14 | import aravis |
---|
15 | import numpy as np |
---|
16 | from aravis import Camera |
---|
17 | from PIL import Image |
---|
18 | import matplotlib.pyplot as plt |
---|
19 | from io import BytesIO |
---|
20 | import time |
---|
21 | |
---|
22 | import requests |
---|
23 | import ftplib |
---|
24 | |
---|
25 | # Import smtplib for the actual sending function |
---|
26 | import smtplib |
---|
27 | from email.mime.text import MIMEText |
---|
28 | from validate_email import validate_email |
---|
29 | |
---|
30 | url='http://10.0.1.133/jpg/image.jpg' |
---|
31 | run_IR_File='/home/delerue/run_IR.txt' |
---|
32 | save_IR_File='/home/delerue/save_IR.txt' |
---|
33 | path_images='/home/delerue/IR_images/' |
---|
34 | |
---|
35 | ids = aravis.get_device_ids() #List visible cameras |
---|
36 | cam = Camera(ids[0]) #get the first camera |
---|
37 | cam.start_acquisition_continuous(nb_buffers=1) |
---|
38 | fig = plt.figure(figsize=(14,7)) |
---|
39 | #fig = plt.figure(figsize=(16,9)) |
---|
40 | #fig = plt.figure(figsize=(4,3)) |
---|
41 | figIR=fig.add_subplot(121) |
---|
42 | figZavio=fig.add_subplot(122) |
---|
43 | #fid=open(run_IR_File,'w') |
---|
44 | #fid.close() |
---|
45 | iloop=1 |
---|
46 | while (os.path.isfile(run_IR_File))and(iloop<50): |
---|
47 | iloop=iloop+1 |
---|
48 | #print(iloop) |
---|
49 | try: |
---|
50 | imageZavioImg=Image.open(BytesIO(requests.get(url, auth=('admin', 'admin')).content)) |
---|
51 | imageIR = cam.pop_frame()# get next frame from camera |
---|
52 | imageIR = cam.pop_frame()# get next frame from camera |
---|
53 | except: |
---|
54 | print('Error reading images') |
---|
55 | |
---|
56 | imageZavio = np.array(imageZavioImg) |
---|
57 | #print frame |
---|
58 | figIR_img=figIR.imshow(imageIR) |
---|
59 | figIR.set_title('Infrarouge') |
---|
60 | figIR_img.set_cmap('jet') |
---|
61 | figIR_img.axes.get_xaxis().set_visible(False) |
---|
62 | figIR_img.axes.get_yaxis().set_visible(False) |
---|
63 | figZavio_img=figZavio.imshow(imageZavio) |
---|
64 | figZavio.set_title('Visible') |
---|
65 | figZavio_img.axes.get_xaxis().set_visible(False) |
---|
66 | figZavio_img.axes.get_yaxis().set_visible(False) |
---|
67 | #fig.set_cmap('hot') |
---|
68 | nowstr=time.strftime("%d/%m/%Y %H:%M:%S") |
---|
69 | nowfile=time.strftime("%Y_%m_%d_%H_%M_%S") |
---|
70 | plt.suptitle('Musee Sciences ACO\n'+nowstr, fontsize=32) |
---|
71 | plt.savefig(path_images+'latest.png') |
---|
72 | if os.path.isfile(save_IR_File): |
---|
73 | nowfilename='image_'+nowfile+'.png' |
---|
74 | plt.savefig(path_images+nowfilename) |
---|
75 | print('Image sauvee sous '+nowfilename) |
---|
76 | fid=open(path_images+nowfilename+".to_upload",'w') |
---|
77 | fid.close() |
---|
78 | try: |
---|
79 | fid=open(save_IR_File,'r') |
---|
80 | linemail=fid.readline() |
---|
81 | fid.close() |
---|
82 | except: |
---|
83 | print('Email file error') |
---|
84 | if validate_email(linemail.strip()): |
---|
85 | print(linemail.strip()+' is a valid email address!') |
---|
86 | fid=open(path_images+nowfilename+".to_email",'w') |
---|
87 | fid.write(linemail.strip()) |
---|
88 | fid.close() |
---|
89 | email_dest=linemail.strip() |
---|
90 | email_src=nowfilename |
---|
91 | while(len(email_src)>1): |
---|
92 | msg = MIMEText('Bonjour,\nVotre image infrarouge est disponible sur http://lal.delerue.org/ETALON/IR/' + email_src ) |
---|
93 | msg['Subject'] = 'Votre image infrarouge' |
---|
94 | msg['From'] = 'Visites@sciencesaco.fr' |
---|
95 | msg['From'] = 'Visites ACO <Visites@sciencesaco.fr>' |
---|
96 | # msg['From'] = 'Visites Musee Sciences ACO' |
---|
97 | msg['To'] = email_dest |
---|
98 | try: |
---|
99 | mails=smtplib.SMTP_SSL('lalrelay.in2p3.fr') |
---|
100 | mails.login('delerue@lal.in2p3.fr','IR&THz4SP') |
---|
101 | mails.sendmail('visites@sciencesaco.fr',msg['To'], msg.as_string()) |
---|
102 | mails.quit() |
---|
103 | print('msg envoye a ' + email_dest) |
---|
104 | os.remove(path_images+email_src+".to_email") |
---|
105 | email_src="" |
---|
106 | except: |
---|
107 | print('Envoie de courriel impossible') |
---|
108 | email_src="" |
---|
109 | else: |
---|
110 | print(linemail.strip()+' is not a valid email address!') |
---|
111 | try: |
---|
112 | ftp=ftplib.FTP('ftp.delerue.org','delerue','st.exupery') #ftp.login() |
---|
113 | ftp.cwd('/www/lal.delerue.org/ETALON/IR/') |
---|
114 | #print ftp.retrlines('LIST') |
---|
115 | ftp.storbinary('STOR '+nowfilename, open(path_images+nowfilename, 'rb')) |
---|
116 | #print ftp.retrlines('LIST') |
---|
117 | ftp.quit() |
---|
118 | print('Image disponible sur http://lal.delerue.org/ETALON/IR/' + nowfilename ) |
---|
119 | except: |
---|
120 | print('FTP error') |
---|
121 | os.remove(save_IR_File) |
---|
122 | plt.show(block=False) |
---|
123 | #time.sleep(0.5) |
---|
124 | fig.canvas.draw() |
---|
125 | #figZavio.clear() |
---|
126 | #plt.close() |
---|
127 | fig.canvas.draw() |
---|
128 | # #cam.shutdown() |
---|
129 | cam.stop_acquisition() |
---|
130 | |
---|
131 | |
---|