-
Notifications
You must be signed in to change notification settings - Fork 0
/
capturaImagens.py
111 lines (96 loc) · 4.72 KB
/
capturaImagens.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
import RPi.GPIO as GPIO
from picamera import PiCamera
import time
from PIL import Image
import numpy as np
import cv2
class CapturaImagens:
gpios = [(18,6),(23,25),(27,24),(12,17),(22,21)]
path = '/home/pi/Documents/tc2/'
def captura(self,overlay):
# W = Branco G=Verde, R=Verm, Y=Amarelo, B=Azul
try:
camera = PiCamera()
camera.resolution = (800,600)
camera.start_preview(alpha=128)
##Parte de incluir a ROI no preview da camera
if(int(overlay) == 64):
img = Image.open('overlay64.png')
else:
img = Image.open('overlay128.png')
pad = Image.new('RGB',(((img.size[0] + 31)//32)*32,((img.size[1] + 15)//16) * 16,))
pad.paste(img,(0,0))
o = camera.add_overlay(pad.tostring(),size = img.size)
o.alpha = 128
o.layer = 3
choice =input("Pressione 1 para iniciar: \n ")
while choice != 1:
choice = input("Pressione 1 para iniciar: \n")
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
for x in range(len(self.gpios)):
GPIO.setup(self.gpios[x][0],GPIO.OUT)
GPIO.setup(self.gpios[x][1],GPIO.OUT)
GPIO.output(self.gpios[x][0],True)
GPIO.output(self.gpios[x][1],True)
time.sleep(5)
if(x==0):
camera.capture(self.path+'white.jpg',resize=(800,600))
if(int(overlay) == 64):
img2crp = cv2.imread(self.path+'white.jpg')
crpd_img= img2crp[268:332,368:432]
cv2.imwrite(self.path+'CRPD_64'+'white.jpg',crpd_img)
else:
img2crp = cv2.imread(self.path+'white.jpg')
crpd_img= img2crp[236:364,336:464]
cv2.imwrite(self.path+'CRPD_128'+'white.jpg',crpd_img)
elif(x==1):
camera.capture(self.path+'green.jpg',resize=(800,600))
if(int(overlay) == 64):
img2crp = cv2.imread(self.path+'green.jpg')
crpd_img= img2crp[268:332,368:432]
cv2.imwrite(self.path+'CRPD_64'+'green.jpg',crpd_img)
else:
img2crp = cv2.imread(self.path+'green.jpg')
crpd_img= img2crp[236:364,336:464]
cv2.imwrite(self.path+'CRPD_128'+'green.jpg',crpd_img)
elif(x==2):
camera.capture(self.path+'red.jpg',resize=(800,600))
if(int(overlay) == 64):
img2crp = cv2.imread(self.path+'red.jpg')
crpd_img= img2crp[268:332,368:432]
cv2.imwrite(self.path+'CRPD_64'+'red.jpg',crpd_img)
else:
img2crp = cv2.imread(self.path+'red.jpg')
crpd_img= img2crp[236:364,336:464]
cv2.imwrite(self.path+'CRPD_128'+'red.jpg',crpd_img)
elif(x==3):
camera.capture(self.path+'yellow.jpg',resize=(800,600))
if(int(overlay) == 64):
img2crp = cv2.imread(self.path+'yellow.jpg')
crpd_img= img2crp[268:332,368:432]
cv2.imwrite(self.path+'CRPD_64'+'yellow.jpg',crpd_img)
else:
img2crp = cv2.imread(self.path+'yellow.jpg')
crpd_img= img2crp[236:364,336:464]
cv2.imwrite(self.path+'CRPD_128'+'yellow.jpg',crpd_img)
elif(x==4):
camera.capture(self.path+'blue.jpg',resize=(800,600))
if(int(overlay) == 64):
img2crp = cv2.imread(self.path+'blue.jpg')
crpd_img= img2crp[268:332,368:432]
cv2.imwrite(self.path+'CRPD_64'+'blue.jpg',crpd_img)
else:
img2crp = cv2.imread(self.path+'blue.jpg')
crpd_img= img2crp[236:364,336:464]
cv2.imwrite(self.path+'CRPD_128'+'blue.jpg',crpd_img)
##camera.stop_preview()
GPIO.output(self.gpios[x][0],False)
GPIO.output(self.gpios[x][1],False)
camera.stop_preview()
#GPIO.cleanup()
camera.stop_preview()
pass
finally:
GPIO.cleanup()
camera.close()