Created
February 28, 2020 07:45
-
-
Save dkurt/3175fdc7283900b9f10d33e94038ec9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from openvino.inference_engine import IENetwork, IECore | |
import cv2 as cv | |
PERSON_ID = 11 | |
net = IENetwork('semantic-segmentation-adas-0001.xml', 'semantic-segmentation-adas-0001.bin') | |
ie = IECore() | |
exec_net = ie.load_network(net, 'CPU') | |
img = cv.imread('/home/dkurt/Pictures/samsung-neon.jpg') | |
bg = cv.imread('/home/dkurt/Pictures/127117.jpg') | |
bg = cv.resize(bg, (img.shape[1], img.shape[0])) | |
inp = cv.resize(img, (2048, 1024)).astype(np.float32).transpose(2, 0, 1).reshape(1, 3, 1024, 2048) | |
# inp /= 255 | |
outputs = exec_net.infer({'data': inp}) | |
mask = outputs['3976.1'].reshape(1024, 2048) | |
mask = (mask == PERSON_ID).astype(np.uint8) | |
mask = cv.resize(mask, (img.shape[1], img.shape[0]), interpolation=cv.INTER_NEAREST) | |
mask = mask.astype(np.bool) | |
img[~mask] = 0 | |
bg[mask] = 0 | |
img = img + bg | |
cv.imshow('mask', img) | |
cv.waitKey() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment