File size: 813 Bytes
6e858ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

import cv2
import numpy as np
from tqdm.auto import tqdm

clothes_dir = 'dataset/test_clothes'
clothes_edges_dir = 'dataset/test_edge'


for img_fn in tqdm(os.listdir(clothes_dir)):
    cloth_img_fp = os.path.join(clothes_dir, img_fn)
    img = cv2.imread(cloth_img_fp)
    OLD_IMG = img.copy()
    mask = np.zeros(img.shape[:2], np.uint8)
    SIZE = (1, 65)
    bgdModle = np.zeros(SIZE, np.float64)

    fgdModle = np.zeros(SIZE, np.float64)
    rect = (1, 1, img.shape[1], img.shape[0])
    cv2.grabCut(img, mask, rect, bgdModle, fgdModle, 10, cv2.GC_INIT_WITH_RECT)

    mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8')
    img *= mask2[:, :, np.newaxis]

    mask2 *= 255

    cloth_edges_img_fp = os.path.join(clothes_edges_dir, img_fn)
    cv2.imwrite(cloth_edges_img_fp, mask2)