Detect if object is above line

As per the title, can you suggest a way to identify if the object to the right of the picture below is above/below the line marked with the blue arrows. Unfortunately I can’t post them as two separate pictures because new users are limited to one embedded media per post.

Thanks!

please do not duplicate your questions here, thank you.

There are two separate problems. One is detecting the curved line, which I’m 90% there on and the other is working out if an object is above/below the detected line.

okay so… you have to extrapolate the line?

it’s not a straight line. apply whatever curve model you like that seems to fit well.

what even do we see in that picture? it’s abstract art.

No, sorry. Because of the rules of the forum I can’t post two embedded media in the same post so I had to merge the two side by side in one picture. Essentially the object to be tracked will always be above/below the line I pointed out and no extrapolation of said line is needed.

Essentially, the camera starts with a static background from which I extract my line. As the objects start to come into view, I isolate them and need to determine if, at any point when they are in view, they move above the line.

maybe I should lobby harder for new users to be allowed more pictures…the limit annoys everyone.

anyway, you could use imgur, dropbox, google drive, … whatever is convenient.

Because I’ve been deep in this for quite a few hours, my brain foolishly assumed everyone has the same overview of the problem that I do. Hope everything is clear now? In any case, here are the two pictures separately:

Fixed line
Moving object whose position in relationship to the line need to be determined

per-pixel binary/boolean operation.

calculate the intersection (bitwise_and). then see if the intersection is empty or not (countNonZero).

equivalent operations are provided by numpy, so you get to choose.

https://docs.opencv.org/4.5.2/d0/d86/tutorial_py_image_arithmetics.html

a three-level illustration:

white area is intersection. both masks are true there.

Great, thanks! One more question. When you said in the other thread about the correct tools for a certain problem, that got me thinking on how I recognize the outline of the moving objects. That part is done again with a blow torch and a hammer:

  1. Convert each frame to grayscale
  2. Apply an absDiff() on two consecutive frames.
  3. Apply a Cloe morphological transformation on the diff
  4. Binary threshold to a value which seems to give out decent results
  5. Apply a blur transformation

It’s not ideal, but it works. Main problem is getting a “tail” on the position of the object in the current frame and the fact that the outline is not always consistent - depending on the color of the object.

Here’s a few pictures of the objects being tracked. Getting the outline right (especially at the bottom of the object) is critical. Obj1, obj2

that’s a good first attempt…

I would however recommend something from the bgsegm module. same principle (differences), but it builds a “model” (picture) of the background rather than using the previous frame.

you might need morphology operations and/or blur to clean that up too.

https://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html

https://docs.opencv.org/master/d8/d38/tutorial_bgsegm_bg_subtraction.html

Thanks. Very good resources. Have switched over to KNN and works well. One thing I can’t seem to do is get a decent filter to fill in the object properly and get rid of the noise.

Raw output of KNN
Processed mask

The processed mask is obtained with an open morphology done with ellipse kernel (3x5)