-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdown_sizing.py
More file actions
41 lines (35 loc) · 1.02 KB
/
down_sizing.py
File metadata and controls
41 lines (35 loc) · 1.02 KB
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
34
35
36
37
38
39
40
41
'''
==================================================================
-- Author: Hamid Doostmohammadi, Azadeh Nazemi
-- Create date: 05/11/2020
-- Description: This code is for resizing/rescaling many images.
This can be used for trainning in ML.
-- Status: In progress
===================================================================
'''
from imutils import paths
import numpy as np
import cv2
import os
import sys
from imutils.paths import list_images
import imutils
import time
import math
fileMode = "jpg"
print("[INFO] loading images...")
n = sys.argv[2]
nn = int(n)/10
imagePaths = sorted(list(paths.list_images(sys.argv[1])))
for imagePath in imagePaths:
image = cv2.imread(imagePath)
filename = imagePath.split("\\")[-1]
ho, wo = image.shape[:2]
ar = wo/ho
if ar < 1:
W
image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE)
ho, wo = image.shape[:2]
orig = image
resized = cv2.resize(image, (int(wo*nn), int(ho*nn)))
cv2.imwrite(filename, resized)