title: Marking a detected object through Masking
body: <p>I was following <a href="https://stackoverflow.com/questions/40207763/track-vehicle-trajectory-by-using-opencv">this</a> link, to solve a <a href="https://stackoverflow.com/questions/45584199/object-tracking-on-image">problem of mine</a>. In the first link, it mentioned, we can create a "mask" and if the next object is very near to that "mask", we will not detect it, as it might be the same object. But if it has a distance, we should detect it and then track it till the end.</p>
  
  <p>But I'm not getting how to create the mask and use the conditional statement to exclude it. So, there's first issue of creating the mask. If I can create the mask of the object, then I can try to exclude it from the next detection.</p>
  
  <pre><code>import cv2
  import numpy as np
  
  cap = cv2.VideoCapture('anyvideo.mp4')
  
  while(1):
  
      # Take each frame
      ret, frame = cap.read()
  
      if ret:
  
          # detect the object  and get contour of the image. I'm calling it bbox
  
          tracker = cv2.Tracker_create("KCF")
          ok = tracker.init(frame, tuple(bbox))
          ok, bbox = tracker.update(frame)
          p1 = (int(bbox[0]), int(bbox[1]))
          p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))
          cv2.rectangle(frame, p1, p2, (0,0,255))
          cv2.putText(frame, 'Tracked', (x + 25,y + 10), cv2.FONT_HERSHEY_SIMPLEX,1, (255,255,255), 2, cv2.LINE_AA)
          mask = np.full((frame.shape[0], frame.shape[1]), 0, dtype=np.uint8)
          res = res.append(cv2.bitwise_and(frame,frame,mask = mask))
  
  
          k = cv2.waitKey(5) &amp; 0xFF
          if k == 27:
              break
      else:
          break
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Thank you!</p>