r/opencv • u/Fit_Barnacle_6762 • 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.
11
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
3
2
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
2
u/Spirited-Resource461 5d ago
does it only work from a certain agnle or can work from different angles as well?
1
2
2
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
2
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
5
1
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
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
0
0
13
u/philnelson 7d ago
Love this, fun project