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

  • Home
  • SEARCH
  • 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 9202919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:21:44+00:00 2026-06-17T23:21:44+00:00

Hey everyone Im very new to programming and python-opencv in general, ive already searched

  • 0

Hey everyone Im very new to programming and python-opencv in general, ive already searched for an answer for this but I couldn’t find it.

Im trying to do motion tracking using my webcam by:

  • taking absolute difference of the current frame and the previous frame
  • This is converted to greyscale and run through a threshold filter so that only pixels that have changed (i.e. where there is movement) will be white. All other pixels will be black.

But I’m getting an error when I try to threshold and applying the dilate in the difference of the frames:

t_minus_dilate = cv2.dilate(t_minus_thresh, es)
TypeError: <unknown> is not a numpy array

This means that the frame used is not a numpy array?

Heres part of my code:

cv2.namedWindow("window_b", cv2.CV_WINDOW_AUTOSIZE)
# Structuring element
es = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (9,4))

## Webcam Settings
capture = cv2.VideoCapture(0)

def diffImg(t0, t1, t2): #calculates the difference between frames
    d1 = cv2.absdiff(t2, t1)
    d2 = cv2.absdiff(t1, t0)
    return cv2.bitwise_and(d1, d2)

t_minus = cv2.cvtColor(capture.read()[1], cv2.COLOR_RGB2GRAY)
t_minus_thresh = cv2.threshold(t_minus, 0, 255, cv2.THRESH_OTSU)
t_minus_dilate = cv2.dilate(t_minus_thresh, es)

t = cv2.cvtColor(capture.read()[1], cv2.COLOR_RGB2GRAY)
t_thresh = cv2.threshold(t, 0, 255, cv2.THRESH_OTSU)
t_dilate = cv2.dilate(t_minus_thresh, es)

t_plus = cv2.cvtColor(capture.read()[1], cv2.COLOR_RGB2GRAY)
t_plus_thresh = cv2.threshold(t_plus, 0, 255, cv2.THRESH_OTSU)
t_plus_dilate = cv2.dilate(t_plus_thresh, es)


while True:

    diff = diffImg(t_minus_dilate, t_dilate, t_plus_dilate) #difference between the frames
    cv2.imshow('window_b',diff)

    t_minus_dilate = t_dilate
    t = diff
    t_plus_dilate = cv2.dilate(diff, es)

    key = cv2.waitKey(10) #20
    if key == 27: #exit on ESC
        cv2.destroyAllWindows()
        break

I dont know it its the best way to use this but Im gonna use this code to make a game that the objective is to pop bubbles that are falling over the screen, if theres movement where the bubble is positioned (if there are white pixels) the bubble is popped.

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-17T23:21:46+00:00Added an answer on June 17, 2026 at 11:21 pm

    Try this:

    retvel, t_minus_thresh = cv2.threshold(t_minus, 0, 255, cv2.THRESH_OTSU)
    t_minus_dilate = cv2.dilate(t_minus_thresh, es)
    

    cv2.threshold returns two values and the second one is the image

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

Sidebar

Related Questions

Hey Everyone, This question seems really silly to me, but I can't for the
Hey everyone, in many programming languages there is this great idiom that lets you
Hey everyone i did some research online but i couldn't get a solution, hopefully
Hey Everyone, Sorry to bother you with this, but I'm having an issue with
Hey everyone quick question, I know this sounds strange to do in javascript but
Hey everyone, great community you got here. I'm an Electrical Engineer doing some programming
Hey everyone, just a quick thing, I have the hex to integer working, but
Hey guys, I'm very excited about how experienced I am in programming. The first,
Hey everyone, I'm a bit new to SEO. I built a one page website
Hey everyone! Im pretty new to Android and I have a webView under 2

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.