Split an image in 2 sections and check if an object have crossed the boundaries using OPENCV

30 Views Asked by At

I have a video and want to divide the frames into two sections, like the example image:

enter image description here

If I have an object represented by the blue dot, how can I determine if it has changed regions using OPENCV, considering that I have its coordinate in all the frames?

Here is the code I used to created the image :

import cv2
from google.colab.patches import cv2_imshow
import numpy as np

img = np.zeros((600,800,3), dtype=np.uint8)
img.fill(255)

a = np.array([(0, 200), (100, 200), (300, 400), (400, 600),(0,800)])
cv2.drawContours(img, [a], 0, (0,0,0), 2)



font = cv2.FONT_HERSHEY_SIMPLEX

img = cv2.circle(img, (300,500), radius=5, color=(255, 0, 0), thickness=-1)
cv2.putText(img, 'OBJ', (230,500), font, 1, (0, 0, 0), 2, cv2.LINE_AA)

cv2.putText(img, 'B', (50,550), font, 3, (0, 0, 0), 2, cv2.LINE_AA)
cv2.putText(img, 'A', (700,100), font, 3, (0, 0, 0), 2, cv2.LINE_AA)

cv2_imshow(img)

One possibility is to check in each frame which section the object is in, and if there are changes, I know that it has changed region. However, I don't know how to implement this. Any suggestions are welcome.

Thank you.

0

There are 0 best solutions below