
I would like to check if both object touch each other, I’ve build a solution and works, but I think is not the better approach.
I explain my solution: My square is a square of 100x100 white (255) color, so I got the sum of the values (255x100x100 = 2.550.000), and then I made the other object (circle) on black color (0), then, when circle overlap the square obviously the sum of the values on square changes, and I check the result with a condition, this approach works fine, but I made a lot of calculations and I’m looking for a better approach without many calculation, is it possible?
Thanks in advance.
If you make the shapes two different colors you could scan to see pixel difference from color change once they collide
as it is, the picture doesn’t move, and neither does the square or the circular blob.
you should explain what they really are. don’t explain what you did. you are asking for approaches that differ from what you did.
zoom out. explain like we don’t know what is going on. because we don’t. all we see is a black and white picture and you talking about counting pixels.
oh and don’t tag threads with such nonspecific tags as “opencv”. this forum is all about OpenCV.
I put a video about the situation, at the right side of the square is the circle (on black color) so it doesn’t look, but after a few seconds I collision the circle with the square an if you check the terminal, you’ll look it identifies the collision printing “Inside ROI”
Video: Square and circle collision - YouTube
The image was created with:
image_process = np.zeros((480, 640), dtype='uint8')
image_process[180:280, 120:220] = 255
To identify collision I’m using this:
if image_process[180:280, 120:220].sum() != 2550000:
image_process[180:280, 120:220] = 255
print('Inside ROI')
But I’m want to know if exist a better approach or a function with opencv to do this more simple and with better performace.