JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
transform.py
Go to the documentation of this file.
1# This file is part of OpenCV Zoo project.
2# It is subject to the license terms in the LICENSE file found in the same directory.
3#
4# Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
5# Third party copyrights are property of their respective owners.
6
7import collections
8import numpy as numpy
9import cv2 as cv
10
11class Compose:
12 def __init__(self, transforms=[]):
13 self.transforms = transforms
14
15 def __call__(self, img):
16 for t in self.transforms:
17 img = t(img)
18 return img
19
20class Resize:
21 def __init__(self, size, interpolation=cv.INTER_LINEAR):
22 self.size = size
23 self.interpolation = interpolation
24
25 def __call__(self, img):
26 return cv.resize(img, self.size)
27
29 def __init__(self, size):
30 self.size = size # w, h
31
32 def __call__(self, img):
33 h, w, _ = img.shape
34 ws = int(w / 2 - self.size[0] / 2)
35 hs = int(h / 2 - self.size[1] / 2)
36 return img[hs:hs+self.size[1], ws:ws+self.size[0], :]
37
39 def __init__(self, mean=None, std=None):
40 self.mean = mean
41 self.std = std
42
43 def __call__(self, img):
44 if self.mean is not None:
45 img[:, :, 0] = img[:, :, 0] - self.mean[0]
46 img[:, :, 1] = img[:, :, 1] - self.mean[1]
47 img[:, :, 2] = img[:, :, 2] - self.mean[2]
48 if self.std is not None:
49 img[:, :, 0] = img[:, :, 0] / self.std[0]
50 img[:, :, 1] = img[:, :, 1] / self.std[1]
51 img[:, :, 2] = img[:, :, 2] / self.std[2]
52 return img
53
55 def __init__(self, ctype):
56 self.ctype = ctype
57
58 def __call__(self, img):
59 return cv.cvtColor(img, self.ctype)
__init__(self, size)
Definition transform.py:29
__call__(self, img)
Definition transform.py:32
__init__(self, ctype)
Definition transform.py:55
__init__(self, transforms=[])
Definition transform.py:12
__call__(self, img)
Definition transform.py:15
__call__(self, img)
Definition transform.py:43
__init__(self, mean=None, std=None)
Definition transform.py:39
__call__(self, img)
Definition transform.py:25
__init__(self, size, interpolation=cv.INTER_LINEAR)
Definition transform.py:21