def resize_image(self,img,*args):
# unpacks width, height
height, width,_ = img.shape
print("Original size: {} {}".format(width, height))
count_times_resized = 0
while width > 500 or height > 500:
#if width > 300 or height > 300:
# divides images WxH by half
width = width / 2
height = height /2
count_times_resized += 1
# prints x times resized to console
if count_times_resized != 0:
print("Resized {}x smaller, to: {} {}".format(count_times_resized*2,width, height))
# makes sures image is not TOO small
if width < 300 and height < 300:
width = width * 2
height = height * 2
img = cv2.resize(img,(int(width),int(height)))
return img
评论列表
文章目录