-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImProc.py
49 lines (39 loc) · 1.77 KB
/
ImProc.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
import picamera
import RPi.GPIO as GPIO
import time
from time import sleep
from PIL import Image
import matplotlib.pyplot as plt
import capturaImagens
import cv2
import numpy as np
import math
import os
class ImProc:
path = '/home/pi/Documents/tc2/histogramas/'
def histogramas(self,nome,cores,overlay):
RGBArray = np.empty([0])
#concatena todos os RGB de das cores 'green','red','white','yellow','blue' nesta ordem
for x in range(len(cores)):
nomeArquivo = 'CRPD_'+overlay+cores[x]+'.jpg'
#img = cv2.imread(self.path+nomeArquivo)
img = cv2.imread(nomeArquivo)
bgr= cv2.split(img)
histB= np.array(cv2.calcHist(bgr,[0],None,[256],[0,256]))
RGBArray = np.append(RGBArray,histB)
histG= np.array(cv2.calcHist(bgr,[1],None,[256],[0,256]))
RGBArray = np.append(RGBArray,histG)
histR= np.array(cv2.calcHist(bgr,[2],None,[256],[0,256]))
RGBArray = np.append(RGBArray,histR)
#se o arquivo existe
if(os.path.isfile(self.path+'Todos.csv')): #SE SIM
csv=np.genfromtxt(self.path+'Todos.csv', delimiter='\t') #LE O ARRAY EXISTENTE
data = np.array(csv) #TRANSFORMA NUM NPARRAY
data = np.column_stack((data,RGBArray)) #STACK COLOCA EM OUTRA COLUNA
np.savetxt(self.path+'Todos.csv',data, delimiter='\t',fmt='%d')
else: #SENAO
f = open(self.path+'Todos.csv','w+') #CRIA O CSV
csv=np.genfromtxt(self.path+'Todos.csv', delimiter='\t')
data = np.array(csv)
b = np.append(data,RGBArray)
np.savetxt(self.path+'Todos.csv',b,delimiter='\t',fmt='%d') #E ESCREVE O ARRAY NA COLUNA