-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage.py
More file actions
31 lines (26 loc) · 751 Bytes
/
image.py
File metadata and controls
31 lines (26 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
import numpy
class Image(object):
def __init__(self, image_path):
if isinstance(image_path, basestring):
self.image = cv2.imread(image_path)
else:
self.image = image_path
def get(self):
return self.image
def showImg(self, title):
cv2.imshow(title, self.image)
cv2.waitKey(0)
def getSize(self):
return self.image.shape
def resize(self, type, size):
if (type.lower() == 'w'):
ratio = float(size) / self.image.shape[1]
dim = (size, int(self.image.shape[0]) * ratio)
elif (type.lower() == 'h'):
ratio = float(size) / self.image.shape[0]
dim = (int(self.image.shape[1] * ratio), size)
else:
return self.image
result = cv2.resize(self.image, dim, interpolation=cv2.INTER_AREA)
return result