logo
Browse Source

update.

Signed-off-by: wxywb <xy.wang@zilliz.com>
main
wxywb 3 years ago
parent
commit
2f28802601
  1. 2
      __init__.py
  2. 10
      image_crop_cv2.py

2
__init__.py

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .image_crop_cv2 import ImageDecodeCV2
from .image_crop_cv2 import ImageCropCV2
# The factory method

10
image_crop_cv2.py

@ -17,7 +17,7 @@ import logging
import cv2
import requests
import numpy as np
from typing import List
from typing import List, Tuple
from towhee import register
from towhee.operator import PyOperator, OperatorFlag
@ -29,14 +29,14 @@ log = logging.getLogger()
@register(output_schema=['img'],
flag=OperatorFlag.STATELESS | OperatorFlag.REUSEABLE)
class ImageCropCV2(PyOperator):
def __init__(self, clamp = False)
def __init__(self, clamp = False):
self.clamp = clamp
@staticmethod
def _clamp(x, minimum, maximum)
def _clamp(x, minimum, maximum):
return max(minimum, min(x, maximum))
def __call__(self, img: np.ndarray, bboxes: List[(int, int, int, int)]):
def __call__(self, img: np.ndarray, bboxes: List[Tuple]):
h, w, _ = img.shape
res = []
for box in bboxes:
@ -45,6 +45,6 @@ class ImageCropCV2(PyOperator):
x2 = ImageCropCV2._clamp(x2, 0, w)
y1 = ImageCropCV2._clamp(y1, 0, h)
y2 = ImageCropCV2._clamp(y2, 0, h)
res.append(Image[y1:y2,x1:x2,:])
res.append(img[y1:y2,x1:x2,:])
return res

Loading…
Cancel
Save