Ask Your Question
0

Opencv.js - Background subtraction and replacement in Javascript

asked 2020-02-19 15:22:51 -0600

I'm applying the items in this tutorial, in an attempt to replace a background image of a video while maintaining the foreground objects. Ideally, I'd like to replace the black and white mask that is generated with the color version of the arm holding the box, in a different setting (image background). I'm stuck on generating the mask, and applying the new background image with the foreground of the video frame.

enter image description here

I'm familiar with OpenCV in python, but am struggling to find resources or documentation on what is and what isn't implemented in the opencv.js build. I realize that all of the functionality is not implemented in opencv.js. However, I am almost certain this is achievable with opencv.js, I'm just not sure what steps I need to take as it appears the python examples I'm trying to port are not correct.

That said, here's a python example that accomplishes what I'm attempting to do.

enter image description here

If anyone has any pointers on how I can turn the black and white mask into a bounding area to obtain the arm holding the box and swap it's color image background that would be helpful.

edit retag flag offensive close merge delete

Comments

documentation on what is and what isn't implemented in the opencv.js build

there's a whitelist here

berak gravatar imageberak ( 2020-02-20 01:38:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-17 03:08:49 -0600

kpachinger gravatar image

Google search "OpenCV tutorial Javascript background subtraction". Following that example, you would also do bg.copyTo(dst, mask); The mask may need cv.bitwise_not(mask,mask) or cv.THRESHOLD_BINARY. You may use cv.copyMakeBorder() to allow for unequal mat size. Also, sometimes cv.cvtColor() in regard to bit depth or function output.

Usually a Python example can be followed by replacing cv2 or cv:: with cv. and moving the variable assignment into the function. Numpy and improc photo modules, if those are used, may prove difficult to migrate. Try typing something like cv.seamlessClone in the console to check availability... But the online tutorials output a VERY robust error message in the iframe.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-02-19 14:51:44 -0600

Seen: 2,321 times

Last updated: Apr 17 '20