0

I have a video stream where I do the detection of people using Opencv and python. My ROI is rectangular, but I would like to make a custom shape as in the figure.

roi opencv

petezurich
  • 9,280
  • 9
  • 43
  • 57
Márcio
  • 21
  • 5

1 Answers1

2

It seems this is a stationary camera. If so, you can hard code the rectangular region of interest. You can then use a mask (created with for instance MS Paint) to black out everything outside of the custom shape.

Result:
enter image description here

Code:

    import cv2 
    # load image
    img = cv2.imread('image.jpg')
    # load mask
    mask = cv2.imread('roi_mask.png',0)
    # create subimage
    roi = img[120:350,150:580]
    # mask roi
    masked_roi = cv2.bitwise_and(roi,roi,mask=mask)
    # display result
    cv2.imshow('Roi',roi)
    cv2.imshow('Mask',mask)
    cv2.imshow('Result',masked_roi)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
J.D.
  • 4,511
  • 2
  • 7
  • 20