Coder Social home page Coder Social logo

harry-potters-invisible-cloak's Introduction

Harry-Potters-Invisible-cloak

Image masking basic techniques

Tired of scratching your head through hectic reasearch papers? Common let's make something interesting with the help of basic computer vision knowledge using opencv library.

Lets run the code first:

  • Install all dependencies:
pip install -r requirements.txt
  • Run code:
python src.py

Stay away from frame untill video window pops up for the background image to be created

What's in the code:

The code has been written to recognize RED color as cloak for now.

lower_range = np.array([0,120,50])
higher_range = np.array([10,255,255])

You can change the color bound according to yourself.The color range for HSV value are available here. For HSV, Hue range is [0,179], Saturation range is [0,255] and Value range is [0,255]. Different softwares use different scales. So if you are comparing OpenCV values with them, you need to normalize these ranges.

  • Masking is one of the key features for this project:
mask1 = cv2.inRange(hsv, lower_range, higher_range)

The above forms a mask of the area we want to make invisible to frame-feed.

  • The next task is to extract the above mask from the frame,background and foreground.
#segmenting out cloth color
mask2 = cv2.bitwise_not(mask1)

#Segment the red color part out of the frame using bitwise and with the inverted mask
layer1 = cv2.bitwise_and(img, img, mask = mask2)

#Create image showing static background frame pixels only for the masked region
layer2 = cv2.bitwise_and(background, background, mask = mask1)

  • This is now where the magic happens:
#output
output = cv2.addWeighted(layer1,1,layer2,1,0)

Both the mask were added with equal weights using opencv's addWeight

References:

www.machinelearningman.com

https://docs.opencv.org/master/d0/d86/tutorial_py_image_arithmetics.html

harry-potters-invisible-cloak's People

Contributors

asr-aditya avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.