APS - Processamento de Imagens
Por: cviniciusmessias • 16/9/2019 • Trabalho acadêmico • 707 Palavras (3 Páginas) • 344 Visualizações
import cv2 as cv
import matplotlib.pyplot as plt
quad = []
quad.append(cv.imread('Quad1.png'))
quad.append(cv.imread('Quad2.png'))
quad.append(cv.imread('Quad3.png'))
quad.append(cv.imread('Quad4.png'))
quad.append(cv.imread('Quad5.png'))
triang = []
triang.append(cv.imread('Triang1.png'))
triang.append(cv.imread('Triang2.png'))
triang.append(cv.imread('Triang3.png'))
triang.append(cv.imread('Triang4.png'))
triang.append(cv.imread('Triang5.png'))
circ = []
circ.append(cv.imread('Circ1.png'))
circ.append(cv.imread('Circ2.png'))
circ.append(cv.imread('Circ3.png'))
circ.append(cv.imread('Circ4.png'))
circ.append(cv.imread('Circ5.png'))
areaQuad = []
perimetroQuad = []
compacidadeQuad = []
areaTriang = []
perimetroTriang = []
compacidadeTriang = []
areaCirc = []
perimetroCirc = []
compacidadeCirc = []
i = -1
#Quadrado
while i < 4:
i = i + 1
img = cv.cvtColor(quad[i], cv.COLOR_BGR2GRAY)
__, img = cv.threshold(img, 127, 255, cv.THRESH_BINARY_INV)
f1 = []
for pos in range(0, img.shape[0]):
f1.append(cv.countNonZero(img[0:img.shape[0], pos]))
total = sum(f1)
areaQuad.append(total)
edge = cv.Canny(img, 100, 200)
f2 = []
for pos in range(0, edge.shape[0]):
f2.append(cv.countNonZero(edge[0:edge.shape[0], pos]))
total = sum(f2)
perimetroQuad.append(total)
total = pow(perimetroQuad[i], 2) / areaQuad[i]
compacidadeQuad.append(total)
del f1
del f2
total = 0
i = -1
#Triangulo
while i < 4:
i = i + 1
img = cv.cvtColor(triang[i], cv.COLOR_BGR2GRAY)
__, img = cv.threshold(img, 127, 255, cv.THRESH_BINARY_INV)
f1 = []
for pos in range(0, img.shape[0]):
f1.append(cv.countNonZero(img[0:img.shape[0], pos]))
total = sum(f1)
areaTriang.append(total)
edge = cv.Canny(img, 100, 200)
f2 = []
for pos in range(0, edge.shape[0]):
f2.append(cv.countNonZero(edge[0:edge.shape[0], pos]))
total = sum(f2)
perimetroTriang.append(total)
total = pow(perimetroTriang[i], 2) / areaTriang[i]
compacidadeTriang.append(total)
del f1
del f2
total = 0
i = -1
#Circulo
while i < 4:
i = i + 1
img = cv.cvtColor(circ[i], cv.COLOR_BGR2GRAY)
__, img = cv.threshold(img, 127, 255, cv.THRESH_BINARY_INV)
f1 = []
for pos in range(0, img.shape[0]):
f1.append(cv.countNonZero(img[0:img.shape[0], pos]))
total = sum(f1)
areaCirc.append(total)
edge = cv.Canny(img, 100, 200)
f2 = []
for pos in range(0, edge.shape[0]):
f2.append(cv.countNonZero(edge[0:edge.shape[0], pos]))
total = sum(f2)
perimetroCirc.append(total)
...