-
Notifications
You must be signed in to change notification settings - Fork 6
/
create_color_features.py
38 lines (31 loc) · 1.25 KB
/
create_color_features.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
import cv2
import argparse
import utils
import glob
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", default='icons',
help="Path to the dir that contains the images to be indexed")
ap.add_argument("-o", "--output", default='features_output',
help="Path to the dir to write feature output to")
ap.add_argument("-c", "--colorSpace", default='bgr',
help="color space to use for generating historgram features (bgr, hsv, or lab)")
args = vars(ap.parse_args())
# gather image paths and sort
image_paths = glob.glob('{}/*'.format(args['dataset']))
image_paths.sort()
# open output file to write to
output = open('{}/color_hists.csv'.format(args["output"]), "w")
# init color histogram descriptor
desc = utils.colorutils.color_histogram([6, 6, 6], color_space=args['colorSpace'])
color_data = []
# loop over the input dataset of images
for image_path in image_paths:
# load image i and describe
image = cv2.imread(image_path)
features = desc.describe(image)
# write image path and feature values as row in csv
features = [str(x) for x in features]
output.write('{},{}\n'.format(image_path, ','.join(features)))
# clean up
output.close()