forked from handav/image_processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (28 loc) · 1.04 KB
/
main.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
import cv2
import os
path_to_images = './windows'
ideal_larger_size = 800
def resize_image(image):
height, width = image.shape[:2]
if width >= height:
ratio = height/width
new_height = int(ideal_larger_size*ratio)
image = cv2.resize(image, (ideal_larger_size, new_height))
else:
ratio = width/height
new_width = int(ideal_larger_size*ratio)
image = cv2.resize(image, (new_width, ideal_larger_size))
return image
def save_new_image(image, image_name):
new_image_name = 'processed_' + image_name
cv2.imwrite(new_image_name, image)
for image_name in os.listdir(path_to_images):
if 'jpg' in image_name.lower() or 'jpeg' in image_name.lower():
image_path = path_to_images + '/' + image_name
image = cv2.imread(image_path)
image = resize_image(image)
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
save_new_image(image, image_name)
# cv2.imshow('edges', edges)
# cv2.waitKey(0)