I’m using frame differencing and opencv to detect movement between frames (absdiff, threshold, erode, etc).
How can I get the coordinates of the individual locations of the movements (the rect: x, y, width, height), basically of the white blobs?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I’m doing the same thing. Here’s the code I have (some things handled in different classes, I just put it all together here). The first part is what you already have, skip down to the contours part.
See here for more details (especially the options on which contours to find, can help you narrow down what you find. I just used CV_RETR_EXTERNAL).
Note that I made (before) a Mat displayer, which is a deep-copy of frame (copied with frame.copyTo(displayer). This is because if you draw stuff directly on frame, it’ll be transferred to “frameLast” and pop up with the next absDiff. Of course you could avoid this extra image by cleanly copying frame to frameLast before drawing (so drawing everything at the end), I do this so I can easily draw from anywhere in the code, makes it easier for now since I’m trying a lot of things and want to be able to see intermediate steps at times.