Repository: blakeblackshear/frigate

Issue:
Draw motion masks under boxes in Debug view
**Describe what you are trying to accomplish and why in non technical terms**
I am trying to use the debug tools to set up masks and zones in relation to bounding boxes. But this is sometimes difficult when a motion mask covers the boxes that I'm trying to see.

**Describe the solution you'd like**
I would like the motion mask to be drawn _under_ the other overlayed content such as bounding boxes. This would make it easier to see the boxes, while still being able to see the mask.

**Describe alternatives you've considered**
An alternative might be to draw them as semi-transparent areas, so that things under them are still visible. But I imagine that would likely be more difficult.

**Additional context**
For example, in this (cropped for privacy) screenshot, the motion mask obscures the bounding box:
![image](https://github.com/blakeblackshear/frigate/assets/10095474/95e157b3-ece0-4897-8d3d-61240db2cb2a)

(That's not a great example, since I can clearly see what the object is, and where the middle center point is, but it's the best example I have without sharing pets or people.)




Discussion:
objects that are detected and motion masks are not related, I don't think that this makes sense
This is a little bit of a strange request, as motion masks are mostly irrelevant to bounding boxes. Motion masks are used to prevent unwanted motion in areas of your scene from triggering object detection, like moving trees or a camera timestamp. Over-masking will make it more difficult for Frigate to track objects. 
Even if they're not related, I often want to be able to see all the settings on a particular camera. Needing to turn one off overlay in order to see a different one just adds extra steps.

My assumption (though perhaps incorrect) is that this would only be a matter of changing the order in which the elements are drawn. Though, admittedly, I don't know how it works. I should go find out. If it's as easy as I would think, I'll open a PR. If not, I'll close the issue.
Yup, found it: https://github.com/blakeblackshear/frigate/blob/dev/frigate/object_processing.py#L625

Pretty sure I just need to move that if statement so that it draws first. I'll submit a PR when I'm at a computer I can use for that. :)
Tested by editing the code in my deployed docker container:
![image](https://github.com/blakeblackshear/frigate/assets/10095474/406a6998-02e2-49fa-83da-a2edd2b5e67f)


Resolving patch:
diff --git a/frigate/object_processing.py b/frigate/object_processing.py
--- a/frigate/object_processing.py
+++ b/frigate/object_processing.py
@@ -498,6 +498,10 @@ def get_current_frame(self, draw_options={}):
 
         frame_copy = cv2.cvtColor(frame_copy, cv2.COLOR_YUV2BGR_I420)
         # draw on the frame
+        if draw_options.get("mask"):
+            mask_overlay = np.where(self.camera_config.motion.mask == [0])
+            frame_copy[mask_overlay] = [0, 0, 0]
+
         if draw_options.get("bounding_boxes"):
             # draw the bounding boxes on the frame
             for obj in tracked_objects.values():
@@ -622,10 +626,6 @@ def get_current_frame(self, draw_options={}):
                 )
                 cv2.drawContours(frame_copy, [zone.contour], -1, zone.color, thickness)
 
-        if draw_options.get("mask"):
-            mask_overlay = np.where(self.camera_config.motion.mask == [0])
-            frame_copy[mask_overlay] = [0, 0, 0]
-
         if draw_options.get("motion_boxes"):
             for m_box in motion_boxes:
                 cv2.rectangle(


Test patch: