MotionDetection in ROI of live stream

Good afternoon.

So I’m working on a motion detection “aplication” for a project, that detects motion(duh) from a livestream that is being broadcasted through a phone camera.

I can detect the movement and that part is okay.

For the second part I would like to analise the motion only in a certain region of the stream.

I was able to write code so that I was able to select a certain ROI. My problem here is how to detect the motion only in that ROI.

I don’t know if anybody has tried to do this or knows of any tutorial/example where I can find some help.

I know that this post might not be very well explained, but if you have any doubt please ask in the comments.

Thank you