-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogo_identifier.py
More file actions
50 lines (36 loc) · 1.05 KB
/
Copy pathlogo_identifier.py
File metadata and controls
50 lines (36 loc) · 1.05 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import numpy as np
import sys
import os
import random
import math
import datetime
import sys
from tvs import tv_names
from test_classifier import classify_logo
reload(sys)
sys.setdefaultencoding('utf8')
def read_dir(file_path):
file_names = []
if os.path.isdir(file_path):
for f in os.listdir(file_path):
newfile_path = os.path.join(file_path, f)
if os.path.isdir(newfile_path):
file_names.extend(read_dir(newfile_path))
elif os.path.splitext(f)[-1].lower() == '.jpg':
file_names.append(newfile_path)
return file_names
else:
return file_path
# given a group of images to identify the logos
def identify_logos(images_dir):
results = []
test_images = read_dir(images_dir)
for image_path in test_images:
predicted_id = classify_logo(image_path)
predicted_tv = tv_names[predicted_id]
result = {'image': image_path, 'result': predicted_tv}
results.append(result)
return results