Detect shapes, move one and calculate overlap area

Hello,

I would like to do the operation described on the attached image.

  • Detect shapes in an image
  • Move one of them
  • Calculate the area In pixels of the overlap between these two shapes.

So far I managed to detect the edges using cv2.findContours() First I would like to know if it is the right way or there is something more suitable for such task? Then how could I move only one of the shape detected and calculate the overlap area?

Thanks for your help

is this your real data ?

Nope,

This is typically my data. I would like to detect the two horizontal dark “fingers”

I wanted to send a simplified version to make the explanation clear

and what do we see?

how you’d “move” this depends on why you want to move it and what it is.

the answer to “why” isn’t “because I want to intersect”. the answer ought to be why you want to do that, recursively, until you feel successfully interrogated.

resist the urge to be vague/academic.

various nice and simple and cheap pixel-wise operations could be applied… or others! depends on the situation!

You see the photons sent by your screen. I want to move it for my own pleasure.
Please don’t tell me what to do about why I want to do this or the way I am asking this question.

Hi, Fafou34130.

When I look at the picture above, I think it will be possible to some extent after going through the steps below.

  1. First, leave only important areas to make it easier to recognize and remove the remaining images.

  2. binarize the cut image. I think it would be better to give you an OTSU option.

  3. Calculate the spacing on both sides in rows before the initial overlap.

  4. When overlapping to some extent, use the slope or RAMP function to find the center of the overlapping area.

  5. Scan from the top to the middle row and from the bottom to the middle row until the distance cannot be calculated.

  6. Find the average error by collecting only the calculated intervals.

  7. Uncalculated rows are calculated by inversely calculating the distance found in the first step.

  8. In step 7, the sum of the distances inversely calculated will be the overlapping area.

However, if the two beams are completely overlapped and the spacing cannot be calculated, it is not known how much the overlap is.

Best Regard

Thanks a lot. I will try to go in this direction and will keep you posted

1 Like