-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateNegatives.py
executable file
·48 lines (38 loc) · 1.35 KB
/
generateNegatives.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
"""
# python3 ./generateNegatives.py -infiles '*jpg'
python3 ../../generateDistortedPositives.py -infiles 'sample_pos*'
Check with
opencv_createsamples -w 80 -h 20 -vec merged.vec
"""
import argparse
import glob
import os
import shutil
import cv2
import sys
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument('-infiles', action='store', dest='infiles',
help='filenames of negative images')
parser.add_argument('-width', action='store', dest='width',
help='width of image in pixels', default=80, type=int)
parser.add_argument('-height', action='store', dest='height',
help='height of image in pixels', default=20, type=int)
args = parser.parse_args()
cwd = os.getcwd()
vecdir = cwd+'/NegativesSmall'
print(vecdir)
try:
os.makedirs(vecdir)
except:
pass
names=glob.glob(args.infiles)
print(names)
#generate slices of original pictures (to be negative samples)
for i, name in enumerate(names):
img = cv2.imread(name,0)
big_picture_height, big_picture_width = img.shape
for i,ix in enumerate(np.arange(0, big_picture_width, args.width)):
for j, jy in enumerate(np.arange(0, big_picture_height, args.height)):
small_picture = img[jy:jy+args.height, ix:ix+args.width]
cv2.imwrite(vecdir+'/small_'+str(jy)+'-'+str(ix)+name,small_picture)