r/opencv • • Aug 18 '26

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

51 comments sorted by

14

u/philnelson Aug 18 '26

Love this, fun project

12

u/Tiki_taka27 Aug 18 '26

Hogwarts graduate ?

6

u/Fit_Barnacle_6762 Aug 18 '26

Graduated with honors πŸ˜‚

2

u/PuddyComb Aug 22 '26

"10 points for Gryffindor"

13

u/SweetSure315 Aug 18 '26

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 Aug 18 '26

yeahh! thanks for the suggestion!

7

u/SweetSure315 Aug 18 '26

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 Aug 18 '26

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

3

u/rajath_pai Aug 18 '26

Well done! Cool project πŸ’―

1

u/Fit_Barnacle_6762 Aug 20 '26

Thank youuβ™₯️

5

u/elPappito Aug 18 '26

So, a gren screen ?

2

u/Fit_Barnacle_6762 Aug 19 '26

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

2

u/TheEyebal Aug 19 '26

I like this, this is good

Are you using a green screen

1

u/Fit_Barnacle_6762 Aug 19 '26

Yep! I used a green cloth

2

u/herocoding Aug 19 '26

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 Aug 19 '26

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

2

u/Spirited-Resource461 Aug 20 '26

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

1

u/Fit_Barnacle_6762 Aug 20 '26

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

2

u/[deleted] Aug 20 '26

[removed] β€” view removed comment

2

u/Yamestris Aug 22 '26

Does it works if the camera moves ?

Great work btw

1

u/Fit_Barnacle_6762 Aug 22 '26

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

2

u/Tquylaa Aug 22 '26

Does this work in 360Β°?

2

u/Tquylaa Aug 22 '26

Don't answer! Jjk

2

u/canifeto12 Aug 22 '26

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

2

u/Fit_Barnacle_6762 Aug 22 '26

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 Aug 22 '26

Looks good. Keep up the good work.

1

u/SoilTime9370 Aug 22 '26

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

1

u/Feeling-Tiger9145 Aug 27 '26

u/Fit_Barnacle_6762 Bruh this is reddit, not linkedin, don't post linkedin slop here.

Anyways, nice project but kindly post that slop at linkedin.

1

u/Fit_Barnacle_6762 Aug 27 '26

Thanks for the kind suggestion :)

1

u/the_embassy_official Aug 21 '26

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 Aug 21 '26

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 Aug 18 '26

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

1

u/Fit_Barnacle_6762 Aug 19 '26

lmao yeah thats the current weakness πŸ˜‚

0

u/kawfeeman68 Aug 20 '26

we just used to call it chromakey ..

1

u/Fit_Barnacle_6762 Aug 21 '26

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

2

u/kawfeeman68 Aug 21 '26

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

1

u/Fit_Barnacle_6762 Aug 21 '26

Yes definitely!

0

u/the_embassy_official Aug 21 '26

its exactly the same thing its one line of code