George commited on
Commit
6460857
1 Parent(s): f803e88

try to fix font not found

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. demo.py +0 -63
app.py CHANGED
@@ -38,7 +38,7 @@ def inference(filename):
38
  if prob < 0.10:
39
  text = 'Unknown'
40
  else:
41
- text = '{}({}): {:.2f}%'.format(
42
  results[0]['chinese_name'],
43
  results[0]['latin_name'],
44
  100.0 * results[0]['probability']
@@ -59,7 +59,7 @@ def inference(filename):
59
  image_for_draw,
60
  text,
61
  position,
62
- font='simsun.ttc',
63
  font_size=15
64
  )
65
 
 
38
  if prob < 0.10:
39
  text = 'Unknown'
40
  else:
41
+ text = '{} {}: {:.2f}%'.format(
42
  results[0]['chinese_name'],
43
  results[0]['latin_name'],
44
  100.0 * results[0]['probability']
 
59
  image_for_draw,
60
  text,
61
  position,
62
+ font=None,
63
  font_size=15
64
  )
65
 
demo.py DELETED
@@ -1,63 +0,0 @@
1
- import os
2
- import time
3
-
4
- import cv2
5
- import khandy
6
- import numpy as np
7
-
8
- from insectid import InsectDetector
9
- from insectid import InsectIdentifier
10
-
11
-
12
- if __name__ == '__main__':
13
- src_dirs = [r'images']
14
-
15
- detector = InsectDetector()
16
- identifier = InsectIdentifier()
17
- src_filenames = sum([khandy.list_files_in_dir(src_dir, True)
18
- for src_dir in src_dirs], [])
19
- src_filenames = sorted(
20
- src_filenames, key=lambda t: os.stat(t).st_mtime, reverse=True)
21
-
22
- for k, filename in enumerate(src_filenames):
23
- print('[{}/{}] {}'.format(k+1, len(src_filenames), filename))
24
- start_time = time.time()
25
- image = khandy.imread(filename)
26
- if image is None:
27
- continue
28
- if max(image.shape[:2]) > 1280:
29
- image = khandy.resize_image_long(image, 1280)
30
- image_for_draw = image.copy()
31
- image_height, image_width = image.shape[:2]
32
-
33
- boxes, confs, classes = detector.detect(image)
34
- for box, conf, class_ind in zip(boxes, confs, classes):
35
- box = box.astype(np.int32)
36
- box_width = box[2] - box[0] + 1
37
- box_height = box[3] - box[1] + 1
38
- if box_width < 30 or box_height < 30:
39
- continue
40
-
41
- cropped = khandy.crop_or_pad(image, box[0], box[1], box[2], box[3])
42
- results = identifier.identify(cropped)
43
- print(results[0])
44
- prob = results[0]['probability']
45
- if prob < 0.10:
46
- text = 'Unknown'
47
- else:
48
- text = '{}: {:.2f}%'.format(
49
- results[0]['latin_name'], 100.0 * results[0]['probability'])
50
- position = [box[0] + 2, box[1] - 20]
51
- position[0] = min(max(position[0], 0), image_width)
52
- position[1] = min(max(position[1], 0), image_height)
53
- cv2.rectangle(image_for_draw,
54
- (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 2)
55
- image_for_draw = khandy.draw_text(image_for_draw, text, position,
56
- font='simsun.ttc', font_size=15)
57
-
58
- print('Elapsed: {:.3f}s'.format(time.time() - start_time))
59
- cv2.imshow('image', image_for_draw)
60
- key = cv2.waitKey(0)
61
- if key == 27:
62
- cv2.destroyAllWindows()
63
- break