wk-labs/lab6/main.py
2021-12-01 12:38:49 +01:00

18 lines
548 B
Python

import cv2 as cv
import numpy as np
if __name__ == '__main__':
img = cv.imread('../img/messi5.jpg', cv.IMREAD_COLOR)
mask = np.zeros(img.shape[:2], np.uint8)
bgdModel = np.zeros((1, 65), np.float64)
fgdModel = np.zeros((1, 65), np.float64)
rect = (50, 50, 450, 290)
cv.grabCut(img, mask, rect, bgdModel, fgdModel, 5, cv.GC_INIT_WITH_RECT)
mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8')
img = img * mask2[:, :, np.newaxis]
cv.imshow("image", img)
cv.waitKey()
cv.destroyAllWindows()