Guest User

cloak.py

a guest
May 30th, 2021
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2
  2. import numpy as np
  3.  
  4. cap=cv2.VideoCapture(0)
  5. back = cv2.imread('background.jpg')
  6.  
  7. while cap.isOpened():
  8.     ret,frame = cap.read()
  9.     if ret:
  10.         hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
  11.         #cv2.imshow("HSV",hsv)
  12.         # blue = np.uint8([[[0,0,255]]])
  13.         # hsv_blue = cv2.cvtColor(blue,cv2.COLOR_BGR2HSV)
  14.  
  15.         #print(hsv_red)
  16.  
  17.         l_blue=np.array([90,85,50])
  18.         u_blue=np.array([128,255,255])
  19.  
  20.         mask = cv2.inRange(hsv,l_blue,u_blue)
  21.         #cv2.imshow("Mask",mask)
  22.  
  23.         part1 = cv2.bitwise_and(back,back,mask=mask)
  24.         #cv2.imshow("Half",part1)
  25.  
  26.         mask=cv2.bitwise_not(mask)
  27.         #cv2.imshow("New mask",mask)
  28.  
  29.         part2 = cv2.bitwise_and(frame,frame,mask=mask)
  30.         cv2.imshow("Final",part2+part1)
  31.  
  32.         if cv2.waitKey(5) == ord('q'):
  33.                  break
  34.  
  35.  
  36. cap.release()
  37. cv2.destroyAllWindows()
RAW Paste Data