-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
34 lines (25 loc) · 890 Bytes
/
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
34
import torch
import numpy as np
import random
import cv2
import os
def init_device_seed(seed, cuda_visible):
os.environ['CUDA_VISIBLE_DEVICES'] = cuda_visible
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Device: {}'.format(device))
torch.manual_seed(seed)
random.seed(seed)
np.random.seed(seed)
return device
def get_smoothed_image(img):
img_blur = cv2.GaussianBlur(img, (5,5), 0)
img_canny = cv2.Canny(img, 100, 200)
img_result = np.copy(img)
for i in range(img_canny.shape[0]):
for j in range(img_canny.shape[1]):
if img_canny[i, j] == 255:
for a in range(-2, 3):
for b in range(-2, 3):
if 0 <= a < img.shape[0] and 0 <= b < img.shape[1]:
img_result[a, b] = img_blur[a, b]
return img_result