-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (26 loc) · 857 Bytes
/
main.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
import cv2
from cvzone.SelfiSegmentationModule import SelfiSegmentation
import os
cap = cv2.VideoCapture(0)
segmentor = SelfiSegmentation()
paths=os.listdir("Resources")
for i in range(len(paths)):
paths[i]="Resources/"+paths[i]
image_index=0
while True:
success, img = cap.read()
bgimg = cv2.imread(paths[image_index])
bgimg = cv2.resize(bgimg, (640, 480))
no_bg_img = segmentor.removeBG(img, bgimg,0.8)
no_bg_img = cv2.flip(no_bg_img, 1)
no_bg_img = cv2.resize(no_bg_img,(640,480))
cv2.imshow("video", no_bg_img)
key=cv2.waitKey(1)
if key==ord('d'):
image_index=(image_index+1)%len(paths)
elif key==ord('a'):
image_index=(image_index-1)%len(paths)
elif key == ord('q') or cv2.getWindowProperty('video', cv2.WND_PROP_VISIBLE) < 1:
break
cap.release()
cv2.destroyAllWindows()