PF-AFN icon indicating copy to clipboard operation
PF-AFN copied to clipboard

script for extracting clothes edges

Open xkaple00 opened this issue 3 years ago • 3 comments

Hi, could you publish the script for edges extraction from the clothes images (built-in function in python) or point me in the direction of how you did that?

xkaple00 avatar Mar 21 '21 10:03 xkaple00

The built-in function we use is cv2. grabCut(img, mask, rect, bgdModel, fgdModel, iterCount, mode=None). You can refer to the following code.

import cv2 import numpy as np from matplotlib import pyplot as plt

img = cv2.imread('demo.jpg') 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]

plt.subplot(121), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) plt.title("grabcut"), plt.xticks([]), plt.yticks([]) plt.subplot(122), plt.imshow(cv2.cvtColor(OLD_IMG, cv2.COLOR_BGR2RGB)) plt.title("original"), plt.xticks([]), plt.yticks([])

plt.show()

geyuying avatar Mar 23 '21 03:03 geyuying

The built-in function we use is cv2. grabCut(img, mask, rect, bgdModel, fgdModel, iterCount, mode=None). You can refer to the following code.

import cv2 import numpy as np from matplotlib import pyplot as plt

img = cv2.imread('demo.jpg') 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]

plt.subplot(121), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) plt.title("grabcut"), plt.xticks([]), plt.yticks([]) plt.subplot(122), plt.imshow(cv2.cvtColor(OLD_IMG, cv2.COLOR_BGR2RGB)) plt.title("original"), plt.xticks([]), plt.yticks([])

plt.show()

This code snippet doesn't give accurate results. image

shreyjasuja avatar Apr 04 '21 13:04 shreyjasuja

import cv2 import numpy as np from matplotlib import pyplot as plt

img = cv2.imread('demo.jpg') 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]

plt.subplot(121), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) plt.title(“grabcut”), plt.xticks([]), plt.yticks([]) plt.subplot(122), plt.imshow(cv2.cvtColor(OLD_IMG, cv2.COLOR_BGR2RGB)) plt.title(“original”), plt.xticks([]), plt.yticks([])

plt.show()

image

wang674 avatar Apr 23 '22 04:04 wang674