mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
add Harry Potter Cloak script using Open-CV (#228)
* add Harry Potter Cloak script using Open-CV * add Indian Flag using Turtle * Delete README.md * Delete main.py * Update README.md
This commit is contained in:
parent
5b8a5b169a
commit
f5ea56dd29
73
Harry-Potter-Cloak/HarryPotterCloak.py
Normal file
73
Harry-Potter-Cloak/HarryPotterCloak.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
import cv2
|
||||
import numpy
|
||||
|
||||
def hello(x):
|
||||
print("")
|
||||
|
||||
if __name__=='__main__':
|
||||
cap = cv2.VideoCapture(0)
|
||||
bars = cv2.namedWindow("bars")
|
||||
|
||||
cv2.createTrackbar("upper_hue","bars",110,180,hello)
|
||||
cv2.createTrackbar("upper_saturation","bars",255, 255, hello)
|
||||
cv2.createTrackbar("upper_value","bars",255, 255, hello)
|
||||
cv2.createTrackbar("lower_hue","bars",68,180, hello)
|
||||
cv2.createTrackbar("lower_saturation","bars",55, 255, hello)
|
||||
cv2.createTrackbar("lower_value","bars",54, 255, hello)
|
||||
|
||||
#Capturing the initial frame for creation of background
|
||||
while(True):
|
||||
cv2.waitKey(1000)
|
||||
ret,init_frame = cap.read()
|
||||
if(ret):
|
||||
break
|
||||
|
||||
while(True):
|
||||
ret,frame = cap.read()
|
||||
inspect = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
|
||||
|
||||
#getting the HSV values for masking the cloak
|
||||
upper_hue = cv2.getTrackbarPos("upper_hue", "bars")
|
||||
upper_saturation = cv2.getTrackbarPos("upper_saturation", "bars")
|
||||
upper_value = cv2.getTrackbarPos("upper_value", "bars")
|
||||
lower_value = cv2.getTrackbarPos("lower_value","bars")
|
||||
lower_hue = cv2.getTrackbarPos("lower_hue","bars")
|
||||
lower_saturation = cv2.getTrackbarPos("lower_saturation","bars")
|
||||
|
||||
#Kernel to be used for dilation
|
||||
kernel = numpy.ones((3,3),numpy.uint8)
|
||||
|
||||
upper_hsv = numpy.array([upper_hue,upper_saturation,upper_value])
|
||||
lower_hsv = numpy.array([lower_hue,lower_saturation,lower_value])
|
||||
|
||||
mask = cv2.inRange(inspect, lower_hsv, upper_hsv)
|
||||
mask = cv2.medianBlur(mask,3)
|
||||
mask_inv = 255-mask
|
||||
mask = cv2.dilate(mask,kernel,5)
|
||||
|
||||
#The mixing of frames in a combination to achieve the required frame
|
||||
b = frame[:,:,0]
|
||||
g = frame[:,:,1]
|
||||
r = frame[:,:,2]
|
||||
b = cv2.bitwise_and(mask_inv, b)
|
||||
g = cv2.bitwise_and(mask_inv, g)
|
||||
r = cv2.bitwise_and(mask_inv, r)
|
||||
frame_inv = cv2.merge((b,g,r))
|
||||
|
||||
b = init_frame[:,:,0]
|
||||
g = init_frame[:,:,1]
|
||||
r = init_frame[:,:,2]
|
||||
b = cv2.bitwise_and(b,mask)
|
||||
g = cv2.bitwise_and(g,mask)
|
||||
r = cv2.bitwise_and(r,mask)
|
||||
blanket_area = cv2.merge((b,g,r))
|
||||
|
||||
final = cv2.bitwise_or(frame_inv, blanket_area)
|
||||
|
||||
cv2.imshow("Harry's Cloak",final)
|
||||
|
||||
if(cv2.waitKey(3) == ord('q')):
|
||||
break;
|
||||
|
||||
cv2.destroyAllWindows()
|
||||
cap.release()
|
6
Harry-Potter-Cloak/README.md
Normal file
6
Harry-Potter-Cloak/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
## Harry Potter Cloak using OpenCV
|
||||
|
||||
This is a fun python script to simulate a harry potter cloak using image masking with the help of opencv library.
|
||||
It also uses the numpy library for some mathematical calculations.
|
||||
|
||||
Requirements: You will need Python installed on your system along with numpy and opencv library for this script to work properly.
|
2
Harry-Potter-Cloak/requirements.txt
Normal file
2
Harry-Potter-Cloak/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
numpy
|
||||
opencv
|
|
@ -52,6 +52,7 @@ So far, the following projects have been integrated to this repo:
|
|||
|[Minecraft Server in background](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Minecraft_server_in_background)|[Max von Forell](https://github.com/mvforell)|
|
||||
|[Own IP locator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Location_Of_Own_IP_Adress)|[Chris]()|
|
||||
|[Port Scanner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Port_Scanner)|[Plutoberth](https://github.com/Plutoberth)|
|
||||
|[Harry Potter Cloak](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Harry-Potter-Cloak) | [thesmartdeveloperr](https://github.com/thesmartdeveloperr)|
|
||||
|[Python Algebra Solver](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Algebra-Solver)|[Sengxay Xayachack](https://github.com/frankxayachack)|
|
||||
|[Random name generator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Random_Names_Generator)| [Ayush Bhardwaj](https://github.com/hastagAB)|
|
||||
|[Random Password Generators](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Random_Password_Generator)| [Hafpaf](https://github.com/hafpaf) and [Renderer-RCT2](https://github.com/Renderer-RCT2)|
|
||||
|
|
Loading…
Reference in New Issue
Block a user