-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawRects.py
57 lines (47 loc) · 1.58 KB
/
drawRects.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
#!/usr/bin/python
import os
import sys
import os.path
import shutil
import random
import cv2
import math
import numpy as np
if __name__ =='__main__':
gtFile = sys.argv[1]
srcDir = sys.argv[2]
dstDir = sys.argv[3]
if not os.path.exists(dstDir):
os.system("mkdir -p "+dstDir)
with open(gtFile,'r') as f:
lines = f.readlines()
count = 0
line_index = 0
while line_index < len(lines):
count += 1
if 0 == count % 50:
print '%s/%s'%(count,len(lines))
path = lines[line_index].strip('\n\t')+'.jpg'
line_index += 1
numFace = int( lines[line_index].strip('\n\t') )
line_index += 1
srcPath = srcDir + path
img = cv2.imread(srcPath)
if img is None:
print '%s is not be found.'%(path)
line_index += numFace
for face_index in range(0,numFace):
words = lines[line_index].strip('\n\t').split()
line_index += 1
if not len(words) == 5 :
continue
lt_x = int( float(words[0])+0.5 )
lt_y = int( float(words[1])+0.5 )
rb_x = lt_x + int( float(words[2])+0.5 )
rb_y = lt_y + int( float(words[3])+0.5 )
cv2.rectangle(img,(lt_x,lt_y),(rb_x,rb_y),(255,0,0),1)
savePath = dstDir + path[path.find('/'):]
saveDir = savePath[0:savePath.rfind('/')]
if not os.path.exists(saveDir):
os.makedirs(saveDir)
cv2.imwrite(savePath,img)