11from abc import ABCMeta as _ABCMeta , abstractmethod as _abstractmethod
22from typing import Any as _Any
33
4+ from cv2 import rectangle as _rectangle , putText as _put_text , FONT_HERSHEY_COMPLEX_SMALL as _FONT
45from numpy import ndarray as _ndarray
56
7+ from leads_jarvis .utils import to_opencv
8+
69
710class Detection (object , metaclass = _ABCMeta ):
811 @_abstractmethod
@@ -11,3 +14,18 @@ def detect(self, image: _ndarray) -> list[dict[str, _Any]]:
1114
1215 def __call__ (self , image : _ndarray ) -> list [dict [str , _Any ]]:
1316 return self .detect (image )
17+
18+ def mark (self , image : _ndarray , data : list [dict [str , _Any ]] | None = None ,
19+ filter_type : tuple [str , ...] | None = None ) -> _ndarray :
20+ if data is None :
21+ data = self (image )
22+ image = to_opencv (image )
23+ for item in data :
24+ name = item ["name" ]
25+ if filter_type is not None and name not in filter_type :
26+ continue
27+ box = item ["box" ]
28+ x1 , y1 , x2 , y2 = round (box ["x1" ]), round (box ["y1" ]), round (box ["x2" ]), round (box ["y2" ])
29+ image = _rectangle (image , (x1 , y1 ), (x2 , y2 ), (255 , 255 , 255 ))
30+ image = _put_text (image , name , (x1 , y1 - 4 ), _FONT , 1 , (255 , 255 , 255 ))
31+ return image
0 commit comments