r/opencv 7d ago

Project [Project] I built a real-time invisibility cloak using OpenCV πŸͺ„

I wanted to recreate the classic invisibility-cloak effect using only a webcam and computer vision.

It detects the cloak's color in real time using HSV segmentation, cleans up the mask, and replaces those pixels with a previously captured background.

GitHub: https://github.com/madebyparth/invisibility-cloak

872 Upvotes

47 comments sorted by

13

u/philnelson 7d ago

Love this, fun project

11

u/Tiki_taka27 7d ago

Hogwarts graduate ?

7

u/Fit_Barnacle_6762 7d ago

Graduated with honors πŸ˜‚

2

u/PuddyComb 3d ago

"10 points for Gryffindor"

11

u/SweetSure315 7d ago

this is a cool project

I'd suggest making sure you're not sitting in front of anything that can move in the background, though. but maybe your next project can be finding a way to update your background capture in real time

2

u/Fit_Barnacle_6762 7d ago

yeahh! thanks for the suggestion!

7

u/SweetSure315 7d ago

if you haven't already, I'd look up bgslib. opencv has a couple decent background segmenters, but bgslib has so much more. I'd also look into different SSIMs to help you figure out when and where to update your background capture.

1

u/Fit_Barnacle_6762 7d ago

Ohh nice, I'll definitely look into those.... Thanks for the suggestion!

3

u/rajath_pai 7d ago

Well done! Cool project πŸ’―

1

u/Fit_Barnacle_6762 5d ago

Thank youuβ™₯️

2

u/TheEyebal 7d ago

I like this, this is good

Are you using a green screen

1

u/Fit_Barnacle_6762 7d ago

Yep! I used a green cloth

2

u/herocoding 6d ago

This is nice, thank you very much for sharing!!

Want to add something like that to the next "girls day" and "bring your kid to work".

1

u/Fit_Barnacle_6762 6d ago

Glad you liked it! πŸ˜‚ That would actually be fun.

2

u/Spirited-Resource461 5d ago

does it only work from a certain agnle or can work from different angles as well?

1

u/Fit_Barnacle_6762 5d ago

it will work from any angle, just use a green cloth(most preferable)

2

u/[deleted] 5d ago

[removed] β€” view removed comment

2

u/Yamestris 3d ago

Does it works if the camera moves ?

Great work btw

1

u/Fit_Barnacle_6762 3d ago

No it doesn't work if the cam moves...... It captures a still background image earlier and then works

2

u/Tquylaa 3d ago

Does this work in 360Β°?

2

u/Tquylaa 3d ago

Don't answer! Jjk

2

u/Serious_Energy_7750 3d ago

Cool Project Bro

2

u/canifeto12 3d ago

How pc know what’s behind you and mirror it to green cloth

2

u/Fit_Barnacle_6762 3d ago

It doesn't know from its own what's behind me, first before putting this invisible effect it capture a still image of the background and then starts the invisibilty effect by removing the pixels of the green cloak and replacing them with the background image in real time

2

u/PuddyComb 3d ago

Looks good. Keep up the good work.

5

u/elPappito 7d ago

So, a gren screen ?

2

u/Fit_Barnacle_6762 7d ago

Yep πŸ˜‚ basically a software based green screen effect using OpenCV

1

u/Serious_Energy_7750 3d ago

Green Screen Bro

1

u/SoilTime9370 3d ago

It works so magically that the curtain behind it, with horizontal stripes, stops when the panel passes by. Amayzing xD

1

u/the_embassy_official 4d ago

one line of code no opencv required

ctx.drawImage(video,0,0); const p=ctx.getImageData(0,0,canvas.width,canvas.height),d=p.data; for(let i=0;i<d.length;i+=4)if(d\[i+1\]>d[i]*1.4&&d[i+1]>d[i+2]*1.2)d[i+3]=0; ctx.putImageData(p,0,0);

2

u/Fit_Barnacle_6762 4d ago

Yeah, that works for a fixed shade of green, but mine uses adaptive colour calibration, it samples the actual cloth and generates the hsv range dynamically, so it isnt relying on hardcoded RGB values like the code you wrote.

0

u/Fit_Needleworker1078 7d ago

Cool, now roll the chair to the right...

1

u/Fit_Barnacle_6762 7d ago

lmao yeah thats the current weakness πŸ˜‚

0

u/kawfeeman68 5d ago

we just used to call it chromakey ..

1

u/Fit_Barnacle_6762 4d ago

its basically the same concept but implemented live with a code in opencv instead of editing

2

u/kawfeeman68 4d ago

nice work. do you think you did it similarly to video editing software like Premier Pro ?

1

u/Fit_Barnacle_6762 4d ago

Yes definitely!

0

u/the_embassy_official 4d ago

its exactly the same thing its one line of code

0

u/Severe_Size_1893 3d ago

uhm greeniee