Andre
Andre

Reputation: 1883

MATLAB -Draw a rectangle ROI on a video input

How do I specify/set/define a visible Region of Interest on a video and then perform all the processing just inside that Region Of Interest. Something like this:

enter image description here

(Source: https://www.youtube.com/watch?v=IPmG30byCyc)

As you can see, all the processing from detection to tracking happens just inside the ROI. I wish to implement the same setting.

All I have so far is iterating through the video input and showing it in a video player:

reader = vision.VideoFileReader('rotatedjustright.mp4');
viewer = vision.VideoPlayer;
while ~isDone(reader)

    I = step(reader);
    step(viewer,I);

end

I guess somewhere inside the loop the ROI is specified? Then all processing from background subtraction to tracking will just happen inside?

Upvotes: 1

Views: 905

Answers (1)

Daniel Aldrich
Daniel Aldrich

Reputation: 328

A starting point would be to read in a single frame, then draw a ROI; from this you can create a mask (matrix: 1=ROI 0~ROI).

This mask can then be dot-multiplied to each frame to remove everything outside your ROI. Then continue to do the processing.

More advanced methods can include un-distorting the ROI by transformation and correcting the rotation, then cropping the unwanted areas away leaving you with Just the rectangular ROI.

Upvotes: 1

Related Questions