## how can i mask an area with picamera motion vectors

Mike-DC
Posts: 3
Joined: Wed Aug 24, 2016 5:02 pm

### how can i mask an area with picamera motion vectors

Hi
I am pretty new to the raspberry and am playing with the camera and motion detection using waveform80's picamera python module.

I am using a motion resolution of
motion_width = 1296
motion_height = 730

but an area of the frame suffers a lot of light reflection triggering motion detected at pixel offsets approximately 0,260 to 500 760

if I turn the sensitivity up and/or threshold up to stop the motion being detected in this area then the remainder of the frame is not sensitive enough.
is there any way I can mask this area from motion detection ?

I guess I need to apply a mask somehow to this piece of the code
# calculate length of motion vectors of mpeg macro blocks
a = np.sqrt(
np.square(a['x'].astype(np.float)) +
np.square(a['y'].astype(np.float))
).clip(0, 255).astype(np.uint8)

Regards
Mike

BerryPicker
Posts: 177
Joined: Tue Oct 16, 2012 3:03 pm
Location: The East of England

### Re: how can i mask an area with picamera motion vectors

If the trouble is at the picture edge, you could specify a region of interest to zoom in.

6by9
Raspberry Pi Engineer & Forum Moderator
Posts: 8442
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

### Re: how can i mask an area with picamera motion vectors

You are correct that there is no existing mechanism to do this, and you need to alter the loop that calculates the length of motion vectors of mpeg macro blocks.
Read the docs:
Motion data is calculated at the macro-block level (an MPEG macro-block represents a 16x16 pixel region of the frame), and includes one extra column of data. Hence, if the camera’s resolution is 640x480 (as in the example above) there will be 41 columns of motion data ((640 / 16) + 1), in 30 rows (480 / 16).
So if you've set it to 1296x730, then your motion vector array is going to be 82 x 46 elements. Manipulate the data to ignore the values in your dodgy region before you average them or count number above a threshold. Or it may be simpler to 0 your mask and then use the existing code unmodified.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

i234
Posts: 1
Joined: Sun Apr 02, 2017 12:48 pm

### Re: how can i mask an area with picamera motion vectors

6by9 wrote: ...
Motion data is calculated at the macro-block level (an MPEG macro-block represents a 16x16 pixel region of the frame), and includes one extra column of data. Hence, if the camera’s resolution is 640x480 (as in the example above) there will be 41 columns of motion data ((640 / 16) + 1), in 30 rows (480 / 16).
...
Where does this “one extra column of data” come from?
What does it correspond to?
Thank you.

Return to “Camera board”