thinh-huynh-re commited on
Commit
d7b7f52
1 Parent(s): dd7849d

Font arial

Browse files
Files changed (3) hide show
  1. fonts/arial.ttf +0 -0
  2. run_opencv.py +1 -1
  3. utils/frame_rate.py +17 -9
fonts/arial.ttf ADDED
Binary file (367 kB). View file
 
run_opencv.py CHANGED
@@ -35,7 +35,7 @@ class ArgParser(Tap):
35
 
36
  id2label: Optional[str] = "labels/kinetics_400.json"
37
 
38
- threshold: Optional[float] = 10.0
39
 
40
  max_confidence: Optional[float] = 20.0 # Set None if not scale
41
 
 
35
 
36
  id2label: Optional[str] = "labels/kinetics_400.json"
37
 
38
+ threshold: Optional[float] = None # 10.0
39
 
40
  max_confidence: Optional[float] = 20.0 # Set None if not scale
41
 
utils/frame_rate.py CHANGED
@@ -3,6 +3,7 @@ from typing import Optional
3
 
4
  import cv2
5
  import numpy as np
 
6
 
7
 
8
  class FrameRate:
@@ -12,6 +13,7 @@ class FrameRate:
12
  self.NO_FRAMES = 10
13
  self.fps: float = -1
14
  self.label: str = ""
 
15
  self.reset()
16
 
17
  def reset(self) -> None:
@@ -29,15 +31,21 @@ class FrameRate:
29
 
30
  def show_fps(self, image: np.ndarray, is_recording=False) -> np.ndarray:
31
  if self.fps != -1:
32
- image = cv2.putText(
33
- image,
34
- f"FPS {self.fps:.0f} _ {self.label}",
35
- (50, 50),
36
- cv2.FONT_HERSHEY_SIMPLEX,
37
- fontScale=1,
38
- color=(255, 0, 0),
39
- thickness=2,
40
- )
 
 
 
 
 
 
41
  if is_recording:
42
  image = cv2.circle(
43
  image, (50, 100), radius=10, color=(0, 0, 255), thickness=-1
 
3
 
4
  import cv2
5
  import numpy as np
6
+ from PIL import Image, ImageDraw, ImageFont
7
 
8
 
9
  class FrameRate:
 
13
  self.NO_FRAMES = 10
14
  self.fps: float = -1
15
  self.label: str = ""
16
+ self.font = ImageFont.truetype("fonts/arial.ttf", 33)
17
  self.reset()
18
 
19
  def reset(self) -> None:
 
31
 
32
  def show_fps(self, image: np.ndarray, is_recording=False) -> np.ndarray:
33
  if self.fps != -1:
34
+ text = f"FPS {self.fps:.0f} _ {self.label}"
35
+ # image = cv2.putText(
36
+ # image,
37
+ # text,
38
+ # (50, 50),
39
+ # cv2.FONT_HERSHEY_SIMPLEX,
40
+ # fontScale=1,
41
+ # color=(255, 0, 0),
42
+ # thickness=2,
43
+ # )
44
+ pil_image = Image.fromarray(image)
45
+ draw = ImageDraw.Draw(pil_image)
46
+ draw.text((50, 50), text, font=self.font)
47
+ image = np.asarray(pil_image)
48
+
49
  if is_recording:
50
  image = cv2.circle(
51
  image, (50, 100), radius=10, color=(0, 0, 255), thickness=-1