-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
executable file
·33 lines (29 loc) · 1.09 KB
/
utils.py
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
32
33
import cv2
import sys
import os
def resizeImg(imgPath, pxl_w=800):
import os
image = cv2.imread(imgPath)
if (image.shape[1] < pxl_w):
print "Warning Image:", imgPath, "is smaller than", pxl_w, "in height. No Rescaling done"
return imgPath
r = (pxl_w * 1.0) / image.shape[1]
dim = (pxl_w, int(image.shape[0] * r))
# print dim
# print imgPath
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
path = os.path.split(os.path.abspath(imgPath))
(file_name, ext) = os.path.splitext(path[1])
resized_image_name = file_name + "_" + str(pxl_w) + "_" + ext
resized_image_name = file_name + "_" + str(pxl_w) + "_" + ".png"
# print resized_image_name
new_fname = path[0] + "/" + resized_image_name
print new_fname
cv2.imwrite(new_fname, resized)
cv2.imwrite(new_fname, resized)
return new_fname
def convertjpgtopng(image,name):
img = cv2.imread(image)
newx,newy = img.shape[1]/4,img.shape[0]/4 #new size (w,h)
newimage = cv2.resize(img,(newx,newy))
cv2.imwrite(name, newimage)