-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSobel_edge.py
65 lines (54 loc) · 2.26 KB
/
Sobel_edge.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import cv2
import numpy as np
import os
import json
def LoadTriplets(filename):
with open(filename, encoding='utf-8') as f:
info = json.load(f)
test_images_name = info['test']['images']
test_sketchs_name = info['test']['sketches']
test_triplets = info['test']['triplets']
train_images_name = info['train']['images']
train_sketchs_name = info['train']['sketches']
train_triplets = info['train']['triplets']
#print(len(train_triplets))
#print(train_images_name[0])
#print(train_sketchs_name[0])
#print(train_triplets[0][0])
return (test_images_name, test_sketchs_name, test_triplets, train_images_name, train_sketchs_name, train_triplets)
def ProcessImagesData():
shoes_annotation = r'./Data/sbir_cvpr2016/shoes/annotation/shoes_annotation.json'
print(r'Loading ' + shoes_annotation + r'...')
test_images_name, test_sketchs_name, test_triplets, train_images_name, train_sketchs_name, train_triplets = LoadTriplets(shoes_annotation)
img_path = r'./Data/sbir_cvpr2016/shoes/test/images/'
write_img_path = r'./Data/sbir_cvpr2016/shoes/test/canny_images/'
for img in test_images_name:
print('Process ' + img + '...')
image = cv2.imread(img_path + img)
image = cv2.GaussianBlur(image, (3, 3), 0)
canny = cv2.Canny(image, 50, 150)
canny_sketch = cv2.bitwise_not(canny)
canny_sketch = cv2.cvtColor(canny_sketch, cv2.COLOR_GRAY2RGB)
print('Write ' + img + '...')
#cv2.imshow(img, canny_sketch)
#cv2.waitKey(0)
cv2.imwrite(write_img_path + img, canny_sketch, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
'''
img_path = r'./Data/sbir_cvpr2016/shoes/train/images/12.jpg'
skt_path = r'./Data/sbir_cvpr2016/shoes/train/sketches/12.png'
img = cv2.imread(img_path)
skt = cv2.imread(skt_path)
img = cv2.GaussianBlur(img, (3, 3), 0)
canny = cv2.Canny(img, 50, 150)
canny_sketch = cv2.bitwise_not(canny)
canny_sketch = cv2.cvtColor(canny_sketch, cv2.COLOR_GRAY2RGB)
cv2.imwrite('./12.jpg', canny_sketch, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
cv2.imshow('Image', img)
cv2.imshow('Sketch', skt)
cv2.imshow('Canny', canny_sketch)
cv2.waitKey(0)
'''
if __name__ == '__main__':
ProcessImagesData()