-
Notifications
You must be signed in to change notification settings - Fork 2
/
labeler.py
72 lines (48 loc) · 1.44 KB
/
labeler.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
import os
import cv2
import pandas as pd
from helpers import getFeatures, drawFeatures
# from helpers import predictFeature
# read csv
bbox = [(0,0,0,0)]
dots= [(0,0)]
column_names = []
for index in range(68):
column_names.append('x'+str(index))
column_names.append('y'+str(index))
column_names.append('category')
data = []
for img in os.listdir('./images'):
row = []
print('./images/'+img)
img_file = cv2.imread('./images/'+img,cv2.IMREAD_COLOR)
rgba_img = cv2.cvtColor(img_file, cv2.COLOR_BGR2RGBA)
# pred_img = predictFeature(img_file)
faces = getFeatures(img_file)
maxDots = 0
if len(faces) > 0:
(bbox,dots) = faces[0]
(faceX, faceY, faceW, faceH) = bbox
if len(dots) > maxDots:
maxDots = len(dots)
cv2.imshow('win', drawFeatures(img_file))
key = cv2.waitKey(0)
category = int(chr(key))
for (x,y) in dots:
normalizedX = (x - faceX) / faceW
normalizedY = (y - faceY) / faceH
row.append(normalizedX)
row.append(normalizedY)
if len(dots) < 68:
for x in range(68 - len(dots)):
row.append(0)
row.append(0)
row.append(category)
data.append(row)
print(maxDots)
df = pd.DataFrame(data, columns= column_names)
export_csv = df.to_csv(r'./export_dataframe.csv', index = None, header=True)
mass = pd.read_csv(r'./export_dataframe.csv')
print(mass)
# save csv to file
cv2.destroyAllWindows()