mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	Fix: workaround for drawing non-latin characters (#7686)
* Add transliteration support to draw_box_with_label function * isort
This commit is contained in:
		
							parent
							
								
									3dd0192fe6
								
							
						
					
					
						commit
						500d369c50
					
				| @ -23,6 +23,7 @@ scipy == 1.11.* | ||||
| norfair == 2.2.* | ||||
| setproctitle == 1.3.* | ||||
| ws4py == 0.5.* | ||||
| unidecode == 1.3.* | ||||
| # Openvino Library - Custom built with MYRIAD support | ||||
| openvino @ https://github.com/NateMeyer/openvino-wheels/releases/download/multi-arch_2022.3.1/openvino-2022.3.1-1-cp39-cp39-manylinux_2_31_x86_64.whl; platform_machine == 'x86_64' | ||||
| openvino @ https://github.com/NateMeyer/openvino-wheels/releases/download/multi-arch_2022.3.1/openvino-2022.3.1-1-cp39-cp39-linux_aarch64.whl; platform_machine == 'aarch64' | ||||
|  | ||||
| @ -5,7 +5,7 @@ import numpy as np | ||||
| from norfair.drawing.color import Palette | ||||
| from norfair.drawing.drawer import Drawer | ||||
| 
 | ||||
| from frigate.util.image import intersection | ||||
| from frigate.util.image import intersection, transliterate_to_latin | ||||
| from frigate.util.object import ( | ||||
|     get_cluster_boundary, | ||||
|     get_cluster_candidates, | ||||
| @ -82,6 +82,11 @@ class TestRegion(unittest.TestCase): | ||||
| 
 | ||||
|         assert len(cluster_candidates) == 2 | ||||
| 
 | ||||
|     def test_transliterate_to_latin(self): | ||||
|         self.assertEqual(transliterate_to_latin("frégate"), "fregate") | ||||
|         self.assertEqual(transliterate_to_latin("utilité"), "utilite") | ||||
|         self.assertEqual(transliterate_to_latin("imágé"), "image") | ||||
| 
 | ||||
|     def test_cluster_boundary(self): | ||||
|         boxes = [(100, 100, 200, 200), (215, 215, 325, 325)] | ||||
|         boundary_boxes = [ | ||||
|  | ||||
| @ -9,10 +9,32 @@ from typing import AnyStr, Optional | ||||
| 
 | ||||
| import cv2 | ||||
| import numpy as np | ||||
| from unidecode import unidecode | ||||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
| 
 | ||||
| 
 | ||||
| def transliterate_to_latin(text: str) -> str: | ||||
|     """ | ||||
|     Transliterate a given text to Latin. | ||||
| 
 | ||||
|     This function uses the unidecode library to transliterate the input text to Latin. | ||||
|     It is useful for converting texts with diacritics or non-Latin characters to a | ||||
|     Latin equivalent. | ||||
| 
 | ||||
|     Args: | ||||
|         text (str): The text to be transliterated. | ||||
| 
 | ||||
|     Returns: | ||||
|         str: The transliterated text. | ||||
| 
 | ||||
|     Example: | ||||
|         >>> transliterate_to_latin('frégate') | ||||
|         'fregate' | ||||
|     """ | ||||
|     return unidecode(text) | ||||
| 
 | ||||
| 
 | ||||
| def draw_timestamp( | ||||
|     frame, | ||||
|     timestamp, | ||||
| @ -116,7 +138,10 @@ def draw_box_with_label( | ||||
| ): | ||||
|     if color is None: | ||||
|         color = (0, 0, 255) | ||||
|     display_text = "{}: {}".format(label, info) | ||||
|     try: | ||||
|         display_text = transliterate_to_latin("{}: {}".format(label, info)) | ||||
|     except Exception: | ||||
|         display_text = "{}: {}".format(label, info) | ||||
|     cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, thickness) | ||||
|     font_scale = 0.5 | ||||
|     font = cv2.FONT_HERSHEY_SIMPLEX | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user