Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:57:54+00:00 2026-06-17T21:57:54+00:00

Hey everyone I’m trying to make a game using my webcam where I need

  • 0

Hey everyone I’m trying to make a game using my webcam where I need some objects to fall down the screen while Im streaming video with my webcam (that stream being my background).

I am using python and module cv2 of opencv

The question is: how do I apply a mask to this objects? I already have an image to be the mask of the original image but I dont know how to apply it to subtract the background of the original image..

ive already tried using the cv2.bitwise_and but nothing happened, the imaged stayed the same with black background:

#targets
original_ball = cv2.imread("Aqua-Ball-Red-icon.png")
ball = cv2.resize(bola_original, (64,64), fx=1, fy=1)
#mask
mask_original = cv2.imread("input-mask.png",0)
mask = cv2.resize(mask_original, (64,64), fx=1, fy=1)
res = cv2.bitwise_and(ball, ball, mask = mask)

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:57:55+00:00Added an answer on June 17, 2026 at 9:57 pm

    If you’re using cv2, you’re working with numpy arrays, and there’s no need to turn to opencv for something as simple as a mask.

    First, manipulate (multiply, possibly) your mask array so that the values you want (i.e.: those not masked out) have value 1. Then, multiply your source image by your mask. That will make the resulting image have the original pixels where the mask == 1, and 0 (i.e.:black) where the mask == 0.

    Here’s the gist of it:

    import numpy
    original_ball = cv2.imread("Aqua-Ball-Red-icon.png")
    ball = cv2.resize(bola_original, (64,64), fx=1, fy=1)
    mask_original = cv2.imread("input-mask.png",0)
    mask = cv2.resize(mask_original, (64,64), fx=1, fy=1)
    
    max_value= numpy.max(mask)
    mask/=max_value
    res= ball*mask
    

    Depending on the color depth of your input-mask.png, you may need to reduce it to grayscale first

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone I'm trying to make a game using my webcam where I need
Hey everyone, I am trying to ( temporarily! ) do some ASP.NET and C#
Hey everyone, I need to convert the following format into a new format using
Hey everyone, I am trying to consume a WebService using PHP SoapClient . Now,
Hey everyone I am trying to .submit some values with ajax response and i
Hey everyone. I'm trying to make a swing GUI with a button and a
Hey everyone I am having a little problem with my jQuery I am trying
Hey everyone. The following is the code that I am using to play random
Hey everyone, great community you got here. I'm an Electrical Engineer doing some programming
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.