forked from LucasSouzaa/tcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarp.py
87 lines (76 loc) · 2.63 KB
/
Warp.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
import os
import cv2
import numpy as np
import csv
#C:\Users\mcfal\Documents\GitHub\tcc\SubstitutosMarcados
def generatePath( filesDir ):
FileList = [] #armazenar os caminhos absolutos das images
for dirnames in os.listdir(filesDir):
path = os.path.join(filesDir, dirnames)
for paths, dirs, filename in os.walk(path):
for files in filename:
if files.endswith(".png"):
FileList.append(paths+"/"+files)
return FileList
def getPoints(row):
lineReader = row
lineReader = lineReader.pop(1)
return lineReader
def getRowsAsList(file):
csvFileArr = []
for row in file:
csvFileArr.append(row)
return csvFileArr
FileList = generatePath("C:\\Users\\mcfal\\Documents\\GitHub\\tcc\\Substitutos")
with open('C:\\Users\\mcfal\\Documents\\GitHub\\tcc\\Substitutos\\Pontos Vertice.csv', 'rb') as pontos:
spamreader = csv.reader(pontos, delimiter="\t")
lines = getRowsAsList(spamreader)
i = 1
print(i)
for file in FileList:
img = cv2.imread(file,1)
rows,cols,ch = img.shape
print(lines[i])
#Separando os pontos
x1 = lines[i][1].split(" ")[0]
y1 = lines[i][1].split(" ")[1]
x2 = lines[i][2].split(" ")[0]
y2 = lines[i][2].split(" ")[1]
x3 = lines[i][3].split(" ")[0]
y3 = lines[i][3].split(" ")[1]
x4 = lines[i][4].split(" ")[0]
y4 = lines[i][4].split(" ")[1]
xx1 = lines[i][5].split(" ")[0]
yy1 = lines[i][5].split(" ")[1]
xx2 = lines[i][6].split(" ")[0]
yy2 = lines[i][6].split(" ")[1]
xx3 = lines[i][7].split(" ")[0]
yy3 = lines[i][7].split(" ")[1]
xx4 = lines[i][8].split(" ")[0]
yy4 = lines[i][8].split(" ")[1]
pts1 = np.float32([[x1,y1],[x2,y2],[x3,y3],[x4,y4]])
pts2 = np.float32([[xx1,yy1],[xx2,yy2],[xx3,yy3],[xx4,yy4]])
dst1 = np.float32([[0,0],[0,320],[320/2,0],[320/2,320]])
dst2 = np.float32([[320/2,0],[320/2,320],[320,0],[320,320]])
M1 = cv2.getPerspectiveTransform(pts1,dst1)
M2 = cv2.getPerspectiveTransform(pts2,dst2)
warp1 = cv2.warpPerspective(img,M1,(320,320))
warp2 = cv2.warpPerspective(img,M2,(320,320))
#Concatenando
warpFinal = img
for y in range(0,320/2) :
for x in range(0,320):
warpFinal[x,y] = warp1[x,y]
for y in range(320/2,320) :
for x in range(0,320):
warpFinal[x,y] = warp2[x,y]
if(i <= 6):
print(i)
cv2.imwrite("C:\\Users\\mcfal\\Documents\\GitHub\\tcc\\SubstitutosWarp\\Substitutos\\Individuo_55\\"+`i`+".png",warpFinal)
if(i > 6 and i <13):
print(i)
cv2.imwrite("C:\\Users\\mcfal\\Documents\\GitHub\\tcc\\SubstitutosWarp\\Substitutos\\Individuo_64\\"+`i`+".png",warpFinal)
if(i >= 13):
print(i)
cv2.imwrite("C:\\Users\\mcfal\\Documents\\GitHub\\tcc\\SubstitutosWarp\\Substitutos\\Individuo_89\\"+`i`+".png",warpFinal)
i = i+1